summaryrefslogtreecommitdiffstats
path: root/useful
diff options
context:
space:
mode:
authorSimon Rettberg2013-04-05 15:51:53 +0200
committersr2013-04-12 19:11:41 +0200
commit9414f8d4bfb4a85e8be4d3c73bc2a625d0e90f47 (patch)
tree1716ab7dfb2e43b735fc1cf9f75d0c99c909a6b3 /useful
parentremotehost subfolder under 'server/boot/' (diff)
downloadtm-scripts-9414f8d4bfb4a85e8be4d3c73bc2a625d0e90f47.tar.gz
tm-scripts-9414f8d4bfb4a85e8be4d3c73bc2a625d0e90f47.tar.xz
tm-scripts-9414f8d4bfb4a85e8be4d3c73bc2a625d0e90f47.zip
Added small util to analyze strace logfiles for missing files/libs and delays
Diffstat (limited to 'useful')
-rwxr-xr-xuseful/ultrastrace.php82
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;
+ }
+}
+