Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
cachetracker.php
1<?php
3
4
6{
7 private static $cacheStatBytes = 0;
8 private static $arCacheDebug = array();
9
10 private static $skipUntil = array(
11 "bitrix\\main\\diag\\cachetracker::add" => true,
12 "bitrix\\main\\data\\cache->initcache" => true,
13 "bitrix\\main\\data\\cache->startdatacache" => true,
14 "bitrix\\main\\data\\cache->enddatacache" => true,
15 "bitrix\\main\\data\\cache->clean" => true,
16 "bitrix\\main\\data\\cache->cleandir" => true,
17 "bitrix\\main\\data\\managedcache->read" => true,
18 "bitrix\\main\\data\\managedcache->setimmediate" => true,
19 "bitrix\\main\\data\\managedcache->clean" => true,
20 "bitrix\\main\\data\\managedcache->cleandir" => true,
21 "bitrix\\main\\data\\managedcache->cleanall" => true,
22 "cbitrixcomponent->startresultcache" => true,
23 );
24
28 public static function setCacheStatBytes($cacheStatBytes)
29 {
30 self::$cacheStatBytes = $cacheStatBytes;
31 }
32
33 public static function addCacheStatBytes($cacheStatBytes)
34 {
35 self::$cacheStatBytes += $cacheStatBytes;
36 }
37
38 public static function getCacheStatBytes()
39 {
40 return self::$cacheStatBytes;
41 }
42
43 public static function add($size, $path, $baseDir, $initDir, $filename, $operation)
44 {
45 $prev = array();
46 $found = -1;
47 foreach (Helper::getBackTrace(8) as $tr)
48 {
49 $func = ($tr["class"] ?? '') . ($tr["type"] ?? '') . ($tr["function"] ?? '');
50
51 if ($found < 0 && !isset(self::$skipUntil[mb_strtolower($func)]))
52 {
53 $found = count(self::$arCacheDebug);
54 self::$arCacheDebug[$found] = array(
55 "TRACE" => array(),
56 "path" => $path,
57 "basedir" => $baseDir,
58 "initdir" => $initDir,
59 "filename" => $filename,
60 "cache_size" => $size,
61 "callee_func" => $prev["class"].$prev["type"].$prev["function"],
62 "operation" => $operation,
63 );
64 self::$arCacheDebug[$found]["TRACE"][] = array(
65 "func" => $prev["class"].$prev["type"].$prev["function"],
66 "args" => array(),
67 "file" => $prev["file"],
68 "line" => $prev["line"],
69 );
70 }
71
72 if ($found > -1)
73 {
74 if (count(self::$arCacheDebug[$found]["TRACE"]) < 8)
75 {
76 $args = array();
77 if (isset($tr["args"]) && is_array($tr["args"]))
78 {
79 foreach ($tr["args"] as $k1 => $v1)
80 {
81 if (is_array($v1))
82 {
83 foreach ($v1 as $k2 => $v2)
84 {
85 if (is_scalar($v2))
86 $args[$k1][$k2] = $v2;
87 elseif (is_object($v2))
88 $args[$k1][$k2] = get_class($v2);
89 else
90 $args[$k1][$k2] = gettype($v2);
91 }
92 }
93 else
94 {
95 if (is_scalar($v1))
96 $args[$k1] = $v1;
97 elseif (is_object($v1))
98 $args[$k1] = get_class($v1);
99 else
100 $args[$k1] = gettype($v1);
101 }
102 }
103 }
104
105 self::$arCacheDebug[$found]["TRACE"][] = array(
106 "func" => $func,
107 "args" => $args,
108 "file" => $tr["file"] ?? '',
109 "line" => $tr["line"] ?? '',
110 );
111 }
112 else
113 {
114 break;
115 }
116 }
117 $prev = $tr;
118 }
119 }
120
121 public static function getCacheTracking()
122 {
123 return static::$arCacheDebug;
124 }
125
126 public static function setCacheTracking($val)
127 {
128 static::$arCacheDebug = $val;
129 }
130}
static addCacheStatBytes($cacheStatBytes)
static add($size, $path, $baseDir, $initDir, $filename, $operation)
static setCacheStatBytes($cacheStatBytes)
static getBackTrace($limit=0, $options=null, $skip=1)
Definition helper.php:26