1 | <?php |
||
17 | class StatementProfiler implements ProfilerInterface |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Is the profiler active? |
||
22 | * |
||
23 | * @var boolean |
||
24 | */ |
||
25 | protected $active = false; |
||
26 | |||
27 | /** |
||
28 | * Retained profiles. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $profiles = array(); |
||
33 | |||
34 | /** |
||
35 | * Track duplicate statements. |
||
36 | * |
||
37 | * @var boolean |
||
38 | */ |
||
39 | protected $trackDuplicates = false; |
||
40 | |||
41 | /** |
||
42 | * Ignore statements. |
||
43 | * |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $ignoreStatements = array( |
||
47 | // The "AbstractPlugin::getLastRevision" method. |
||
48 | 'SELECT LastRevision FROM PluginData WHERE Name = :name', |
||
49 | |||
50 | // The "AbstractPlugin::getProject" method. |
||
51 | 'SELECT Id FROM Projects WHERE Path = :path', |
||
52 | |||
53 | // The "AbstractDatabaseCollectorPlugin::getProjects" method. |
||
54 | 'SELECT Path, Id AS PathId, RevisionAdded, RevisionDeleted, RevisionLastSeen FROM Paths WHERE PathHash IN (:path_hashes)', |
||
55 | ); |
||
56 | |||
57 | /** |
||
58 | * Console IO. |
||
59 | * |
||
60 | * @var ConsoleIO |
||
61 | */ |
||
62 | private $_io; |
||
63 | |||
64 | /** |
||
65 | * Debug mode. |
||
66 | * |
||
67 | * @var boolean |
||
68 | */ |
||
69 | private $_debugMode = false; |
||
70 | |||
71 | /** |
||
72 | * Creates statement profiler |
||
73 | * |
||
74 | * @param ConsoleIO $io Console IO. |
||
75 | */ |
||
76 | 18 | public function __construct(ConsoleIO $io = null) |
|
81 | |||
82 | /** |
||
83 | * Turns the profiler on and off. |
||
84 | * |
||
85 | * @param boolean $active True to turn on, false to turn off. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 15 | public function setActive($active) |
|
93 | |||
94 | /** |
||
95 | * Is the profiler active? |
||
96 | * |
||
97 | * @return boolean |
||
98 | */ |
||
99 | 17 | public function isActive() |
|
103 | |||
104 | /** |
||
105 | * Toggle duplicate statement tracker. |
||
106 | * |
||
107 | * @param boolean $track Duplicate statement tracker status. |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | 2 | public function trackDuplicates($track) |
|
115 | |||
116 | /** |
||
117 | * Adds a profile entry. |
||
118 | * |
||
119 | * @param float $duration The query duration. |
||
120 | * @param string $function The PDO method that made the entry. |
||
121 | * @param string $statement The SQL query statement. |
||
122 | * @param array $bind_values The values bound to the statement. |
||
123 | * |
||
124 | * @return void |
||
125 | * @throws \PDOException When duplicate statement is detected. |
||
126 | */ |
||
127 | 15 | public function addProfile( |
|
168 | |||
169 | /** |
||
170 | * Removes a profile entry. |
||
171 | * |
||
172 | * @param string $statement The SQL query statement. |
||
173 | * @param array $bind_values The values bound to the statement. |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | 2 | public function removeProfile($statement, array $bind_values = array()) |
|
186 | |||
187 | /** |
||
188 | * Normalizes statement. |
||
189 | * |
||
190 | * @param string $statement The SQL query statement. |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | 12 | protected function normalizeStatement($statement) |
|
198 | |||
199 | /** |
||
200 | * Creates profile key. |
||
201 | * |
||
202 | * @param string $normalized_statement The normalized SQL query statement. |
||
203 | * @param array $bind_values The values bound to the statement. |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | 9 | protected function createProfileKey($normalized_statement, array $bind_values = array()) |
|
211 | |||
212 | /** |
||
213 | * Substitutes parameters in the statement. |
||
214 | * |
||
215 | * @param string $normalized_statement The normalized SQL query statement. |
||
216 | * @param array $bind_values The values bound to the statement. |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | 1 | protected function substituteParameters($normalized_statement, array $bind_values = array()) |
|
237 | |||
238 | /** |
||
239 | * Returns all the profile entries. |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | 13 | public function getProfiles() |
|
247 | |||
248 | /** |
||
249 | * Reset all the profiles |
||
250 | * |
||
251 | * @return void |
||
252 | */ |
||
253 | 1 | public function resetProfiles() |
|
257 | |||
258 | } |
||
259 |