1 | <?php |
||
30 | class Profiler extends Component implements ProfilerInterface |
||
31 | { |
||
32 | /** |
||
33 | * @var bool whether to profiler is enabled. Defaults to true. |
||
34 | * You may use this field to disable writing of the profiling messages and thus save the memory usage. |
||
35 | */ |
||
36 | public $enabled = true; |
||
37 | /** |
||
38 | * @var array[] complete profiling messages. |
||
39 | * Each message has a following keys: |
||
40 | * |
||
41 | * - token: string, profiling token. |
||
42 | * - category: string, message category. |
||
43 | * - beginTime: float, profiling begin timestamp obtained by microtime(true). |
||
44 | * - endTime: float, profiling end timestamp obtained by microtime(true). |
||
45 | * - duration: float, profiling block duration in milliseconds. |
||
46 | * - beginMemory: int, memory usage at the beginning of profile block in bytes, obtained by `memory_get_usage()`. |
||
47 | * - endMemory: int, memory usage at the end of profile block in bytes, obtained by `memory_get_usage()`. |
||
48 | * - memoryDiff: int, a diff between 'endMemory' and 'beginMemory'. |
||
49 | */ |
||
50 | public $messages = []; |
||
51 | |||
52 | /** |
||
53 | * @var array pending profiling messages, e.g. the ones which have begun but not ended yet. |
||
54 | */ |
||
55 | private $_pendingMessages = []; |
||
56 | /** |
||
57 | * @var array|Target[] the profiling targets. Each array element represents a single [[Target|profiling target]] instance |
||
58 | * or the configuration for creating the profiling target instance. |
||
59 | * @since 2.1 |
||
60 | */ |
||
61 | private $_targets = []; |
||
62 | /** |
||
63 | * @var bool whether [[targets]] have been initialized, e.g. ensured to be objects. |
||
64 | * @since 2.1 |
||
65 | */ |
||
66 | private $_isTargetsInitialized = false; |
||
67 | |||
68 | |||
69 | /** |
||
70 | * Initializes the profiler by registering [[flush()]] as a shutdown function. |
||
71 | */ |
||
72 | 4 | public function init() |
|
77 | |||
78 | /** |
||
79 | * @return Target[] the profiling targets. Each array element represents a single [[Target|profiling target]] instance. |
||
80 | */ |
||
81 | 2 | public function getTargets() |
|
93 | |||
94 | /** |
||
95 | * @param array|Target[] $targets the profiling targets. Each array element represents a single [[Target|profiling target]] instance |
||
96 | * or the configuration for creating the profiling target instance. |
||
97 | */ |
||
98 | 1 | public function setTargets($targets) |
|
103 | |||
104 | /** |
||
105 | * Adds extra target to [[targets]]. |
||
106 | * @param Target|array $target the log target instance or its DI compatible configuration. |
||
107 | * @param string|null $name array key to be used to store target, if `null` is given target will be append |
||
108 | * to the end of the array by natural integer key. |
||
109 | */ |
||
110 | 2 | public function addTarget($target, $name = null) |
|
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | 1336 | public function begin($token, array $context = []) |
|
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | 1336 | public function end($token, array $context = []) |
|
180 | |||
181 | /** |
||
182 | * {@inheritdoc} |
||
183 | */ |
||
184 | 2 | public function flush() |
|
205 | |||
206 | /** |
||
207 | * Dispatches the profiling messages to [[targets]]. |
||
208 | * @param array $messages the profiling messages. |
||
209 | */ |
||
210 | 1 | protected function dispatch($messages) |
|
216 | } |