profiler
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
class Profiler {
static protected $ticks = array();
static protected $file = false;
static private $buffer = 0;
public function instantiate() {
register_tick_function(array('Profiler', 'doSomethingWithTheTick'));
self::$buffer = microtime(true);
}
static public function doSomethingWithTheTick() {
$backtrace = debug_backtrace();
if(!self::$file) {
self::$file = $backtrace[0]['file'];
}
self::$ticks[$backtrace[0]['line']][] = microtime(true) - self::$buffer;
self::$buffer = microtime(true);
}
static public function getTicks() {
return self::$ticks;
}
static public function printReport($return = false) {
ksort(self::$ticks);
$lines = array();
$times = array();
$rounds = array();
$lines = array_keys(self::$ticks);
foreach(self::$ticks as $time) {
$times[] = round(array_sum($time) * 100, 5);
$rounds[] = count($time);
}
$ouput = "
<script type=\"text/javascript\">
var c = new Chart(document.getElementById('chart'));
c.setDefaultType(CHART_LINE);
c.setGridDensity(" . count($lines) . ", 15);
c.setHorizontalLabels([" . implode(', ', $lines) . "]);
c.setShowLegend(true);
c.add('Tijd', '#000000', [" . implode(', ', $times) . "]);
c.draw();
var d = new Chart(document.getElementById('chart2'));
d.setDefaultType(CHART_LINE);
d.setGridDensity(" . count($lines) . ", 15);
d.setHorizontalLabels([" . implode(', ', $lines) . "]);
d.setShowLegend(true);
d.add('Rondes', '#FF0000', [" . implode(', ', $rounds) . "]);
d.draw();
</script>";
if($return)
return $ouput;
else
echo $output;
}
}
?>
class Profiler {
static protected $ticks = array();
static protected $file = false;
static private $buffer = 0;
public function instantiate() {
register_tick_function(array('Profiler', 'doSomethingWithTheTick'));
self::$buffer = microtime(true);
}
static public function doSomethingWithTheTick() {
$backtrace = debug_backtrace();
if(!self::$file) {
self::$file = $backtrace[0]['file'];
}
self::$ticks[$backtrace[0]['line']][] = microtime(true) - self::$buffer;
self::$buffer = microtime(true);
}
static public function getTicks() {
return self::$ticks;
}
static public function printReport($return = false) {
ksort(self::$ticks);
$lines = array();
$times = array();
$rounds = array();
$lines = array_keys(self::$ticks);
foreach(self::$ticks as $time) {
$times[] = round(array_sum($time) * 100, 5);
$rounds[] = count($time);
}
$ouput = "
<script type=\"text/javascript\">
var c = new Chart(document.getElementById('chart'));
c.setDefaultType(CHART_LINE);
c.setGridDensity(" . count($lines) . ", 15);
c.setHorizontalLabels([" . implode(', ', $lines) . "]);
c.setShowLegend(true);
c.add('Tijd', '#000000', [" . implode(', ', $times) . "]);
c.draw();
var d = new Chart(document.getElementById('chart2'));
d.setDefaultType(CHART_LINE);
d.setGridDensity(" . count($lines) . ", 15);
d.setHorizontalLabels([" . implode(', ', $lines) . "]);
d.setShowLegend(true);
d.add('Rondes', '#FF0000', [" . implode(', ', $rounds) . "]);
d.draw();
</script>";
if($return)
return $ouput;
else
echo $output;
}
}
?>
Voorbeeldcode:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18