root/trunk/gregarius/cls/profiler.php

Revision 1746, 2.2 kB (checked in by cfriesen, 15 months ago)

put the version # in the profile output

  • Property svn:eolstyle set to native
Line 
1<?php
2
3###############################################################################
4# Gregarius - A PHP based RSS aggregator.
5# Copyright (C) 2003 - 2006 Marco Bonetti
6#
7###############################################################################
8# This program is free software and open source software; you can redistribute
9# it and/or modify it under the terms of the GNU General Public License as
10# published by the Free Software Foundation; either version 2 of the License,
11# or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful, but WITHOUT
14# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15# FITNESS FOR A PARTICULAR PURPOSE.      See the GNU General Public License for
16# more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  or visit
21# http://www.gnu.org/licenses/gpl.html
22#
23###############################################################################
24# E-mail:          mbonetti at gmail dot com
25# Web page:        http://gregarius.net/
26#
27###############################################################################
28
29
30class Profiler {
31
32    var $__init_timer = 0;
33    var $__prev_timer = 0;
34    var $__data = array();
35
36    function Profiler() {
37        $this -> __init_timer = $this->getmicrotime();
38        $this -> __prev_timer = $this -> __init_timer;
39        $this-> _pf('start ' . _VERSION_ . rss_svn_rev('.'));
40    }
41
42    function getmicrotime() {
43        list ($usec, $sec) = explode(" ", microtime());
44        return ((float) $usec + (float) $sec);
45    }
46
47    function _pf($comment) {
48        $current_timer = $this->getmicrotime();
49        $t = (1000 * ($current_timer - $this->__init_timer));
50        $d = (1000 * ($current_timer - $this->__prev_timer));
51        $this -> __prev_timer = $current_timer;
52       
53        $this->__data[] = array($t,$comment,$d);
54    }
55   
56    function render() {
57        $this-> _pf('end');
58        echo "\n\n<!--\n";
59        foreach ($this->__data as $e) {
60            list($t,$c,$d) = $e;
61            printf ("%03.2fms (+%03.2fms)\t%s\n",$t,$d,$c);
62        }
63        echo "\n-->\n\n";
64    }
65}
66?>
Note: See TracBrowser for help on using the browser.