diff options
Diffstat (limited to 'useful')
-rwxr-xr-x | useful/ultrastrace.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/useful/ultrastrace.php b/useful/ultrastrace.php new file mode 100755 index 00000000..46df34a5 --- /dev/null +++ b/useful/ultrastrace.php @@ -0,0 +1,82 @@ +#!/usr/bin/env php +<?php + +if ($argc < 2) die("$argv[0] <tracefile>\n"); + +function parseTime($time) +{ + return $time['h'] * 3600 + $time['m'] * 60 + $time['s']; +} + +$failed = array(); +$found = array(); + +array_shift($argv); + +foreach ($argv as $fname) { + $fh = fopen($fname, 'r'); + if ($fh === false) die("File not found: $fname\n"); + echo "Reading $fname...\n"; + $lineNo = 0; + unset($lastLine); + + while (!feof($fh)) { + $lineNo++; + $line = fgets($fh); + // open("/lib/x86_64-linux-gnu/tls/x86_64/libkdeui.so.5", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) + if (preg_match('#^(?<h>\d+):(?<m>\d+):(?<s>\d+\.\d+)\s#', $line, $out) >= 1) { + $time = parseTime($out); + if (isset($lastLine)) { + if ($time < $lastTime) $lastTime -= 86400; + if ($lastTime + 2 < $time) { + echo "\n------------- Delay detected in $fname at line $lineNo:\n$lastLine$line"; + } + } + $lastLine = $line; + $lastTime = $time; + } + if (preg_match('#^(\d+:\d+:\d+\.\d+\s+)?open\("(?<lib>[^"]*[^"]*[^/])".*\)\s+=\s+(?<ret>\S+)(\s+(?<err>\S+)\s+|$)#', $line, $out) < 1) continue; + //echo "Match: {$out['lib']} -> {$out['ret']} ({$out['err']})\n"; + $file = basename($out['lib']); + $file = preg_replace('/\.so(\.\d+)*$/', '', $file); + if ($out['ret'] < 0) { + if (isset($found[$file])) { + $found[$file][] = ':-( ' . $out['lib'] . ' *** (' . (isset($out['err']) ? $out['err'] : 'Unknown Error') . ')'; + } else { + $failed[$file][] = ':-( ' . $out['lib'] . ' *** (' . (isset($out['err']) ? $out['err'] : 'Unknown Error') . ')'; + } + } else { + if (isset($failed[$file])) { + $found[$file] = $failed[$file]; + unset($failed[$file]); + } + $found[$file][] = ':-) ' . $out['lib']; + } + } + fclose($fh); +} + +echo "│\n│\n│\n│ ******* Found libraries *******************************************************\n"; +foreach ($found as $key => $val) { + echo "│\n├──┬ $key\n"; + $count = count($val); + $i = 1; + foreach ($val as $loc) { + if ($i == $count) echo "│ ╰── $loc\n"; + else echo "│ ├── $loc\n"; + ++$i; + } +} + +echo "│\n│\n│\n│ ******* Missing libraries *****************************************************\n"; +foreach ($failed as $key => $val) { + echo "│\n├──┬ $key\n"; + $count = count($val); + $i = 1; + foreach ($val as $loc) { + if ($i == $count) echo "│ ╰── $loc\n"; + else echo "│ ├── $loc\n"; + ++$i; + } +} + |