-
Notifications
You must be signed in to change notification settings - Fork 40
/
detect_big_differences.php
85 lines (72 loc) · 2.26 KB
/
detect_big_differences.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Script to detect big changes between runs.
*
* More useful when running it through CLI as
* it can be easily used from CI servers to check
* the exit code.
*
* It takes timestamps (in miliseconds, like the runs files names) in ascending ordered,
* so the first one will be considered the before branch and the next one/s the after branches.
*
* Example:
* php detect_big_differences.php 1231231231231 1231231231232 1231231231233
*/
include(__DIR__ . '/webapp/inc.php');
include(__DIR__ . '/webapp/lib.php');
$normalize = false;
// Removing the script name.
array_shift($argv);
// Look for the --outliers flag in order to normalize.
foreach ($argv as $key => $arg) {
if ($arg == '--outliers' || substr($arg, 0, 9) == '--normali') {
$normalize = true;
unset($argv[$key]);
}
}
if (empty($argv)) {
echo 'Error: You need to specify the runs filenames without their .php sufix.' . PHP_EOL;
exit(1);
}
if (count($argv) == 1) {
echo 'Error: You should specify, at least, two runs to compare.' . PHP_EOL;
exit(1);
}
// The filename without .php.
$timestamps = $argv;
$report = new report();
if (!$report->parse_runs($timestamps, $normalize)) {
echo 'Error: The selected runs are not comparable.' . PHP_EOL;
foreach ($report->get_errors() as $var => $error) {
echo $var . ': ' . $error . PHP_EOL;
}
exit(1);
}
// Uses the thresholds specified in the .properties files.
if (!$report->calculate_big_differences()) {
echo 'Error: No way to get the default thresholds...' . PHP_EOL;
exit(1);
}
$branches = $report->get_big_differences();
// Report changes.
$exitcode = 0;
if ($branches) {
foreach ($branches as $branchnames => $changes) {
if (!empty($changes)) {
echo "$branchnames" . PHP_EOL;
}
foreach ($changes as $state => $data) {
foreach ($data as $var => $steps) {
foreach ($steps as $stepname => $info) {
$normalizestr = $normalize ? '(Normalized) ' : '';
echo $normalizestr;
echo "- $state: $var - $stepname -> $info" . PHP_EOL;
}
}
}
if (!empty($changes['increment'])) {
$exitcode = 1;
}
}
}
exit($exitcode);