/adei/ui

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/ui

« back to all changes in this revision

Viewing changes to classes/profiler.php

  • Committer: Suren A. Chilingaryan
  • Date: 2008-04-02 10:23:22 UTC
  • Revision ID: csa@dside.dyndns.org-20080402102322-okib92sicg2dx3o3
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/*
 
4
require_once("Benchmark/Profiler.php");
 
5
 
 
6
 
 
7
function __profile__($cmd) {
 
8
        static $log, $last_time, $total;
 
9
        
 
10
        list($usec, $sec) = explode(" ", microtime());
 
11
        $now = (float) $usec + (float) $sec;
 
12
        
 
13
        if($cmd) {
 
14
                if($cmd == 'get') {
 
15
                        unregister_tick_function('__profile__');
 
16
                        foreach($log as $function => $time) {
 
17
                                if($function != '__profile__') {
 
18
                                        $by_function[$function] = round($time / $total * 100, 2);
 
19
                                }
 
20
                        }
 
21
                        arsort($by_function);
 
22
                        return $by_function;
 
23
                }
 
24
                else if($cmd == 'init') {
 
25
                        $last_time = $now;
 
26
                        return;
 
27
                }
 
28
                else if($cmd == 'restart') {
 
29
                        register_tick_function('__profile__', $this);
 
30
                        return;
 
31
                }
 
32
        }
 
33
        $delta = $now - $last_time;
 
34
        $last_time = $now;
 
35
        $trace = debug_backtrace();
 
36
        $caller = $trace[1]['function'];
 
37
        @$log[$caller] += $delta;
 
38
        $total += $delta;
 
39
}
 
40
 
 
41
class PROFILER {
 
42
 var $profiler;
 
43
 
 
44
 function __construct() {
 
45
    $this->Start();
 
46
 }
 
47
 
 
48
 function __destruct() {
 
49
    $this->Display(false);
 
50
 }
 
51
 
 
52
 function Start() {
 
53
    global $profiler;
 
54
    
 
55
    __profile__('init');
 
56
    register_tick_function('__profile__', $this);
 
57
    declare(ticks=1); 
 
58
 
 
59
 
 
60
    $this->profiler = new Benchmark_Profiler(true);
 
61
    $this->profiler->start();
 
62
 }
 
63
 
 
64
 
 
65
 function Display($prof = true) {
 
66
    if ($prof) {
 
67
        $this->profiler->stop();
 
68
        $this->profiler->display();
 
69
    }
 
70
 
 
71
    print_r(__profile__('get'));
 
72
    echo("\n");
 
73
 }
 
74
 
 
75
 function Restart() {
 
76
    $this->profiler->start();
 
77
    __profile__('restart');
 
78
 }
 
79
 
 
80
 
 
81
 function EnterSection($name) {
 
82
    $this->profiler->enterSection($name);
 
83
 }
 
84
 
 
85
 function LeaveSection($name) {
 
86
    $this->profiler->leaveSection($name);
 
87
 }
 
88
}
 
89
 
 
90
//$adei_profiler = new PROFILER();
 
91
*/
 
92
 
 
93
?>
 
 
b'\\ No newline at end of file'