Last active
February 10, 2020 20:09
-
-
Save nikic/1695353d0c0f1a9bba3e9be54671fed6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Extracting last timings as a convenience here, | |
// as we're usually interested in the last crate. | |
// We could also aggregate instead. | |
$metric = 'user_system'; | |
$timings1 = parse_llvm_timing(extract_last_pass_timings(file_get_contents($argv[1]))); | |
$timings2 = parse_llvm_timing(extract_last_pass_timings(file_get_contents($argv[2]))); | |
$timings1 = array_column($timings1, null, 'name'); | |
$timings2 = array_column($timings2, null, 'name'); | |
$passes = array_keys(array_merge($timings1, $timings2)); | |
$results = []; | |
foreach ($passes as $pass) { | |
$time1 = $timings1[$pass][$metric] ?? null; | |
$time2 = $timings2[$pass][$metric] ?? null; | |
$diff = $time2 - $time1; | |
$results[] = [ | |
'name' => $pass, | |
'old_time' => $time1, | |
'new_time' => $time2, | |
'diff' => $diff, | |
]; | |
} | |
uasort($results, function($a, $b) { | |
return abs($a['diff']) <=> abs($b['diff']); | |
}); | |
foreach ($results as $result) { | |
printf("%-60s %s %s %s\n", | |
$result['name'], | |
format_time($result['old_time']), | |
format_time($result['new_time']), | |
format_time($result['diff'])); | |
} | |
function format_time(?float $time): string { | |
if ($time === null) { | |
return ' ------'; | |
} else { | |
return sprintf('%6.3fs', $time); | |
} | |
} | |
function parse_llvm_timing(string $data): array { | |
$time = '\d+\.\d+'; | |
$perc = '\(\s*\d+\.\d+%\)'; | |
$regex = <<<REGEX | |
/^\s+(?<user>$time)\s+$perc | |
\s+(?<system>$time)\s+$perc | |
\s+(?<user_system>$time)\s+$perc | |
\s+(?<wall>$time)\s+$perc | |
\s+(?<name>.+)$/xm | |
REGEX; | |
if (!preg_match_all($regex, $data, $matches, PREG_SET_ORDER)) { | |
throw new Exception('Nothing matches?'); | |
} | |
$results = []; | |
foreach ($matches as $match) { | |
$results[] = [ | |
'name' => $match['name'], | |
'user' => (float) $match['user'], | |
'system' => (float) $match['system'], | |
'user_system' => (float) $match['user_system'], | |
'wall' => (float) $match['wall'], | |
]; | |
} | |
return $results; | |
} | |
function extract_last_pass_timings(string $data): string { | |
$separator = '... Pass execution timing report ...'; | |
$pos = strrpos($data, $separator); | |
return substr($data, $pos); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment