From 10f8ecb4d0e699bfbae3ffa0e4d55beac946d64e Mon Sep 17 00:00:00 2001 From: Tamer Tas Date: Wed, 17 Jul 2019 12:43:06 +0200 Subject: [PATCH] [browser-stories] expose raw results without statistical aggregation {json} command prints the results of benchmarks after aggregating it. This makes accessing raw data for analysis, a tedious process. This CL implements {raw-json} for accessing raw results. TBR=ulan@chromium.org No-Try: true Bug: v8:9448 Change-Id: I7c00fc0eca23b8bd5c967db903f71c5b46eddea3 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1706059 Reviewed-by: Tamer Tas Auto-Submit: Tamer Tas Commit-Queue: Tamer Tas Cr-Commit-Position: refs/heads/master@{#62761} --- tools/callstats.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tools/callstats.py b/tools/callstats.py index 70db89b5da..9f41a148b1 100755 --- a/tools/callstats.py +++ b/tools/callstats.py @@ -545,6 +545,41 @@ def create_total_page_stats(domains, args): # Add a new "Total" page containing the summed up metrics. domains['Total'] = total +# Generate Raw JSON file. + +def do_raw_json(args): + versions = {} + for path in args.logdirs: + if os.path.isdir(path): + for root, dirs, files in os.walk(path): + version = os.path.basename(root) + if version not in versions: versions[version] = {} + for filename in files: + if filename.endswith(".txt"): + m = re.match(r'^([^#]+)(#.*)?\.txt$', filename) + domain = m.group(1) + if domain not in versions[version]: versions[version][domain] = {} + read_stats(os.path.join(root, filename), + versions[version][domain], args) + + for version, domains in versions.items(): + if args.aggregate: + create_total_page_stats(domains, args) + for domain, entries in domains.items(): + raw_entries = [] + for name, value in entries.items(): + # We don't want the calculated sum in the JSON file. + if name == "Sum": continue + raw_entries.append({ + 'name': name, + 'duration': value['time_list'], + 'count': value['count_list'], + }) + + domains[domain] = raw_entries + + print(json.dumps(versions, separators=(',', ':'))) + # Generate JSON file. @@ -706,6 +741,20 @@ def main(): help="Create aggregated entries. Adds Group-* entries at the toplevel. " \ "Additionally creates a Total page with all entries.") + # Command: raw-json. + subparsers["raw-json"] = subparser_adder.add_parser( + "raw-json", help="Collect raw results from 'run' command into" \ + "a single json file.") + subparsers["raw-json"].set_defaults( + func=do_raw_json, error=subparsers["json"].error) + subparsers["raw-json"].add_argument( + "logdirs", type=str, metavar="", nargs="*", + help="specify directories with log files to parse") + subparsers["raw-json"].add_argument( + "--aggregate", dest="aggregate", action="store_true", default=False, + help="Create aggregated entries. Adds Group-* entries at the toplevel. " \ + "Additionally creates a Total page with all entries.") + # Command: help. subparsers["help"] = subparser_adder.add_parser( "help", help="help information")