diff options
| author | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-11-27 10:35:11 +0000 |
|---|---|---|
| committer | artem <artem@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-11-27 10:35:11 +0000 |
| commit | 1bd6dc62e58531f845b82f6192f7eb009aea400f (patch) | |
| tree | 40ffcda3f1b6a7ad9b53e19a81ea47aa907d1e7e /frontends/php/include/copt.lib.php | |
| parent | 98ce4eb6a912de7878aa3632c8de0fecd22455c8 (diff) | |
| download | zabbix-1bd6dc62e58531f845b82f6192f7eb009aea400f.tar.gz zabbix-1bd6dc62e58531f845b82f6192f7eb009aea400f.tar.xz zabbix-1bd6dc62e58531f845b82f6192f7eb009aea400f.zip | |
- [NTT-66] merged rev. 5100:5102 of branches/1.4.j/ (Artem) [tuning performance for "Status of Triggers";changes in SCHEMA, index events_1 now: {object,objectid,eventid}]
git-svn-id: svn://svn.zabbix.com/trunk@5103 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/copt.lib.php')
| -rw-r--r-- | frontends/php/include/copt.lib.php | 329 |
1 files changed, 153 insertions, 176 deletions
diff --git a/frontends/php/include/copt.lib.php b/frontends/php/include/copt.lib.php index ec1cb294..ae0d97eb 100644 --- a/frontends/php/include/copt.lib.php +++ b/frontends/php/include/copt.lib.php @@ -86,20 +86,19 @@ ** Eugene Grigorjev (eugene.grigorjev@zabbix.com) **/ -// define("USE_PROFILING",1); - define("USE_VAR_MON",1); - define("USE_TIME_PROF",1); - define("USE_MEM_PROF",1); - define("USE_COUNTER_PROF",1); - define("USE_MENU_PROF",1); - //define("USE_MENU_DETAILS",1); - define("USE_SQLREQUEST_PROF",1); - //define("SHOW_SQLREQUEST_DETAILS",1); +//define("USE_PROFILING",1); +define("USE_VAR_MON",1); +define("USE_TIME_PROF",1); +define("USE_MEM_PROF",1); +define("USE_COUNTER_PROF",1); +define("USE_MENU_PROF",1); +//define("USE_MENU_DETAILS",1); +define("USE_SQLREQUEST_PROF",1); +//define("SHOW_SQLREQUEST_DETAILS",1); + +if(!defined('OBR')) define('OBR',"<br/>\n"); - if(!defined("OBR")) define("OBR","<br/>\n"); - -if(defined('USE_PROFILING')) -{ +if(defined('USE_PROFILING')){ $starttime=array(); $memorystamp=array(); $sqlrequests = defined('SHOW_SQLREQUEST_DETAILS') ? array() : 0; @@ -107,56 +106,51 @@ if(defined('USE_PROFILING')) $perf_counter = array(); $var_list = array(); - class COpt - { + class COpt{ /* protected static $starttime[]=array(); */ - - /* protected static */ function getmicrotime() { -if(defined('USE_TIME_PROF')) { - list($usec, $sec) = explode(' ',microtime()); return ((float)$usec + (float)$sec); -}else { - return 0; -} + /* protected */ static function getmicrotime() { + if(defined('USE_TIME_PROF')) { + list($usec, $sec) = explode(' ',microtime()); + return ((float)$usec + (float)$sec); + } + else { + return 0; + } } - /* public static */ function showmemoryusage($descr=null) - { -if(defined('USE_MEM_PROF')) { - $memory_usage = COpt::getmemoryusage(); - $memory_usage = $memory_usage.'b | '.($memory_usage>>10).'K | '.($memory_usage>>20).'M'; - SDI('PHP memory usage ['.$descr.'] '.$memory_usage); -} + /* public */ static function showmemoryusage($descr=null){ + if(defined('USE_MEM_PROF')) { + $memory_usage = COpt::getmemoryusage(); + $memory_usage = $memory_usage.'b | '.($memory_usage>>10).'K | '.($memory_usage>>20).'M'; + SDI('PHP memory usage ['.$descr.'] '.$memory_usage); + } } - /* protected static */ function getmemoryusage() { -if(defined('USE_MEM_PROF')) { - return memory_get_usage('memory_limit'); -} else { - return 0; -} + /* protected */ static function getmemoryusage() { + if(defined('USE_MEM_PROF')) { + return memory_get_usage('memory_limit'); + } else { + return 0; + } } - /* public static */ function counter_up($type=NULL) - { -if(defined('USE_COUNTER_PROF')) -{ - global $perf_counter; - global $starttime; + /* public */ static function counter_up($type=NULL){ + if(defined('USE_COUNTER_PROF')){ + global $perf_counter; + global $starttime; - foreach(array_keys($starttime) as $keys) - { - if(!isset($perf_counter[$keys][$type])) - $perf_counter[$keys][$type]=1; - else - $perf_counter[$keys][$type]++; + foreach(array_keys($starttime) as $keys){ + if(!isset($perf_counter[$keys][$type])) + $perf_counter[$keys][$type]=1; + else + $perf_counter[$keys][$type]++; + } } -} } - /* public static */ function profiling_start($type=NULL) - { + /* public */ static function profiling_start($type=NULL){ global $starttime; global $memorystamp; global $sqlmark; @@ -167,37 +161,33 @@ if(defined('USE_COUNTER_PROF')) $starttime[$type] = COpt::getmicrotime(); $memorystamp[$type] = COpt::getmemoryusage(); -if(defined('USE_VAR_MON')) -{ + if(defined('USE_VAR_MON')){ + $var_list[$type] = isset($GLOBALS) ? array_keys($GLOBALS) : array(); + } - $var_list[$type] = isset($GLOBALS) ? array_keys($GLOBALS) : array(); -} -if(defined('USE_SQLREQUEST_PROF')) -{ - if(defined('SHOW_SQLREQUEST_DETAILS')){ - $sqlmark[$type] = count($sqlrequests); - } - else { - $sqlmark[$type] = $sqlrequests; - } -} + if(defined('USE_SQLREQUEST_PROF')){ + if(defined('SHOW_SQLREQUEST_DETAILS')){ + $sqlmark[$type] = count($sqlrequests); + } + else{ + $sqlmark[$type] = $sqlrequests; + } + } } - /* public static */ function savesqlrequest($sql) - { -if(defined('USE_SQLREQUEST_PROF')) -{ - global $sqlrequests; - if(defined('SHOW_SQLREQUEST_DETAILS')){ - array_push($sqlrequests, $sql); - }else{ - $sqlrequests++; - } -} + /* public */ static function savesqlrequest($sql){ + if(defined('USE_SQLREQUEST_PROF')){ + global $sqlrequests; + if(defined('SHOW_SQLREQUEST_DETAILS')){ + array_push($sqlrequests, $sql); + } + else{ + $sqlrequests++; + } + } } - /* public static */ function profiling_stop($type=NULL) - { + /* public */ static function profiling_stop($type=NULL){ global $starttime; global $memorystamp; global $sqlrequests; @@ -211,126 +201,113 @@ if(defined('USE_SQLREQUEST_PROF')) if(is_null($type)) $type='global'; echo OBR; -if(defined('USE_TIME_PROF')) -{ - echo "(".$type.") Time to execute: ".round($endtime - $starttime[$type],6)." seconds!".OBR; -} -if(defined('USE_MEM_PROF')) -{ - echo "(".$type.") Memory limit : ".ini_get('memory_limit').OBR; - echo "(".$type.") Memory usage : ".mem2str($memorystamp[$type])." - ".mem2str($memory).OBR; - echo "(".$type.") Memory leak : ".mem2str($memory - $memorystamp[$type]).OBR; -} -if(defined('USE_VAR_MON')) -{ - $curr_var_list = isset($GLOBALS) ? array_keys($GLOBALS) : array(); - $var_diff = array_diff($curr_var_list, $var_list[$type]); - echo "(".$type.") Undeleted vars : ".count($var_diff)." ["; - print_r(implode(', ',$var_diff)); - echo "]".OBR; -} -if(defined('USE_COUNTER_PROF')) -{ - if(isset($perf_counter[$type])) - { - ksort($perf_counter[$type]); - foreach($perf_counter[$type] as $name => $value) - { - echo "(".$type.") Counter '".$name."' : ".$value.OBR; + if(defined('USE_TIME_PROF')){ + echo '('.$type.') Time to execute: '.round($endtime - $starttime[$type],6).' seconds!'.OBR; + } + + if(defined('USE_MEM_PROF')){ + echo '('.$type.') Memory limit : '.ini_get('memory_limit').OBR; + echo '('.$type.') Memory usage : '.mem2str($memorystamp[$type]).' - '.mem2str($memory).OBR; + echo '('.$type.') Memory leak : '.mem2str($memory - $memorystamp[$type]).OBR; + } + + if(defined('USE_VAR_MON')){ + $curr_var_list = isset($GLOBALS) ? array_keys($GLOBALS) : array(); + $var_diff = array_diff($curr_var_list, $var_list[$type]); + echo '('.$type.') Undeleted vars : '.count($var_diff).' ['; + print_r(implode(', ',$var_diff)); + echo ']'.OBR; + } + + if(defined('USE_COUNTER_PROF')){ + + if(isset($perf_counter[$type])){ + ksort($perf_counter[$type]); + foreach($perf_counter[$type] as $name => $value){ + echo '('.$type.') Counter "'.$name.'" : '.$value.OBR; + } } } -} -if(defined('USE_SQLREQUEST_PROF')) -{ - if(defined('SHOW_SQLREQUEST_DETAILS')) - { - $requests_cnt = count($sqlrequests); - echo "(".$type.") SQL requests count: ".($requests_cnt - $sqlmark[$type]).OBR; - for($i = $sqlmark[$type]; $i < $requests_cnt; $i++) - { - echo "(".$type.") SQL request : ".$sqlrequests[$i].OBR; + if(defined('USE_SQLREQUEST_PROF')){ + if(defined('SHOW_SQLREQUEST_DETAILS')){ + $requests_cnt = count($sqlrequests); + echo '('.$type.') SQL requests count: '.($requests_cnt - $sqlmark[$type]).OBR; + + for($i = $sqlmark[$type]; $i < $requests_cnt; $i++){ + echo '('.$type.') SQL request : '.$sqlrequests[$i].OBR; + } + } + else{ + echo '('.$type.') SQL requests count: '.($sqlrequests - $sqlmark[$type]).OBR; + } } - } - else - { - echo "(".$type.") SQL requests count: ".($sqlrequests - $sqlmark[$type]).OBR; - } -} } - /* public static */ function set_memory_limit($limit='8M') - { + /* public */ static function set_memory_limit($limit='8M'){ ini_set('memory_limit',$limit); } - /* public static */ function compare_files_with_menu($menu=null) - { -if(defined('USE_MENU_PROF')) -{ - $files_list = glob('*.php'); - - $result = array(); - foreach($files_list as $file) - { - $list = array(); - foreach($menu as $label=>$sub) - { - foreach($sub['pages'] as $sub_pages) - { - if(!isset($sub_pages["label"])) $sub_pages["label"]=$sub_pages['url']; - - $menu_path = $sub["label"].'->'.$sub_pages["label"]; - - if($sub_pages['url'] == $file) - { - array_push($list, $menu_path); - } - if(!in_array($sub_pages['url'], $files_list)) - $result['error'][$sub_pages['url']] = array($menu_path); - - if(isset($sub_pages['sub_pages'])) foreach($sub_pages['sub_pages'] as $page) - { - $menu_path = $sub["label"].'->'.$sub_pages["label"].'->sub_pages'; + /* public */ static function compare_files_with_menu($menu=null){ + if(defined('USE_MENU_PROF')){ + + $files_list = glob('*.php'); + + $result = array(); + foreach($files_list as $file){ + $list = array(); + foreach($menu as $label=>$sub){ + foreach($sub['pages'] as $sub_pages){ + if(empty($sub_pages)) continue; - if(!in_array($page, $files_list)) - $result['error'][$page] = array($menu_path); - - if($page != $file) continue; - array_push($list, $menu_path); + if(!isset($sub_pages['label'])) $sub_pages['label']=$sub_pages['url']; + + $menu_path = $sub['label'].'->'.$sub_pages['label']; + + if($sub_pages['url'] == $file){ + array_push($list, $menu_path); + } + if(!in_array($sub_pages['url'], $files_list)) + $result['error'][$sub_pages['url']] = array($menu_path); + + if(isset($sub_pages['sub_pages'])) foreach($sub_pages['sub_pages'] as $page){ + $menu_path = $sub['label'].'->'.$sub_pages['label'].'->sub_pages'; + + if(!in_array($page, $files_list)) + $result['error'][$page] = array($menu_path); + + if($page != $file) continue; + array_push($list, $menu_path); + } } } - } - if(count($list) != 1) $level = 'worning'; - else $level = 'normal'; + + if(count($list) != 1) $level = 'worning'; + else $level = 'normal'; - $result[$level][$file] = $list; - } - foreach($result as $level => $files_list) - { -if(defined('USE_MENU_DETAILS')) -{ - echo OBR.'(menu check) ['.$level.OBR; - foreach($files_list as $file => $menu_list) - { - echo "(menu check)".SPACE.SPACE.SPACE.SPACE.$file.' {'.implode(',',$menu_list)."}".OBR; + $result[$level][$file] = $list; + } + + foreach($result as $level => $files_list){ + if(defined('USE_MENU_DETAILS')){ + echo OBR.'(menu check) ['.$level.OBR; + foreach($files_list as $file => $menu_list){ + echo '(menu check)'.SPACE.SPACE.SPACE.SPACE.$file.' {'.implode(',',$menu_list).'}'.OBR; + } + } + else{ + echo OBR.'(menu check) ['.$level.'] = '.count($files_list).OBR; + } } -} -else -{ - echo OBR.'(menu check) ['.$level."] = ".count($files_list).OBR; -} } -} } } - COpt::set_memory_limit('8M'); - COpt::profiling_start("script"); + COpt::set_memory_limit('320M'); + COpt::profiling_start('script'); } -else -{ +else{ $static = null; if(version_compare(phpversion(),'5.0','>=')) $static = 'static'; |
