~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to frontends/php/include/copt.lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
        ** Author: 
86
86
        **     Eugene Grigorjev (eugene.grigorjev@zabbix.com)
87
87
        **/
88
 
        
 
88
 
89
89
//      define("USE_PROFILING",1);
90
 
//      define("USE_TIME_PROF",1);
91
 
//      define("USE_MEM_PROF",1);
92
 
//      define("USE_SQLREQUEST_PROF",1);
93
 
//      define("SHOW_SQLREQUEST_DETAILS",1);
94
 
 
 
90
        define("USE_VAR_MON",1);
 
91
        define("USE_TIME_PROF",1);
 
92
        define("USE_MEM_PROF",1);
 
93
        define("USE_COUNTER_PROF",1);
 
94
        define("USE_MENU_PROF",1);
 
95
        //define("USE_MENU_DETAILS",1);
 
96
        define("USE_SQLREQUEST_PROF",1);
 
97
        //define("SHOW_SQLREQUEST_DETAILS",1);
 
98
        
 
99
        if(!defined("OBR")) define("OBR","<br/>\n");
 
100
        
95
101
if(defined('USE_PROFILING'))
96
102
{
97
103
        $starttime=array();
98
104
        $memorystamp=array();
99
 
        $sqlrequests=array();
 
105
        $sqlrequests = defined('SHOW_SQLREQUEST_DETAILS') ? array() : 0;
100
106
        $sqlmark = array();
 
107
        $perf_counter = array();
 
108
        $var_list = array();
101
109
 
102
110
        class COpt
103
111
        {
113
121
                }
114
122
 
115
123
 
 
124
                /* public static */ function showmemoryusage($descr=null)
 
125
                {
 
126
if(defined('USE_MEM_PROF')) {
 
127
                        $memory_usage = COpt::getmemoryusage();
 
128
                        $memory_usage = $memory_usage.'b | '.($memory_usage>>10).'K | '.($memory_usage>>20).'M';
 
129
                        SDI('PHP memory usage ['.$descr.'] '.$memory_usage);
 
130
}
 
131
                }
 
132
 
116
133
                /* protected static */ function getmemoryusage() {
117
134
if(defined('USE_MEM_PROF')) {
118
135
                        return memory_get_usage('memory_limit');
121
138
}
122
139
                }
123
140
 
124
 
                /* protected static */ function mem2str($size)
 
141
                /* public static */ function counter_up($type=NULL)
125
142
                {
126
 
                        $prefix = 'B';
127
 
                        if($size > 1048576) {   $size = $size/1048576;  $prefix = 'M'; }
128
 
                        elseif($size > 1024) {  $size = $size/1024;     $prefix = 'K'; }
129
 
                        return round($size, 6).$prefix;
 
143
if(defined('USE_COUNTER_PROF'))
 
144
{
 
145
                        global $perf_counter;
 
146
                        global $starttime;
 
147
 
 
148
                        foreach(array_keys($starttime) as $keys)
 
149
                        {
 
150
                                if(!isset($perf_counter[$keys][$type]))
 
151
                                        $perf_counter[$keys][$type]=1;
 
152
                                else
 
153
                                        $perf_counter[$keys][$type]++;
 
154
                        }
 
155
}
130
156
                }
131
 
 
 
157
                
132
158
                /* public static */ function profiling_start($type=NULL)
133
159
                {
134
160
                        global $starttime;
135
161
                        global $memorystamp;
136
162
                        global $sqlmark;
137
163
                        global $sqlrequests;
 
164
                        global $var_list;
138
165
 
139
166
                        if(is_null($type)) $type='global';
140
167
 
141
168
                        $starttime[$type] = COpt::getmicrotime();
142
169
                        $memorystamp[$type] = COpt::getmemoryusage();
 
170
if(defined('USE_VAR_MON'))
 
171
{
 
172
                        
 
173
                        $var_list[$type] = isset($GLOBALS) ? array_keys($GLOBALS) : array();
 
174
}
143
175
if(defined('USE_SQLREQUEST_PROF'))
144
176
{
 
177
        if(defined('SHOW_SQLREQUEST_DETAILS')){
145
178
                        $sqlmark[$type] = count($sqlrequests);
 
179
        }
 
180
        else {
 
181
                        $sqlmark[$type] = $sqlrequests;
 
182
        }
146
183
}
147
184
                }
148
185
 
151
188
if(defined('USE_SQLREQUEST_PROF'))
152
189
{
153
190
                        global $sqlrequests;
 
191
        if(defined('SHOW_SQLREQUEST_DETAILS')){
154
192
                        array_push($sqlrequests, $sql);
 
193
        }else{
 
194
                        $sqlrequests++;
 
195
        }
155
196
}
156
197
                }
