| 1 | #!/usr/bin/env pike |
|---|
| 2 | |
|---|
| 3 | string percent_change(int a, int b) |
|---|
| 4 | { |
|---|
| 5 | string s = ""; |
|---|
| 6 | float c = 100.0 * (b - a) / a; |
|---|
| 7 | if (b > a) |
|---|
| 8 | s += "+"; |
|---|
| 9 | s += sprintf("%.2g%%", c); |
|---|
| 10 | return s; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | string analyze_regression_results(string current, string regression, |
|---|
| 14 | string id) |
|---|
| 15 | { |
|---|
| 16 | mapping(string:string) current_results = ([]); |
|---|
| 17 | string name; |
|---|
| 18 | string result; |
|---|
| 19 | mapping(string:int) stats = (["PASS":0, |
|---|
| 20 | "FAIL":0, |
|---|
| 21 | "pass":0, |
|---|
| 22 | "fail":0]); |
|---|
| 23 | int current_reading_nodes; |
|---|
| 24 | int current_owl_nodes; |
|---|
| 25 | int current_connection_nodes; |
|---|
| 26 | int new_reading_nodes; |
|---|
| 27 | int new_owl_nodes; |
|---|
| 28 | int new_connection_nodes; |
|---|
| 29 | |
|---|
| 30 | foreach (current / "\n", string s) { |
|---|
| 31 | sscanf(s, "%s%*[ ]%s ", name, result); |
|---|
| 32 | if (has_value(({"PASS", "FAIL"}), result) |
|---|
| 33 | && has_value(name, ":")) |
|---|
| 34 | current_results[name] = result; |
|---|
| 35 | else |
|---|
| 36 | sscanf(s, "Total nodes: %d %d %d", current_reading_nodes, |
|---|
| 37 | current_owl_nodes, current_connection_nodes); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | array(string) delta = ({}); |
|---|
| 41 | foreach (regression / "\n", string s) { |
|---|
| 42 | sscanf(s, "%s%*[ ]%s ", name, result); |
|---|
| 43 | if (has_value(({"PASS", "FAIL"}), result) |
|---|
| 44 | && has_value(name, ":")) { |
|---|
| 45 | if (!current_results[name]) { |
|---|
| 46 | delta += ({s}); |
|---|
| 47 | stats[result]++; |
|---|
| 48 | } |
|---|
| 49 | else |
|---|
| 50 | m_delete(current_results, name); |
|---|
| 51 | } |
|---|
| 52 | sscanf(s, "Total nodes: %d %d %d", new_reading_nodes, |
|---|
| 53 | new_owl_nodes, new_connection_nodes); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | foreach (indices(current_results), string name) { |
|---|
| 57 | if (current_results[name] == "PASS") { |
|---|
| 58 | delta += ({sprintf("%-16s%s", name, "fail")}); |
|---|
| 59 | stats["fail"]++; |
|---|
| 60 | } |
|---|
| 61 | else { |
|---|
| 62 | delta += ({sprintf("%-16s%s", name, "pass")}); |
|---|
| 63 | stats["pass"]++; |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | string summary = ctime(time()) + id + ":\n" + delta * "\n" + "\n"; |
|---|
| 68 | if (stats["PASS"] + stats["pass"] > 0) { |
|---|
| 69 | summary += sprintf("%d PASS", stats["PASS"] + stats["pass"]); |
|---|
| 70 | if (stats["pass"] > 0) |
|---|
| 71 | summary += sprintf(" (%d PASS, %d pass)", |
|---|
| 72 | stats["PASS"], stats["pass"]); |
|---|
| 73 | summary += "\n"; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if (stats["FAIL"] + stats["fail"] > 0) { |
|---|
| 77 | summary += sprintf("%d FAIL", stats["FAIL"] + stats["fail"]); |
|---|
| 78 | if (stats["fail"] > 0) |
|---|
| 79 | summary += sprintf(" (%d FAIL, %d fail)", |
|---|
| 80 | stats["FAIL"], stats["fail"]); |
|---|
| 81 | summary += "\n"; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | summary += sprintf("Total nodes: %d %d %d (%s %s %s)\n", |
|---|
| 85 | new_reading_nodes, new_owl_nodes, new_connection_nodes, |
|---|
| 86 | percent_change(current_reading_nodes, |
|---|
| 87 | new_reading_nodes), |
|---|
| 88 | percent_change(current_owl_nodes, new_owl_nodes), |
|---|
| 89 | percent_change(current_connection_nodes, |
|---|
| 90 | new_connection_nodes)); |
|---|
| 91 | summary += "\n"; |
|---|
| 92 | |
|---|
| 93 | return summary; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | int main(int argc, array(string) argv) |
|---|
| 97 | { |
|---|
| 98 | if (argc < 2) { |
|---|
| 99 | werror("Too few arguments\n"); |
|---|
| 100 | return 1; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | string patched = argv[1]; |
|---|
| 104 | string reference; |
|---|
| 105 | if (argc > 2) |
|---|
| 106 | reference = argv[2]; |
|---|
| 107 | else |
|---|
| 108 | reference = (patched / "-")[0]; |
|---|
| 109 | |
|---|
| 110 | write(analyze_regression_results(Stdio.read_file(reference), |
|---|
| 111 | Stdio.read_file(patched), |
|---|
| 112 | patched)); |
|---|
| 113 | |
|---|
| 114 | return 0; |
|---|
| 115 | } |
|---|