Method for recording a benchmark directly. Args: name: The BenchmarkEntry name. iters: (optional) How many iterations were run cpu_time: (optional) Total cpu time in seconds wall_time: (optional) Total wall time in seconds throughput: (optional) Throughput (in MB/s) extras
(
name, iters=None, cpu_time=None, wall_time=None,
throughput=None, extras=None, metrics=None)
| 52 | |
| 53 | |
| 54 | def _global_report_benchmark( |
| 55 | name, iters=None, cpu_time=None, wall_time=None, |
| 56 | throughput=None, extras=None, metrics=None): |
| 57 | """Method for recording a benchmark directly. |
| 58 | |
| 59 | Args: |
| 60 | name: The BenchmarkEntry name. |
| 61 | iters: (optional) How many iterations were run |
| 62 | cpu_time: (optional) Total cpu time in seconds |
| 63 | wall_time: (optional) Total wall time in seconds |
| 64 | throughput: (optional) Throughput (in MB/s) |
| 65 | extras: (optional) Dict mapping string keys to additional benchmark info. |
| 66 | metrics: (optional) A list of dict representing metrics generated by the |
| 67 | benchmark. Each dict should contain keys 'name' and'value'. A dict |
| 68 | can optionally contain keys 'min_value' and 'max_value'. |
| 69 | |
| 70 | Raises: |
| 71 | TypeError: if extras is not a dict. |
| 72 | IOError: if the benchmark output file already exists. |
| 73 | """ |
| 74 | logging.info("Benchmark [%s] iters: %d, wall_time: %g, cpu_time: %g," |
| 75 | "throughput: %g, extras: %s, metrics: %s", name, |
| 76 | iters if iters is not None else -1, |
| 77 | wall_time if wall_time is not None else -1, |
| 78 | cpu_time if cpu_time is not None else -1, |
| 79 | throughput if throughput is not None else -1, |
| 80 | str(extras) if extras else "None", |
| 81 | str(metrics) if metrics else "None") |
| 82 | |
| 83 | entries = test_log_pb2.BenchmarkEntries() |
| 84 | entry = entries.entry.add() |
| 85 | entry.name = name |
| 86 | if iters is not None: |
| 87 | entry.iters = iters |
| 88 | if cpu_time is not None: |
| 89 | entry.cpu_time = cpu_time |
| 90 | if wall_time is not None: |
| 91 | entry.wall_time = wall_time |
| 92 | if throughput is not None: |
| 93 | entry.throughput = throughput |
| 94 | if extras is not None: |
| 95 | if not isinstance(extras, dict): |
| 96 | raise TypeError("extras must be a dict") |
| 97 | for (k, v) in extras.items(): |
| 98 | if isinstance(v, numbers.Number): |
| 99 | entry.extras[k].double_value = v |
| 100 | else: |
| 101 | entry.extras[k].string_value = str(v) |
| 102 | if metrics is not None: |
| 103 | if not isinstance(metrics, list): |
| 104 | raise TypeError("metrics must be a list") |
| 105 | for metric in metrics: |
| 106 | if "name" not in metric: |
| 107 | raise TypeError("metric must has a 'name' field") |
| 108 | if "value" not in metric: |
| 109 | raise TypeError("metric must has a 'value' field") |
| 110 | |
| 111 | metric_entry = entry.metrics.add() |
no test coverage detected