Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/tools/parse_baselines/main.py
1956 views
1
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
"""Script used to calculate baselines from raw performance test output."""
4
5
import argparse
6
import os
7
import tempfile
8
import json
9
from typing import List
10
11
from providers.types import FileDataProvider
12
from providers.iperf3 import Iperf3DataParser
13
from providers.block import BlockDataParser
14
from providers.snapshot_restore import SnapshotRestoreDataParser
15
16
OUTPUT_FILENAMES = {
17
'vsock_throughput': 'test_vsock_throughput',
18
'network_tcp_throughput': 'test_network_tcp_throughput',
19
'block_performance': 'test_block_performance',
20
'snapshot_restore_performance': 'test_snap_restore_performance'
21
}
22
23
DATA_PARSERS = {
24
'vsock_throughput': Iperf3DataParser,
25
'network_tcp_throughput': Iperf3DataParser,
26
'block_performance': BlockDataParser,
27
'snapshot_restore_performance': SnapshotRestoreDataParser,
28
}
29
30
31
def get_data_files(args) -> List[str]:
32
"""Return a list of files that contain results for this test."""
33
assert os.path.isdir(args.data_folder)
34
35
file_list = []
36
37
# Get all files in the dir tree that have the right name.
38
for root, _, files in os.walk(args.data_folder):
39
for file in files:
40
if file == OUTPUT_FILENAMES[args.test]:
41
file_list.append(os.path.join(root, file))
42
43
# We need at least one file.
44
assert len(file_list) > 0
45
46
return file_list
47
48
49
def concatenate_data_files(data_files: List[str]):
50
"""Create temp file to hold all concatenated results for this test."""
51
outfile = tempfile.NamedTemporaryFile()
52
53
for filename in data_files:
54
with open(filename) as infile:
55
outfile.write(str.encode(infile.read()))
56
57
return outfile
58
59
60
def main():
61
"""Run the main logic."""
62
parser = argparse.ArgumentParser()
63
parser.add_argument("-d", "--data-folder",
64
help="Path to folder containing raw test data.",
65
action="store",
66
required=True)
67
parser.add_argument("-t", "--test",
68
help="Performance test for which baselines \
69
are calculated.",
70
action="store",
71
choices=['vsock_throughput',
72
'network_tcp_throughput',
73
'block_performance',
74
'snapshot_restore_performance'],
75
required=True)
76
args = parser.parse_args()
77
78
# Create the concatenated data file.
79
data_file = concatenate_data_files(get_data_files(args))
80
81
# Instantiate a file data provider.
82
data_provider = FileDataProvider(data_file.name)
83
84
# Instantiate the right data parser.
85
parser = DATA_PARSERS[args.test](data_provider)
86
87
# Finally, parse and print the baselines.
88
print(json.dumps(parser.parse(), indent=4))
89
90
91
if __name__ == "__main__":
92
main()
93
94