[Fix] Put the right line numbers into functions/methods
[hiphop-php.git] / bin / report_mutex.php
blobeba6cdb7a0e1e2851fe9dc67901cd733e885c49d
1 <?php
3 $server = $argv[1];
4 $top = $argv[2];
5 $translate = $argv[3];
6 if (!$top) $top = 20;
8 $ret = shell_exec("GET 'http://$server/stats.kvp?agg=*&keys=:mutex.*:'");
9 $stats = json_decode($ret);
10 if (!$stats) {
11 exit("No mutex profile data was found on server\n");
14 foreach ($stats as $name => $count) {
15 if (preg_match('/mutex.([0-9a-f:]+).(hit|time)/', $name, $m)) {
16 $stack = $m[1];
17 $type = $m[2];
19 if ($type == 'hit') {
20 $hits[$stack] = $count;
21 } else {
22 $times[$stack] = $count;
27 arsort($hits); $hits = array_slice($hits, 0, $top);
28 arsort($times); $times = array_slice($times, 0, $top);
30 $thits = array();
31 print str_repeat('=', 70)."\n";
32 foreach ($hits as $stack => $count) {
33 print $count ." x sampling hits:\n";
34 print $translate ? translate_stack($stack) : $stack."\n";
35 print str_repeat('-', 70)."\n";
37 $ttimes = array();
38 print str_repeat('=', 70)."\n";
39 foreach ($times as $stack => $count) {
40 print (int)($count/1000000) ." seconds:\n";
41 print $translate ? translate_stack($stack) : $stack."\n";
42 print str_repeat('-', 70)."\n";
45 function translate_stack($stack) {
46 global $server;
47 return shell_exec("GET http://$server/translate?stack=$stack");