From: <on...@us...> - 2002-09-18 11:08:48
|
Update of /cvsroot/xoops/xoops-current/html/class In directory usw-pr-cvs1:/tmp/cvs-serv29243 Added Files: xoopslogger.php Log Message: no message --- NEW FILE: xoopslogger.php --- <?php // $Id: xoopslogger.php,v 1.1 2002/09/18 11:08:44 onokazu Exp $ // ------------------------------------------------------------------------- // // XOOPS - PHP Content Management System // // <http://www.xoops.org/> // // ------------------------------------------------------------------------- // // This program is free software; you can redistribute it and/or modify // // it under the terms of the GNU General Public License as published by // // the Free Software Foundation; either version 2 of the License, or // // (at your option) any later version. // // // // This program is distributed in the hope that it will be useful, // // but WITHOUT ANY WARRANTY; without even the implied warranty of // // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software // // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------- // // Author: Kazumi Ono (AKA onokazu) // // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ // // ------------------------------------------------------------------------- // class XoopsLogger{ var $queries = array(); var $blocks = array(); var $logstart = array(); var $logend = array(); function XoopsLogger(){ } function &getInstance(){ static $instance; if (!isset($instance)) { $instance = new XoopsLogger(); } return $instance; } function startTime($name = 'XOOPS'){ $this->logstart[$name] = explode(' ', microtime()); } function stopTime($name = 'XOOPS'){ $this->logend[$name] = explode(' ', microtime()); } function addQuery($sql, $error=NULL, $errno=NULL){ $this->queries[] = array('sql' => $sql, 'error' => $error, 'errno' => $errno); } function addBlock($name, $cached = false, $cachetime = 0){ $this->blocks[] = array('name' => $name, 'cached' => $cached, 'cachetime' => $cachetime); } function dumpQueries(){ $ret = '<div style="margin: 0px 5px 5px 5px; background: #ffffff; padding: 5px; border: 1px dashed; background-color: #ffffff; color: #333333; text-align:left;"><h4 style="width:50%; text-align:left; border-bottom: 1px dashed;">Queries</h4>'; foreach ($this->queries as $q) { if (isset($q['error'])) { $ret .= '<span style="color:#ff0000;">'.htmlentities($q['sql']).'<br /><b>Error number:</b> '.$q['errno'].'<br /><b>Error message:</b> '.$q['error'].'</span><br /><br />'; } else { $ret .= htmlentities($q['sql']).'<br /><br />'; } } $ret .= 'Total: <span style="color:#ff0000;">'.count($this->queries).'</span> queries</div>'; return $ret; } function dumpBlocks(){ $ret = '<div style="margin: 0px 5px 5px 5px; background: #ffffff; padding: 5px; border: 1px dashed; background-color: #ffffff; color: #333333; text-align:left;"><h4 style="width:50%; text-align:left; border-bottom: 1px dashed;">Blocks</h4>'; foreach ($this->blocks as $b) { if ($b['cached']) { $ret .= '<b>'.$b['name'].'</b> is using cache (regenerates every '.$b['cachetime'].' seconds)<br /><br />'; } else { $ret .= '<b>'.$b['name'].'</b> is created<br /><br />'; } } $ret .= 'Total: <span style="color:#ff0000;">'.count($this->blocks).'</span> blocks</div>'; return $ret; } function dumpTime($name = 'XOOPS'){ if (!isset($this->logstart[$name])) { return 0; } if (!isset($this->logend[$name])) { $stop_time = explode(' ', microtime()); } else { $stop_time = $this->logend[$name]; } /*echo '<pre>';echo var_dump($stop_time);echo '</pre>'; echo '<pre>';echo var_dump($this->logstart);echo '</pre>';*/ return ((float)$stop_time[1] + (float)$stop_time[0]) - ((float)$this->logstart[$name][1] + (float)$this->logstart[$name][0]); } function dumpAll(){ $ret = $this->dumpQueries(); $ret .= $this->dumpBlocks(); if (count($this->logstart) > 0) { $ret .= '<div style="margin: 0px 5px 5px 5px; background: #ffffff; padding: 5px; border: 1px dashed; background-color: #ffffff; color: #333333; text-align:left;"><h4 style="width:50%; text-align:left; border-bottom: 1px dashed;">Execution Time</h4>'; foreach ($this->logstart as $k => $v) { $ret .= '<b>'.$k.'</b> took <span style="color:#ff0000;">'.$this->dumpTime($k).'</span> seconds to load.<br /><br />'; } $ret .= '</div>'; } return $ret; } } ?> |