forked from moodlehq/moodle-performance-comparison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_big_differences.php
69 lines (58 loc) · 1.79 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
<?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');
// Removing the script name.
array_shift($argv);
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)) {
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) {
foreach ($changes as $state => $data) {
foreach ($data as $var => $steps) {
foreach ($steps as $stepname => $info) {
echo "$branchnames - $state: $var - $stepname -> $info" . PHP_EOL;
}
}
}
if (!empty($changes['increment'])) {
$exitcode = 1;
}
}
}
exit($exitcode);