diff --git a/doc/analyse-warnings.php b/doc/analyse-warnings.php new file mode 100755 index 0000000000..3325b29754 --- /dev/null +++ b/doc/analyse-warnings.php @@ -0,0 +1,77 @@ +#!/usr/bin/env php -qC +'.basename($_SERVER['PHP_SELF']).' must NOT be called as web-page --> exiting !!!'); +} +$warnings_by_file = []; + +// allow to pipe in tail of log and stop with Ctrl-C to show analysis +pcntl_signal(SIGINT, function() use ($warnings_by_file) +{ + echo "Caught SIGINT\n"; + analyse($warnings_by_file); +}); +pcntl_signal(SIGTERM, function() use ($warnings_by_file) +{ + echo "Caught SIGTERM\n"; + analyse($warnings_by_file); +}); + +if ($_SERVER['argc'] > 1) +{ + $files = $_SERVER['argv']; + array_shift($files); + $fp = popen('cat '.implode(' ', array_map('escapeshellarg', $files)), 'r'); +} +else +{ + $fp = STDIN; +} + +$n = 1; +while(($line = fgets($fp))) +{ + if (preg_match('#PHP (Warning|Deprecated|Fatal error): (.*) in (/[^ ]+\.php) on line (\d+)\r?\n?$#', $line, $matches)) + { + list(, $type, $warning, $file, $line) = $matches; + $warnings_by_file[$file][] = $line.': '.$type.' '.$warning; + } + error_log("\r$n: $line"); $n++; +} +error_log("Analysing ..."); +analyse($warnings_by_file); + +function analyse(array $warnings_by_file) +{ + uasort($warnings_by_file, $count_sort = static function ($a, $b) { + return count($b) <=> count($a); + }); + + foreach ($warnings_by_file as $file => $messages) + { + echo "\n$file: ".count($messages)."\n"; + + $warnings_by_line = []; + foreach ($messages as $line_msg) + { + list($line, $msg) = explode(':', $line_msg, 2); + $warnings_by_line[$line][] = $msg; + } + uasort($warnings_by_line, $count_sort); + + foreach ($warnings_by_line as $line => $warnings) + { + echo 'Line '.$line . ': '.count($warnings).' times: ' . implode(', ', array_unique($warnings)) . "\n"; + } + } +} \ No newline at end of file