157
198
 
161
202
                        global $memorystamp;
162
203
                        global $sqlrequests;
163
204
                        global $sqlmark;
 
205
                        global $perf_counter;
 
206
                        global $var_list;
164
207
 
165
208
                        $endtime = COpt::getmicrotime();
166
209
                        $memory = COpt::getmemoryusage();
167
210
 
168
211
                        if(is_null($type)) $type='global';
169
212
 
170
 
                        echo "<br>\n";
 
213
                        echo OBR;
171
214
if(defined('USE_TIME_PROF'))
172
215
{
173
 
                        echo "(".$type.") Time to execute: ".round($endtime - $starttime[$type],6)." seconds!\n<br>\n";
 
216
                        echo "(".$type.") Time to execute: ".round($endtime - $starttime[$type],6)." seconds!".OBR;
174
217
}
175
218
if(defined('USE_MEM_PROF'))
176
219
{
177
 
                        echo "(".$type.") Memory limit   : ".ini_get('memory_limit')."<br>\n";
178
 
                        echo "(".$type.") Memory usage   : ".COpt::mem2str($memorystamp[$type])." - ".COpt::mem2str($memory)."\n<br>\n";
179
 
                        echo "(".$type.") Memory leak    : ".COpt::mem2str($memory - $memorystamp[$type])."\n<br>\n";
 
220
                        echo "(".$type.") Memory limit   : ".ini_get('memory_limit').OBR;
 
221
                        echo "(".$type.") Memory usage   : ".mem2str($memorystamp[$type])." - ".mem2str($memory).OBR;
 
222
                        echo "(".$type.") Memory leak    : ".mem2str($memory - $memorystamp[$type]).OBR;
 
223
}
 
224
if(defined('USE_VAR_MON'))
 
225
{
 
226
                        $curr_var_list = isset($GLOBALS) ? array_keys($GLOBALS) : array();
 
227
                        $var_diff = array_diff($curr_var_list, $var_list[$type]);
 
228
                        echo "(".$type.") Undeleted vars : ".count($var_diff)." [";
 
229
                        print_r(implode(', ',$var_diff));
 
230
                        echo "]".OBR;
 
231
}
 
232
if(defined('USE_COUNTER_PROF'))
 
233
{
 
234
                        if(isset($perf_counter[$type]))
 
235
                        {
 
236
                                ksort($perf_counter[$type]);
 
237
                                foreach($perf_counter[$type] as $name => $value)
 
238
                                {
 
239
                                        echo "(".$type.") Counter '".$name."' : ".$value.OBR;
 
240
                                }
 
241
                        }
180
242
}
181
243
if(defined('USE_SQLREQUEST_PROF'))
182
244
{
 
245
        if(defined('SHOW_SQLREQUEST_DETAILS'))
 
246
        {
183
247
                        $requests_cnt = count($sqlrequests);
184
 
                        echo "(".$type.") SQL requests count: ".($requests_cnt - $sqlmark[$type])."<br>\n";
185
 
        if(defined('SHOW_SQLREQUEST_DETAILS'))
186
 
        {
 
248
                        echo "(".$type.") SQL requests count: ".($requests_cnt - $sqlmark[$type]).OBR;
 
249
 
187
250
                        for($i = $sqlmark[$type]; $i < $requests_cnt; $i++)
188
251
                        {
189
 
                                echo "(".$type.") SQL request    : ".$sqlrequests[$i]."<br>\n";;
 
252
                                echo "(".$type.") SQL request    : ".$sqlrequests[$i].OBR;
190
253
                        }
191
254
        }
 
255
        else
 
256
        {
 
257
                        echo "(".$type.") SQL requests count: ".($sqlrequests - $sqlmark[$type]).OBR;
 
258
        }
192
259
}
193
260
                }
