class_mcPerformance.inc.php
7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?
class mcPerformance {
private static $StaticCalls = array();
private static function prepareStaticCalls($param_ClassName, $param_FncName, array $param_toDiffParams=array()) {
if(!array_key_exists($param_ClassName, mcPerformance::$StaticCalls)) {
mcPerformance::$StaticCalls[$param_ClassName] = array();
}
if(!array_key_exists($param_FncName, mcPerformance::$StaticCalls[$param_ClassName])) {
mcPerformance::$StaticCalls[$param_ClassName][$param_FncName] = array( );
}
global $__mcPerformance_backtrace;
if($__mcPerformance_backtrace) {
$string_backtrace = D::getBacktrace($param_htmltags=false, $param_start=2, $param_end=2);
} else {
$string_backtrace = '__mcPerformance_backtrace = false';
}
$toDiffParams = serialize($param_toDiffParams);
$obj_key = null;
$count_objects = count(mcPerformance::$StaticCalls[$param_ClassName][$param_FncName]);
for($i=0; $i<$count_objects; $i++ ) {
if(mcPerformance::$StaticCalls[$param_ClassName][$param_FncName][$i]['param'] === $toDiffParams) {
$obj_key = $i;
}
}
if(is_null($obj_key)) {
mcPerformance::$StaticCalls[$param_ClassName][$param_FncName][] = array('count'=>1, 'param' => $toDiffParams, 'backtraceStrings' => array($string_backtrace));
} else {
mcPerformance::$StaticCalls[$param_ClassName][$param_FncName][$obj_key]['count']++;
mcPerformance::$StaticCalls[$param_ClassName][$param_FncName][$obj_key]['backtraceStrings'][] = $string_backtrace;
}
}
private static $ObjectCalls = array();
private static function prepareObjectCalls($param_ClassName, $param_FncName, &$param_Object, array $param_toDiffParams=array()) {
if(!array_key_exists($param_ClassName, mcPerformance::$ObjectCalls)) {
mcPerformance::$ObjectCalls[$param_ClassName] = array();
}
if(!array_key_exists($param_FncName, mcPerformance::$ObjectCalls[$param_ClassName])) {
mcPerformance::$ObjectCalls[$param_ClassName][$param_FncName] = array( );
}
global $__mcPerformance_backtrace;
if($__mcPerformance_backtrace) {
$string_backtrace = D::getBacktrace($param_htmltags=false, $param_start=2, $param_end=2);
} else {
$string_backtrace ='__mcPerformance_backtrace = false';
}
if(array_search('getID', get_class_methods($param_ClassName))) {
$getIDFnc = true;
if(!array_key_exists($param_Object->getID(), mcPerformance::$ObjectCalls[$param_ClassName][$param_FncName])) {
mcPerformance::$ObjectCalls[$param_ClassName][$param_FncName][$param_Object->getID()] = array( );
}
$ObjArray = &mcPerformance::$ObjectCalls[$param_ClassName][$param_FncName][$param_Object->getID()];
} else {
$getIDFnc = false;
$ObjArray = &mcPerformance::$ObjectCalls[$param_ClassName][$param_FncName];
}
$toDiffParams = serialize($param_toDiffParams);
$obj_key = null;
$count_objects = count($ObjArray);
for($i=0; $i<$count_objects; $i++ ) {
if($param_Object === $ObjArray[$i]['object'] && $ObjArray[$i]['param'] === $toDiffParams) {
$obj_key = $i;
}
}
if(is_null($obj_key)) {
$ObjArray[] = array('count'=>1, 'object' => &$param_Object, 'param' => $toDiffParams, 'backtraceStrings' => array($string_backtrace));
} else {
$ObjArray[$obj_key]['count']++;
$ObjArray[$obj_key]['backtraceStrings'][] = $string_backtrace;
}
}
/**
* erstellt eine kleine Statistik über die Funktion in der checkMultipleCalls() aufgerufen wird
* Statistik kann über mcPerformance::showStats() angezeigt werden
*
* @param array $param_toDiffParams default array() --- wenn gesetzt, unterscheidet fnc auch nach Parametern
*/
public static function checkMultipleCalls(array $param_toDiffParams=array()) {
global $_LOSP_DEV;
if($_LOSP_DEV) {
$array_backtrace = debug_backtrace();
/**
* static class function call
*/
if($array_backtrace[1]['type'] == '::') {
mcPerformance::prepareStaticCalls($array_backtrace[1]['class'], $array_backtrace[1]['function'], $param_toDiffParams);
/**
* object function call
*/
} else if($array_backtrace[1]['type'] == '->') {
mcPerformance::prepareObjectCalls($array_backtrace[1]['class'], $array_backtrace[1]['function'], $array_backtrace[1]['object'], $param_toDiffParams);
} else {
D::li('type ('.$array_backtrace[1]['type'].') not implemantated');
}
}
}
public static function showStats() {
global $_LOSP_DEV;
if($_LOSP_DEV) {
D::h1('static calls');
foreach(mcPerformance::$StaticCalls as $classname => $fnc) {
D::li('<b>'.$classname.'</b>');
foreach($fnc as $fncname => $FncCalls) {
D::ulli('<b>'.$fncname.' with '.count($FncCalls).' different fnc calls </b>');
$allFncCalls = 0;
foreach($FncCalls as $FncCall) {
$backtraceString = '';
foreach($FncCall['backtraceStrings'] as $index => $string_backtrace) {
if($index==0) {
$backtraceString .= '<i title="'.$string_backtrace.'">'.$index.'</i> ';
} else {
$backtraceString .= '- <b><i title="'.$string_backtrace.'">'.$index.'</i></b> ';
}
}
$string_param = str_replace('"', '', $FncCall['param']);
if(strlen($string_param) < 32) {
$string4param = " ".$string_param." ";
} else {
$string4param = ' <u title="'.$string_param.'">'.md5($FncCall['param'])."</u> ";
}
D::ulli('<i>'.$fncname.'('.$string4param.') wurde '.$FncCall['count'].' aufgerufen</i>'.' backtrace '.$backtraceString);
$allFncCalls += $FncCall['count'];
}
D::ulli('<b>'.$fncname.' general: '.$allFncCalls.' </b>');
}
}
D::h1('object calls');
foreach(mcPerformance::$ObjectCalls as $classname => $fnc) {
if(array_search('getID', get_class_methods($classname))) {
$getIDFnc = true;
} else {
$getIDFnc = false;
}
D::li('<b>'.$classname.'</b>');
foreach($fnc as $fncname => $objects) {
if($getIDFnc) {
D::ulli('<b>'.$fncname.' mit '.count($objects).' unterschiedlichen objects </b>');
foreach($objects as $objID => $objIDArray) {
D::ulli('<b><i>'.$objID.' => wurde '.count($objIDArray).' geladen</i></b>');
foreach($objIDArray as $obj) {
if(strlen($obj['param']) < 32) {
$string4param = "\t Param(".$obj['param'].")";
} else {
$string4param = "\t Param_md5(".md5($obj['param']).")";
}
$backtraceString = '';
foreach($obj['backtraceStrings'] as $index => $string_backtrace) {
if($index==0) {
$backtraceString .= '<i title="'.$string_backtrace.'">'.$index.'</i> ';
} else {
$backtraceString .= '- <b><i title="'.$string_backtrace.'">'.$index.'</i></b> ';
}
}
D::ulli($obj['object'].' => '.$obj['count'].' x '.$fncname. $string4param.' backtrace '.$backtraceString);
}
}
} else {
D::ulli('<b>'.$fncname.' mit '.count($objects).' objects</b>');
foreach($objects as $obj) {
$string_param = str_replace('"', '', $obj['param']);
if(strlen($string_param) < 32) {
$string4param = "\t Param(".$string_param.")";
} else {
$string4param = ' <i title="'.$string_param.'">Param_md5('.md5($obj['param']).")</i>";
}
$backtraceString = '';
foreach($obj['backtraceStrings'] as $index => $string_backtrace) {
if($index==0) {
$backtraceString .= '<i title="'.$string_backtrace.'">'.$index.'</i> ';
} else {
$backtraceString .= '- <b><i title="'.$string_backtrace.'">'.$index.'</i></b> ';
}
}
D::ulli($obj['object'].' => '.$obj['count'].' x '.$fncname. $string4param.' backtrace '.$backtraceString);
}
}
}
}
}
}
}
?>