|
16 | 16 | statistical regression test across all the list-valued properties collected. |
17 | 17 | """ |
18 | 18 |
|
19 | | -import glob |
20 | 19 | import argparse |
| 20 | +import glob |
21 | 21 | import json |
22 | 22 | import os |
23 | 23 | import statistics |
|
32 | 32 | # pylint:disable=wrong-import-position |
33 | 33 | from framework.ab_test import binary_ab_test, check_regression |
34 | 34 | from framework.properties import global_props |
35 | | -from host_tools.metrics import ( |
36 | | - format_with_reduced_unit, |
37 | | - get_metrics_logger, |
38 | | -) |
| 35 | +from host_tools.metrics import get_metrics_logger |
| 36 | + |
| 37 | +UNIT_REDUCTIONS = { |
| 38 | + "Microseconds": "Milliseconds", |
| 39 | + "Milliseconds": "Seconds", |
| 40 | + "Bytes": "Kilobytes", |
| 41 | + "Kilobytes": "Megabytes", |
| 42 | + "Megabytes": "Gigabytes", |
| 43 | + "Gigabytes": "Terabytes", |
| 44 | + "Bits": "Kilobits", |
| 45 | + "Kilobits": "Megabits", |
| 46 | + "Megabits": "Gigabits", |
| 47 | + "Gigabits": "Terabit", |
| 48 | + "Bytes/Second": "Kilobytes/Second", |
| 49 | + "Kilobytes/Second": "Megabytes/Second", |
| 50 | + "Megabytes/Second": "Gigabytes/Second", |
| 51 | + "Gigabytes/Second": "Terabytes/Second", |
| 52 | + "Bits/Second": "Kilobits/Second", |
| 53 | + "Kilobits/Second": "Megabits/Second", |
| 54 | + "Megabits/Second": "Gigabits/Second", |
| 55 | + "Gigabits/Second": "Terabits/Second", |
| 56 | +} |
| 57 | +INV_UNIT_REDUCTIONS = {v: k for k, v in UNIT_REDUCTIONS.items()} |
| 58 | + |
| 59 | + |
| 60 | +UNIT_SHORTHANDS = { |
| 61 | + "Seconds": "s", |
| 62 | + "Microseconds": "μs", |
| 63 | + "Milliseconds": "ms", |
| 64 | + "Bytes": "B", |
| 65 | + "Kilobytes": "KB", |
| 66 | + "Megabytes": "MB", |
| 67 | + "Gigabytes": "GB", |
| 68 | + "Terabytes": "TB", |
| 69 | + "Bits": "Bit", |
| 70 | + "Kilobits": "KBit", |
| 71 | + "Megabits": "MBit", |
| 72 | + "Gigabits": "GBit", |
| 73 | + "Terabits": "TBit", |
| 74 | + "Percent": "%", |
| 75 | + "Count": "", |
| 76 | + "Bytes/Second": "B/s", |
| 77 | + "Kilobytes/Second": "KB/s", |
| 78 | + "Megabytes/Second": "MB/s", |
| 79 | + "Gigabytes/Second": "GB/s", |
| 80 | + "Terabytes/Second": "TB/s", |
| 81 | + "Bits/Second": "Bit/s", |
| 82 | + "Kilobits/Second": "KBit/s", |
| 83 | + "Megabits/Second": "MBit/s", |
| 84 | + "Gigabits/Second": "GBit/s", |
| 85 | + "Terabits/Second": "TBit/s", |
| 86 | + "Count/Second": "Hz", |
| 87 | + "None": "", |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | +def reduce_value(value, unit): |
| 92 | + """ |
| 93 | + Utility function for expressing a value in the largest possible unit in which it would still be >= 1 |
| 94 | +
|
| 95 | + For example, `reduce_value(1_000_000, Bytes)` would return (1, Megabytes) |
| 96 | + """ |
| 97 | + # Could do this recursively, but I am worried about infinite recursion |
| 98 | + # due to precision problems (e.g. infinite loop of dividing/multiplying by 1000, alternating |
| 99 | + # between values < 1 and >= 1000). |
| 100 | + while abs(value) < 1 and unit in INV_UNIT_REDUCTIONS: |
| 101 | + value *= 1000 |
| 102 | + unit = INV_UNIT_REDUCTIONS[unit] |
| 103 | + while abs(value) >= 1000 and unit in UNIT_REDUCTIONS: |
| 104 | + value /= 1000 |
| 105 | + unit = UNIT_REDUCTIONS[unit] |
| 106 | + |
| 107 | + return value, unit |
| 108 | + |
| 109 | + |
| 110 | +def format_with_reduced_unit(value, unit): |
| 111 | + """ |
| 112 | + Utility function for pretty printing a given value by choosing a unit as large as possible, |
| 113 | + and then outputting its shorthand. |
| 114 | +
|
| 115 | + For example, `format_with_reduced_unit(1_000_000, Bytes)` would return "1MB". |
| 116 | + """ |
| 117 | + reduced_value, reduced_unit = reduce_value(value, unit) |
| 118 | + formatted_unit = UNIT_SHORTHANDS.get(reduced_unit, reduced_unit) |
| 119 | + |
| 120 | + return f"{reduced_value:.2f}{formatted_unit}" |
| 121 | + |
39 | 122 |
|
40 | 123 | # Performance tests that are known to be unstable and exhibit variances of up to 60% of the mean |
41 | 124 | IGNORED = [ |
|
0 commit comments