Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
sqltrackerquery.php
1
<?php
2
namespace
Bitrix\Main\Diag
;
3
4
class
SqlTrackerQuery
implements
\ArrayAccess
5
{
7
protected
$sql
=
""
;
9
protected
$binds
=
null
;
11
protected
$state
=
""
;
13
protected
$node
=
""
;
15
protected
$startTime
= 0.0;
17
protected
$finishTime
= 0.0;
19
protected
$time
= 0.0;
21
protected
$trace
=
null
;
23
protected
$tracker
;
24
28
public
function
__construct
(
SqlTracker
$tracker
)
29
{
30
$this->tracker =
$tracker
;
31
}
32
41
public
function
startQuery
(
$sql
, array
$binds
=
null
)
42
{
43
$this->sql =
$sql
;
44
$this->binds =
$binds
;
45
$this->startTime =
Helper::getCurrentMicrotime
();
46
}
47
55
public
function
finishQuery
($skip = 3)
56
{
57
$this->finishTime =
Helper::getCurrentMicrotime
();
58
$this->time = $this->finishTime -
$this->startTime
;
59
$this->trace = $this->
filterTrace
(
Helper::getBackTrace
($this->tracker->getDepthBackTrace(),
null
, $skip));
60
61
$this->tracker->addTime($this->time);
62
$this->tracker->writeFileLog($this->sql, $this->time,
""
, 4);
63
}
64
72
public
function
restartQuery
()
73
{
74
$this->startTime =
Helper::getCurrentMicrotime
();
75
}
76
84
public
function
refinishQuery
()
85
{
86
$this->finishTime =
Helper::getCurrentMicrotime
();
87
$this->
addTime
($this->finishTime - $this->startTime);
88
}
89
95
public
function
getSql
()
96
{
97
return
$this->sql
;
98
}
99
108
public
function
setSql
(
$sql
)
109
{
110
$this->sql = (string)
$sql
;
111
return
$this;
112
}
113
119
public
function
getBinds
()
120
{
121
return
$this->binds
;
122
}
123
132
public
function
setBinds
(array
$binds
)
133
{
134
$this->binds =
$binds
;
135
return
$this;
136
}
137
143
public
function
getState
()
144
{
145
return
$this->state
;
146
}
147
156
public
function
setState
(
$state
)
157
{
158
$this->state = (string)
$state
;
159
return
$this;
160
}
161
167
public
function
getNode
()
168
{
169
return
$this->node
;
170
}
171
180
public
function
setNode
(
$node
)
181
{
182
$this->node = (string)
$node
;
183
return
$this;
184
}
185
191
public
function
getTime
()
192
{
193
return
$this->time
;
194
}
195
204
public
function
setTime
(
$time
)
205
{
206
$this->tracker->addTime(-$this->time);
207
$this->time = (float)
$time
;
208
$this->tracker->addTime($this->time);
209
return
$this;
210
}
211
219
public
function
addTime
(
$time
)
220
{
221
$time
= (float)
$time
;
222
$this->time +=
$time
;
223
$this->tracker->addTime(
$time
);
224
}
225
231
public
function
getTrace
()
232
{
233
return
$this->trace
;
234
}
235
244
public
function
setTrace
(array
$trace
)
245
{
246
$this->trace = $this->
filterTrace
($trace);
247
return
$this;
248
}
249
258
public
function
offsetExists
($offset): bool
259
{
260
switch
((
string
)$offset)
261
{
262
case
"BX_STATE"
:
263
case
"TIME"
:
264
case
"QUERY"
:
265
case
"TRACE"
:
266
case
"NODE_ID"
:
267
return
true
;
268
default
:
269
return
false
;
270
}
271
}
272
281
#[\ReturnTypeWillChange]
282
public
function
offsetGet
($offset)
283
{
284
switch
($offset)
285
{
286
case
"BX_STATE"
:
287
return
$this->state
;
288
case
"TIME"
:
289
return
$this->time
;
290
case
"QUERY"
:
291
return
$this->sql
;
292
case
"TRACE"
:
293
return
$this->trace
;
294
case
"NODE_ID"
:
295
return
$this->node
;
296
default
:
297
return
false
;
298
}
299
}
300
310
public
function
offsetSet
($offset, $value): void
311
{
312
}
313
322
public
function
offsetUnset
($offset): void
323
{
324
}
325
333
protected
function
filterTrace
(
$trace
)
334
{
335
$filtered = array();
336
foreach
(
$trace
as $i => $tr)
337
{
338
$args = array();
339
if
(!empty($tr[
"args"
]) && is_array($tr[
"args"
]))
340
{
341
foreach
($tr[
"args"
] as $k1 => $v1)
342
{
343
if
(is_array($v1))
344
{
345
foreach
($v1 as $k2 => $v2)
346
{
347
if
(is_scalar($v2))
348
{
349
$args[$k1][$k2] = $v2;
350
}
351
elseif (is_object($v2))
352
{
353
$args[$k1][$k2] = get_class($v2);
354
}
355
else
356
{
357
$args[$k1][$k2] = gettype($v2);
358
}
359
}
360
}
361
else
362
{
363
if
(is_scalar($v1))
364
{
365
$args[$k1] = $v1;
366
}
367
elseif (is_object($v1))
368
{
369
$args[$k1] = get_class($v1);
370
}
371
else
372
{
373
$args[$k1] = gettype($v1);
374
}
375
}
376
}
377
}
378
379
$filtered[] = [
380
"file"
=> $tr[
"file"
] ??
null
,
381
"line"
=> $tr[
"line"
] ??
null
,
382
"class"
=> $tr[
"class"
] ??
null
,
383
"type"
=> $tr[
"type"
] ??
null
,
384
"function"
=> $tr[
"function"
] ??
null
,
385
"args"
=> $args,
386
];
387
}
388
return
$filtered;
389
}
390
}
Bitrix\Main\Diag\Helper\getCurrentMicrotime
static getCurrentMicrotime()
Definition
helper.php:11
Bitrix\Main\Diag\Helper\getBackTrace
static getBackTrace($limit=0, $options=null, $skip=1)
Definition
helper.php:26
Bitrix\Main\Diag\SqlTracker
Definition
sqltracker.php:8
Bitrix\Main\Diag\SqlTrackerQuery
Definition
sqltrackerquery.php:5
Bitrix\Main\Diag\SqlTrackerQuery\$sql
$sql
Definition
sqltrackerquery.php:7
Bitrix\Main\Diag\SqlTrackerQuery\getBinds
getBinds()
Definition
sqltrackerquery.php:119
Bitrix\Main\Diag\SqlTrackerQuery\refinishQuery
refinishQuery()
Definition
sqltrackerquery.php:84
Bitrix\Main\Diag\SqlTrackerQuery\$node
$node
Definition
sqltrackerquery.php:13
Bitrix\Main\Diag\SqlTrackerQuery\offsetUnset
offsetUnset($offset)
Definition
sqltrackerquery.php:322
Bitrix\Main\Diag\SqlTrackerQuery\offsetExists
offsetExists($offset)
Definition
sqltrackerquery.php:258
Bitrix\Main\Diag\SqlTrackerQuery\setSql
setSql($sql)
Definition
sqltrackerquery.php:108
Bitrix\Main\Diag\SqlTrackerQuery\setBinds
setBinds(array $binds)
Definition
sqltrackerquery.php:132
Bitrix\Main\Diag\SqlTrackerQuery\getNode
getNode()
Definition
sqltrackerquery.php:167
Bitrix\Main\Diag\SqlTrackerQuery\$tracker
$tracker
Definition
sqltrackerquery.php:23
Bitrix\Main\Diag\SqlTrackerQuery\$startTime
$startTime
Definition
sqltrackerquery.php:15
Bitrix\Main\Diag\SqlTrackerQuery\setTrace
setTrace(array $trace)
Definition
sqltrackerquery.php:244
Bitrix\Main\Diag\SqlTrackerQuery\getTime
getTime()
Definition
sqltrackerquery.php:191
Bitrix\Main\Diag\SqlTrackerQuery\offsetGet
offsetGet($offset)
Definition
sqltrackerquery.php:282
Bitrix\Main\Diag\SqlTrackerQuery\filterTrace
filterTrace($trace)
Definition
sqltrackerquery.php:333
Bitrix\Main\Diag\SqlTrackerQuery\$trace
$trace
Definition
sqltrackerquery.php:21
Bitrix\Main\Diag\SqlTrackerQuery\$finishTime
$finishTime
Definition
sqltrackerquery.php:17
Bitrix\Main\Diag\SqlTrackerQuery\$time
$time
Definition
sqltrackerquery.php:19
Bitrix\Main\Diag\SqlTrackerQuery\setNode
setNode($node)
Definition
sqltrackerquery.php:180
Bitrix\Main\Diag\SqlTrackerQuery\__construct
__construct(SqlTracker $tracker)
Definition
sqltrackerquery.php:28
Bitrix\Main\Diag\SqlTrackerQuery\setState
setState($state)
Definition
sqltrackerquery.php:156
Bitrix\Main\Diag\SqlTrackerQuery\startQuery
startQuery($sql, array $binds=null)
Definition
sqltrackerquery.php:41
Bitrix\Main\Diag\SqlTrackerQuery\finishQuery
finishQuery($skip=3)
Definition
sqltrackerquery.php:55
Bitrix\Main\Diag\SqlTrackerQuery\addTime
addTime($time)
Definition
sqltrackerquery.php:219
Bitrix\Main\Diag\SqlTrackerQuery\offsetSet
offsetSet($offset, $value)
Definition
sqltrackerquery.php:310
Bitrix\Main\Diag\SqlTrackerQuery\restartQuery
restartQuery()
Definition
sqltrackerquery.php:72
Bitrix\Main\Diag\SqlTrackerQuery\getSql
getSql()
Definition
sqltrackerquery.php:95
Bitrix\Main\Diag\SqlTrackerQuery\setTime
setTime($time)
Definition
sqltrackerquery.php:204
Bitrix\Main\Diag\SqlTrackerQuery\$state
$state
Definition
sqltrackerquery.php:11
Bitrix\Main\Diag\SqlTrackerQuery\getTrace
getTrace()
Definition
sqltrackerquery.php:231
Bitrix\Main\Diag\SqlTrackerQuery\getState
getState()
Definition
sqltrackerquery.php:143
Bitrix\Main\Diag\SqlTrackerQuery\$binds
$binds
Definition
sqltrackerquery.php:9
Bitrix\Main\Diag
Definition
cachetracker.php:2
modules
main
lib
diag
sqltrackerquery.php
Создано системой
1.10.0