OLD | NEW |
1 import re | 1 import re |
2 | 2 |
| 3 |
3 # The following has largely been copied from bisect_perf_regression.py | 4 # The following has largely been copied from bisect_perf_regression.py |
4 # TODO(robertocn): Look into the possibility of getting structured data from | 5 # TODO(robertocn): Look into the possibility of getting structured data from |
5 # run_benchmark and similar scripts instead of this markup. | 6 # run_benchmark and similar scripts instead of this markup. |
6 def parse_metric(out, err, metric): # pragma: no cover | 7 def parse_metric(out, err, metric): # pragma: no cover |
7 """Tries to parse the output in RESULT line format or HISTOGRAM format. | 8 """Tries to parse the output in RESULT line format or HISTOGRAM format. |
8 | 9 |
9 Args: | 10 Args: |
10 metric: The metric as a list of [<trace>, <value>] string pairs. | 11 metric: The metric as a list of [<trace>, <value>] string pairs. |
11 out, err: stdout and stderr that may contain the output to be parsed | 12 out, err: stdout and stderr that may contain the output to be parsed |
12 | 13 |
13 Returns: | 14 Returns: |
14 A list of floating point numbers found. | 15 A list of floating point numbers found. |
15 """ | 16 """ |
16 text = (out or '') + (err or '') | 17 text = (out or '') + (err or '') |
17 result = _TryParseResultValuesFromOutput(metric, text) | 18 result = _parse_result_values_from_output(metric, text) |
18 if not result: | 19 if not result: |
19 result = _TryParseHistogramValuesFromOutput(metric, text) | 20 result = _parse_histogram_values_from_output(metric, text) |
20 return len(result), result | 21 return len(result), result |
21 | 22 |
22 def _TryParseResultValuesFromOutput(metric, text): # pragma: no cover | 23 |
| 24 def _parse_result_values_from_output(metric, text): # pragma: no cover |
23 """Attempts to parse a metric in the format RESULT <graph>: <trace>= ... | 25 """Attempts to parse a metric in the format RESULT <graph>: <trace>= ... |
24 | 26 |
25 Args: | 27 Args: |
26 metric: The metric as a list of [<trace>, <value>] string pairs. | 28 metric: The metric as a list of [<trace>, <value>] string pairs. |
27 text: The text to parse the metric values from. | 29 text: The text to parse the metric values from. |
28 | 30 |
29 Returns: | 31 Returns: |
30 A list of floating point numbers found. | 32 A list of floating point numbers found. |
31 """ | 33 """ |
32 if not text: | 34 if not text: |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 ['warm_times', 'page_load_time'], | 91 ['warm_times', 'page_load_time'], |
90 ] | 92 ] |
91 | 93 |
92 if metric in metrics_to_sum: | 94 if metric in metrics_to_sum: |
93 if values_list: | 95 if values_list: |
94 values_list = [reduce(lambda x, y: float(x) + float(y), values_list)] | 96 values_list = [reduce(lambda x, y: float(x) + float(y), values_list)] |
95 | 97 |
96 return values_list | 98 return values_list |
97 | 99 |
98 | 100 |
99 def _TryParseHistogramValuesFromOutput(metric, text): # pragma: no cover | 101 def _parse_histogram_values_from_output(metric, text): # pragma: no cover |
100 """Attempts to parse a metric in the format HISTOGRAM <graph: <trace>. | 102 """Attempts to parse a metric in the format HISTOGRAM <graph: <trace>. |
101 | 103 |
102 Args: | 104 Args: |
103 metric: The metric as a list of [<trace>, <value>] strings. | 105 metric: The metric as a list of [<trace>, <value>] strings. |
104 text: The text to parse the metric values from. | 106 text: The text to parse the metric values from. |
105 | 107 |
106 Returns: | 108 Returns: |
107 A list of floating point numbers found, [] if none were found. | 109 A list of floating point numbers found, [] if none were found. |
108 """ | 110 """ |
109 metric_formatted = 'HISTOGRAM %s: %s= ' % (metric[0], metric[1]) | 111 metric_formatted = 'HISTOGRAM %s: %s= ' % (metric[0], metric[1]) |
110 | 112 |
111 text_lines = text.split('\n') | 113 text_lines = text.split('\n') |
112 values_list = [] | 114 values_list = [] |
113 | 115 |
114 for current_line in text_lines: | 116 for current_line in text_lines: |
115 if metric_formatted in current_line: | 117 if metric_formatted in current_line: |
116 current_line = current_line[len(metric_formatted):] | 118 current_line = current_line[len(metric_formatted):] |
117 | 119 |
118 try: | 120 try: |
119 histogram_values = eval(current_line) | 121 histogram_values = eval(current_line) |
120 | 122 |
121 for b in histogram_values['buckets']: | 123 for b in histogram_values['buckets']: |
122 average_for_bucket = float(b['high'] + b['low']) * 0.5 | 124 average_for_bucket = float(b['high'] + b['low']) * 0.5 |
123 # Extends the list with N-elements with the average for that bucket. | 125 # Extends the list with N-elements with the average for that bucket. |
124 values_list.extend([average_for_bucket] * b['count']) | 126 values_list.extend([average_for_bucket] * b['count']) |
125 except Exception: | 127 except Exception: |
126 pass | 128 pass |
127 | 129 |
128 return values_list | 130 return values_list |
OLD | NEW |