servo/etc/ci/bencher.py
Samson faefed9869
Add linux-pref job (#33261)
Job will do some performance benchmarks (Dromeo, Speedometer) and mesure binary size and will report results to bencher.dev

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: DK Liao <dklassic@gmail.com>
2024-12-06 07:32:26 +00:00

58 lines
1.8 KiB
Python
Executable file

#!/usr/bin/env python3
# Copyright 2024 The Servo Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
import argparse
import json
import os
def size(args):
size = os.path.getsize(args.binary)
print(size)
with open(args.bmf_output, 'w', encoding='utf-8') as f:
json.dump({
'servo': {
'file-size': {
'value': float(size),
}
}
}, f, indent=4)
def merge(args):
output: dict[str, object] = dict()
for input_file in args.inputs:
with open(input_file, 'r', encoding='utf-8') as f:
data = json.load(f)
diff = set(data) & set(output)
if diff:
print("Duplicated keys:", diff)
output = data | output
with open(args.bmf_output, 'w', encoding='utf-8') as f:
json.dump(output, f, indent=4)
parser = argparse.ArgumentParser("Helper commands for bencher")
subparser = parser.add_subparsers()
size_parser = subparser.add_parser("filesize", help="Returns BMF for filesize")
size_parser.add_argument("binary", help="Servo binary file")
size_parser.add_argument("--bmf-output", help="BMF JSON output file", default=None)
size_parser.set_defaults(func=size)
merge_parser = subparser.add_parser("merge", help="Merges BMF JSONs")
merge_parser.add_argument("--bmf-output", help="BMF JSON output file")
merge_parser.add_argument("inputs", help="BMF JSON files to merge", nargs="+")
merge_parser.set_defaults(func=merge)
args = parser.parse_args()
args.func(args)