-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhprof_topfunctions.php
52 lines (40 loc) · 1.1 KB
/
xhprof_topfunctions.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
<?php
class TopFunctions extends SplHeap
{
private $compare_key;
public function __construct ($compare_key)
{
$this->compare_key = $compare_key;
}
protected function compare ($item1, $item2)
{
if ($item1[$this->compare_key] > $item2[$this->compare_key]) {
return 1;
}
if ($item1[$this->compare_key] == $item2[$this->compare_key]) {
return 0;
}
return -1;
}
}
$Top = new TopFunctions('wt');
$items = unserialize(file_get_contents('4cc98a9d64d8e.xhprof_foo'));
$aggregated = array();
foreach ($items as $key => $item)
{
$splitter = strpos($key, '==>');
$splitter = $splitter === false ? 0 : $splitter+3;
$realname = substr($key, $splitter);
if (!isset($aggregated[$realname])) {
$aggregated[$realname] = array('wt' => 0, 'ct' => 0);
}
$aggregated[$realname]['wt'] += $item['wt'];
$aggregated[$realname]['ct'] += $item['ct'];
}
foreach ($aggregated as $key => $item) {
$item['name'] = $key;
$Top->insert($item);
}
for ($i = 0; $i <= 10; $i++) {
var_dump($Top->extract());
}