mMsgs = []; $this->mStart = microtime(true); } static public function instance() { if(self::$stInstance == NULL) { self::$stInstance = new performance_helper(); } return self::$stInstance; } public function start() { $this->mStart = microtime(true); } public function push($tag,$info = '',$start = NULL) { if($start == NULL) { $start = $this->mStart; $this->mStart = microtime(true); } if(empty($info)) { $msg = sprintf("%s:%.6f",$tag,microtime(true) - $start); } else { $msg = sprintf("%s:%.6f,info=",$tag,microtime(true) - $start); $msg = $msg.$info; } array_push($this->mMsgs,$msg); } public function clear() { $this->mMsgs = []; } public function format_log() { $content = ''; foreach($this->mMsgs as $val) { $content .= $val . "\n"; } return $content; } } function perfor_start() { if(defined('PERFORMANCE_MONITOR') && PERFORMANCE_MONITOR) { performance_helper::instance()->start(); } } function perfor_log() { if(defined('PERFORMANCE_MONITOR') && PERFORMANCE_MONITOR) { return performance_helper::instance()->format_log(); } else { return []; } } function perfor_end($tag,$info = '') { if(defined('PERFORMANCE_MONITOR') && PERFORMANCE_MONITOR) { performance_helper::instance()->push($tag, $info); } } function perfor_period($tag,$start,$info = '') { if(defined('PERFORMANCE_MONITOR') && PERFORMANCE_MONITOR) { performance_helper::instance()->push($tag, $info, $start); } } function perfor_clear() { if(defined('PERFORMANCE_MONITOR') && PERFORMANCE_MONITOR) { performance_helper::instance()->clear(); } }