1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sqltrackerquery.php
См. документацию.
1<?php
2
3namespace Bitrix\Main\Diag;
4
5class SqlTrackerQuery implements \ArrayAccess
6{
8 protected $sql = "";
10 protected $binds = null;
12 protected $state = "";
14 protected $node = "";
16 protected $startTime = 0.0;
18 protected $finishTime = 0.0;
20 protected $time = 0.0;
22 protected $trace = null;
24 protected $tracker;
25 protected int $lengths = 0;
26 protected int $selectedRows = 0;
27 protected int $fetchedRows = 0;
28 protected int $selectedFieldsCount = 0;
29 protected bool $hasBigFields = false;
30
35 {
36 $this->tracker = $tracker;
37 }
38
47 public function startQuery($sql, array $binds = null)
48 {
49 $this->sql = $sql;
50 $this->binds = $binds;
51 $this->startTime = Helper::getCurrentMicrotime();
52 }
53
61 public function finishQuery($skip = 3)
62 {
63 $this->finishTime = Helper::getCurrentMicrotime();
64 $this->time = $this->finishTime - $this->startTime;
65 $this->trace = $this->filterTrace(Helper::getBackTrace($this->tracker->getDepthBackTrace(), null, $skip));
66
67 $this->tracker->addTime($this->time);
68 $this->tracker->writeFileLog($this->sql, $this->time, "", 4);
69 }
70
78 public function restartQuery()
79 {
80 $this->startTime = Helper::getCurrentMicrotime();
81 }
82
90 public function refinishQuery()
91 {
92 $this->finishTime = Helper::getCurrentMicrotime();
93 $this->addTime($this->finishTime - $this->startTime);
94 }
95
102 public function addLength(int $length)
103 {
104 $this->lengths += $length;
105 }
106
112 public function getLength(): int
113 {
114 return $this->lengths;
115 }
116
122 public function incrementFetched(): void
123 {
124 $this->fetchedRows++;
125 }
126
132 public function getFetchedRowsCount(): int
133 {
134 return $this->fetchedRows;
135 }
136
143 public function setSelectedRowsCount(int $count): void
144 {
145 $this->selectedRows = $count;
146 }
147
153 public function getSelectedRowsCount(): int
154 {
155 return $this->selectedRows;
156 }
157
164 public function setSelectedFieldsCount(int $count): void
165 {
166 $this->selectedFieldsCount = $count;
167 }
168
174 public function getSelectedFieldsCount(): int
175 {
177 }
178
179 public function setHasBigFields(bool $value)
180 {
181 $this->hasBigFields = $value;
182 }
183
184 public function hasBigFields(): bool
185 {
186 return $this->hasBigFields;
187 }
188
194 public function getSql()
195 {
196 return $this->sql;
197 }
198
207 public function setSql($sql)
208 {
209 $this->sql = (string)$sql;
210 return $this;
211 }
212
218 public function getBinds()
219 {
220 return $this->binds;
221 }
222
231 public function setBinds(array $binds)
232 {
233 $this->binds = $binds;
234 return $this;
235 }
236
242 public function getState()
243 {
244 return $this->state;
245 }
246
255 public function setState($state)
256 {
257 $this->state = (string)$state;
258 return $this;
259 }
260
266 public function getNode()
267 {
268 return $this->node;
269 }
270
279 public function setNode($node)
280 {
281 $this->node = (string)$node;
282 return $this;
283 }
284
290 public function getTime()
291 {
292 return $this->time;
293 }
294
303 public function setTime($time)
304 {
305 $this->tracker->addTime(-$this->time);
306 $this->time = (float)$time;
307 $this->tracker->addTime($this->time);
308 return $this;
309 }
310
318 public function addTime($time)
319 {
320 $time = (float)$time;
321 $this->time += $time;
322 $this->tracker->addTime($time);
323 }
324
330 public function getTrace()
331 {
332 return $this->trace;
333 }
334
343 public function setTrace(array $trace = null)
344 {
345 $this->trace = ($trace !== null ? $this->filterTrace($trace) : []);
346
347 return $this;
348 }
349
358 public function offsetExists($offset): bool
359 {
360 switch ((string)$offset)
361 {
362 case "BX_STATE":
363 case "TIME":
364 case "QUERY":
365 case "TRACE":
366 case "NODE_ID":
367 return true;
368 default:
369 return false;
370 }
371 }
372
381 #[\ReturnTypeWillChange]
382 public function offsetGet($offset)
383 {
384 switch ($offset)
385 {
386 case "BX_STATE":
387 return $this->state;
388 case "TIME":
389 return $this->time;
390 case "QUERY":
391 return $this->sql;
392 case "TRACE":
393 return $this->trace;
394 case "NODE_ID":
395 return $this->node;
396 default:
397 return false;
398 }
399 }
400
410 public function offsetSet($offset, $value): void
411 {
412 }
413
422 public function offsetUnset($offset): void
423 {
424 }
425
433 protected function filterTrace($trace)
434 {
435 $filtered = array();
436 foreach ($trace as $tr)
437 {
438 $args = array();
439 if (!empty($tr["args"]) && is_array($tr["args"]))
440 {
441 foreach ($tr["args"] as $k1 => $v1)
442 {
443 if (is_array($v1))
444 {
445 foreach ($v1 as $k2 => $v2)
446 {
447 if (is_scalar($v2))
448 {
449 $args[$k1][$k2] = $v2;
450 }
451 elseif (is_object($v2))
452 {
453 $args[$k1][$k2] = get_class($v2);
454 }
455 else
456 {
457 $args[$k1][$k2] = gettype($v2);
458 }
459 }
460 }
461 else
462 {
463 if (is_scalar($v1))
464 {
465 $args[$k1] = $v1;
466 }
467 elseif (is_object($v1))
468 {
469 $args[$k1] = get_class($v1);
470 }
471 else
472 {
473 $args[$k1] = gettype($v1);
474 }
475 }
476 }
477 }
478
479 $filtered[] = [
480 "file" => $tr["file"] ?? null,
481 "line" => $tr["line"] ?? null,
482 "class" => $tr["class"] ?? null,
483 "type" => $tr["type"] ?? null,
484 "function" => $tr["function"] ?? null,
485 "args" => $args,
486 ];
487 }
488 return $filtered;
489 }
490}
$count
Определения admin_tab.php:4
setSelectedRowsCount(int $count)
Определения sqltrackerquery.php:143
setBinds(array $binds)
Определения sqltrackerquery.php:231
setSelectedFieldsCount(int $count)
Определения sqltrackerquery.php:164
setHasBigFields(bool $value)
Определения sqltrackerquery.php:179
__construct(SqlTracker $tracker)
Определения sqltrackerquery.php:34
addLength(int $length)
Определения sqltrackerquery.php:102
setTrace(array $trace=null)
Определения sqltrackerquery.php:343
startQuery($sql, array $binds=null)
Определения sqltrackerquery.php:47
offsetSet($offset, $value)
Определения sqltrackerquery.php:410
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393