summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/copt.lib.php
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-12 14:23:12 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-12 14:23:12 +0000
commit4182bc6afb20b00fa27a54c67056bb98a58a49bb (patch)
tree5cab17d23e387cc3b6e8c92e4c928ac5e1111b76 /frontends/php/include/copt.lib.php
parent6a6ac0772b8215bffc5fe8b02fc1033dbf273f41 (diff)
downloadzabbix-4182bc6afb20b00fa27a54c67056bb98a58a49bb.tar.gz
zabbix-4182bc6afb20b00fa27a54c67056bb98a58a49bb.tar.xz
zabbix-4182bc6afb20b00fa27a54c67056bb98a58a49bb.zip
- speed improvement for Overview screens (Eugene)
- developed 'net.if.total[*]' parameter (Eugene) - fixed new map link adding (Eugene) - fixed host group adding (Eugene) - fixed map displaying (Eugene) - fixed 'No permissions' for 'Latest data','Triggers','Alarms' screens (Eugene) - fixed permision deletion (Eugene) - fixed 'get_map_by_sysmapid' function calls(Eugene) - improved php code execution speed (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2825 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/copt.lib.php')
-rw-r--r--frontends/php/include/copt.lib.php98
1 files changed, 90 insertions, 8 deletions
diff --git a/frontends/php/include/copt.lib.php b/frontends/php/include/copt.lib.php
index ce1b3b05..98d65fd1 100644
--- a/frontends/php/include/copt.lib.php
+++ b/frontends/php/include/copt.lib.php
@@ -86,40 +86,121 @@
** Eugene Grigorjev (eugene.grigorjev@zabbix.com)
**/
- define("USE_PROFILING",1);
+// define("USE_PROFILING",1);
+ define("USE_TIME_PROF",1);
+ define("USE_MEM_PROF",1);
+ define("USE_SQLREQUEST_PROF",1);
+// define("SHOW_SQLREQUEST_DETAILS",1);
if(defined('USE_PROFILING'))
{
- $starttime[]=array();
+ $starttime=array();
+ $memorystamp=array();
+ $sqlrequests=array();
+ $sqlmark = array();
class COpt
{
/* protected static $starttime[]=array(); */
+
/* protected static */ function getmicrotime()
{
- list($usec, $sec) = explode(" ",microtime());
+ list($usec, $sec) = explode(' ',microtime());
return ((float)$usec + (float)$sec);
}
+
+ /* protected static */ function getmemoryusage()
+ {
+ return memory_get_usage('memory_limit');
+ }
+
+ /* protected static */ function mem2str($size)
+ {
+ $prefix = 'B';
+ if($size > 1048576) { $size = $size/1048576; $prefix = 'M'; }
+ elseif($size > 1024) { $size = $size/1024; $prefix = 'K'; }
+ return round($size, 6).$prefix;
+ }
+
/* public static */ function profiling_start($type=NULL)
{
global $starttime;
- if(is_null($type)) $type="global";
+ global $memorystamp;
+ global $sqlmark;
+ global $sqlrequests;
+
+ if(is_null($type)) $type='global';
+if(defined('USE_TIME_PROF'))
+{
$starttime[$type] = COpt::getmicrotime();
+}
+if(defined('USE_MEM_PROF'))
+{
+ $memorystamp[$type] = COpt::getmemoryusage();
+}
+if(defined('USE_SQLREQUEST_PROF'))
+{
+ $sqlmark[$type] = count($sqlrequests);
+}
}
+
+ /* public static */ function savesqlrequest($sql)
+ {
+if(defined('USE_SQLREQUEST_PROF'))
+{
+ global $sqlrequests;
+ array_push($sqlrequests, $sql);
+}
+ }
+
/* public static */ function profiling_stop($type=NULL)
{
global $starttime;
+ global $memorystamp;
+ global $sqlrequests;
+ global $sqlmark;
$endtime = COpt::getmicrotime();
+ $memory = COpt::getmemoryusage();
- if(is_null($type)) $type="global";
-// echo "<br/>\nTime to execute (".$type."): ". bcsub($endtime,$starttime[$type],6)." seconds!\n<br/>";
- echo "<br/>\nTime to execute (".$type."): ".($endtime-$starttime[$type])." seconds!\n<br/>";
+ if(is_null($type)) $type='global';
+
+ echo "<br>\n";
+if(defined('USE_TIME_PROF'))
+{
+ echo "(".$type.") Time to execute: ".round($endtime - $starttime[$type],6)." seconds!\n<br>\n";
+}
+if(defined('USE_MEM_PROF'))
+{
+ echo "(".$type.") Memory limit : ".ini_get('memory_limit')."<br>\n";
+ echo "(".$type.") Memory usage : ".COpt::mem2str($memorystamp[$type])." - ".COpt::mem2str($memory)."\n<br>\n";
+ echo "(".$type.") Memory leak : ".COpt::mem2str($memory - $memorystamp[$type])."\n<br>\n";
+}
+if(defined('USE_SQLREQUEST_PROF'))
+{
+ $requests_cnt = count($sqlrequests);
+ echo "(".$type.") SQL requests count: ".($requests_cnt - $sqlmark[$type])."<br>\n";
+ if(defined('SHOW_SQLREQUEST_DETAILS'))
+ {
+ for($i = $sqlmark[$type]; $i < $requests_cnt; $i++)
+ {
+ echo "(".$type.") SQL request : ".$sqlrequests[$i]."<br>\n";;
+ }
+ }
+}
+ }
+
+
+ /* public static */ function set_memory_limit($limit='8M')
+ {
+ ini_set('memory_limit',$limit);
}
}
- COpt::profiling_start("page");
+
+ COpt::set_memory_limit('8M');
+ COpt::profiling_start("script");
}
else
{
@@ -127,6 +208,7 @@ else
{
/* public static */ function profiling_start($type=NULL) {}
/* public static */ function profiling_stop($type=NULL) {}
+ /* public static */ function savesqlrequest($sql) {}
}
}