|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is a part of the Phystrix Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2013-2015 oDesk Corporation. All Rights Reserved. |
|
7
|
|
|
* |
|
8
|
|
|
* This file is licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
namespace Odesk\Bundle\PhystrixBundle\DataCollector; |
|
21
|
|
|
|
|
22
|
|
|
use Odesk\Phystrix\AbstractCommand; |
|
23
|
|
|
use Odesk\Phystrix\RequestLog; |
|
24
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
25
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
26
|
|
|
use Symfony\Component\HttpKernel\DataCollector\DataCollector; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Collects data from Phystrix RequestLog. Makes it compatible to use with Symfony profiler and WebProfiler. |
|
30
|
|
|
*/ |
|
31
|
|
|
class RequestLogDataCollector extends DataCollector |
|
32
|
|
|
{ |
|
33
|
|
|
private $requestLog; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct(RequestLog $requestLog) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->requestLog = $requestLog; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function collect(Request $request, Response $response, \Exception $exception = null) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->data = array('commands' => array()); |
|
46
|
|
|
|
|
47
|
|
|
/** @var AbstractCommand $command */ |
|
48
|
|
|
foreach ($this->requestLog->getExecutedCommands() as $command) { |
|
49
|
|
|
$time = $command->getExecutionTimeInMilliseconds(); |
|
50
|
|
|
if (!$time) { |
|
51
|
|
|
$time = 0; |
|
52
|
|
|
} |
|
53
|
|
|
$this->data['commands'][] = array( |
|
54
|
|
|
'class' => get_class($command), |
|
55
|
|
|
'duration' => $time, |
|
56
|
|
|
'events' => $command->getExecutionEvents(), |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getCommands() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->data['commands']; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getName() |
|
70
|
|
|
{ |
|
71
|
|
|
return 'phystrix'; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|