-
Notifications
You must be signed in to change notification settings - Fork 0
/
grinder.php
59 lines (50 loc) · 1.19 KB
/
grinder.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
<?php
// spell-check-ignore: cfl cfn ev fid su ve
$name = $argv[1];
$file = fopen($name, 'r');
if (!$file) {
echo "File {$name} not found.\n";
exit;
}
// filter out files:
// cat t3.prof | grep -v -E "^(fl|cfl|su|ve|cr|cm|pa|po|ev)" -m 80
// extract functions:
// cat t3.prof | grep -E "^(fn|cfn)=\([0-9]+\) "
// fl=({id}) {filename}
// fn=({id}) {class::function}
// cfl=({id}) {filename}
// cfn=({id}) {class::function}
// calls={count} {line}
// {line} {time} {memory}
/** @var array<int, string> $functions */
$functions = [];
$i = 0;
$function = '';
$calls = [];
/** @var string $line */
while ($line = fgets($file)) {
rd($line);
$i++;
if ($i < 8) {
// skip header
continue;
}
if ($line === "\n") {
// empty
continue;
} elseif ($line[1] === 'l') {
// fl=({id}) {filename}
continue;
} elseif ($line[1] === 'n') {
// fn=({id}) {class::function}
// {line} {time} {memory}
[$fid, $function] = explode(')', substr($line, 3));
if ($function !== '') {
$function = trim($function);
$functions[$fid] = $function;
}
}
if ($i > 50) {
break;
}
}