194
261
 
197
264
                {
198
265
                        ini_set('memory_limit',$limit);
199
266
                }
 
267
 
 
268
                /* public static */ function compare_files_with_menu($menu=null)
 
269
                {
 
270
if(defined('USE_MENU_PROF'))
 
271
{
 
272
                        $files_list = glob('*.php');
 
273
 
 
274
                        $result = array();
 
275
                        foreach($files_list as $file)
 
276
                        {
 
277
                                $list = array();
 
278
                                foreach($menu as $label=>$sub)
 
279
                                {
 
280
                                        foreach($sub['pages'] as $sub_pages)
 
281
                                        {
 
282
                                                if(!isset($sub_pages["label"])) $sub_pages["label"]=$sub_pages['url'];
 
283
                                                
 
284
                                                $menu_path = $sub["label"].'->'.$sub_pages["label"];
 
285
                                                
 
286
                                                if($sub_pages['url'] == $file)
 
287
                                                {
 
288
                                                        array_push($list, $menu_path);
 
289
                                                }
 
290
                                                if(!in_array($sub_pages['url'], $files_list))
 
291
                                                        $result['error'][$sub_pages['url']] = array($menu_path);
 
292
 
 
293
                                                if(isset($sub_pages['sub_pages'])) foreach($sub_pages['sub_pages'] as $page)
 
294
                                                {
 
295
                                                        $menu_path = $sub["label"].'->'.$sub_pages["label"].'->sub_pages';
 
296
                                                        
 
297
                                                        if(!in_array($page, $files_list))
 
298
                                                                $result['error'][$page] = array($menu_path);
 
299
 
 
300
                                                        if($page != $file) continue;
 
301
                                                        array_push($list, $menu_path);
 
302
                                                }
 
303
                                        }
 
304
                                }
 
305
                                if(count($list) != 1)   $level = 'worning';
 
306
                                else                    $level = 'normal';
 
307
                                
 
308
                                $result[$level][$file] = $list;
 
309
                        }
 
310
                        foreach($result as $level => $files_list)
 
311
                        {
 
312
if(defined('USE_MENU_DETAILS'))
 
313
{
 
314
                                echo OBR.'(menu check) ['.$level.OBR;
 
315
                                foreach($files_list as $file => $menu_list)
 
316
                                {
 
317
                                        echo "(menu check)".SPACE.SPACE.SPACE.SPACE.$file.' {'.implode(',',$menu_list)."}".OBR;
 
318
                                }
 
319
}
 
320
else
 
321
{
 
322
                                echo OBR.'(menu check) ['.$level."] = ".count($files_list).OBR;
 
323
}
 
324
                        }
 
325
}
 
326
                }
200
327
        }
201
328
 
202
329
        COpt::set_memory_limit('8M');
204
331
}
205
332
else
206
333
{
 
334
        $static = null;
 
335
        if(version_compare(phpversion(),'5.0','>='))
 
336
                $static = 'static';
 
337
                
 
338
        eval('
207
339
        class COpt
208
340
        {
209
 
                /* public static */ function profiling_start($type=NULL) {}
210
 
                /* public static */ function profiling_stop($type=NULL) {}
211
 
                /* public static */ function savesqlrequest($sql) {}
212
 
        }
 
341
                '.$static.' function profiling_start($type=NULL) {}
 
342
                '.$static.' function profiling_stop($type=NULL) {}
 
343
                '.$static.' function savesqlrequest($sql) {}
 
344
                '.$static.' function showmemoryusage($descr=null) {}
 
345
                '.$static.' function compare_files_with_menu($menu=null) {}
 
346
                '.$static.' function counter_up($type=NULL) {}
 
347
        }'
 
348
        );
213
349
}
214
350
 
215
351
?>