@@ -45,7 +45,7 @@ def prepare_microvm_for_test(microvm):
45
45
check_output ("echo 3 > /proc/sys/vm/drop_caches" )
46
46
47
47
48
- def run_fio (microvm , mode , block_size , fio_engine = "libaio" ):
48
+ def run_fio (microvm , mode , block_size , test_output_dir , fio_engine = "libaio" ):
49
49
"""Run a fio test in the specified mode with block size bs."""
50
50
cmd = (
51
51
CmdBuilder ("fio" )
@@ -71,16 +71,10 @@ def run_fio(microvm, mode, block_size, fio_engine="libaio"):
71
71
.with_arg (f"--write_bw_log={ mode } " )
72
72
.with_arg (f"--write_lat_log={ mode } " )
73
73
.with_arg ("--log_avg_msec=1000" )
74
+ .with_arg ("--output-format=json+" )
74
75
.build ()
75
76
)
76
77
77
- logs_path = Path (microvm .jailer .chroot_base_with_id ()) / "fio_output"
78
-
79
- if logs_path .is_dir ():
80
- shutil .rmtree (logs_path )
81
-
82
- logs_path .mkdir ()
83
-
84
78
prepare_microvm_for_test (microvm )
85
79
86
80
# Start the CPU load monitor.
@@ -93,21 +87,25 @@ def run_fio(microvm, mode, block_size, fio_engine="libaio"):
93
87
)
94
88
95
89
# Print the fio command in the log and run it
96
- rc , _ , stderr = microvm .ssh .run (f"cd /tmp; { cmd } " )
90
+ rc , stdout , stderr = microvm .ssh .run (f"cd /tmp; { cmd } " )
97
91
assert rc == 0 , stderr
98
92
assert stderr == ""
99
93
100
- microvm .ssh .scp_get ("/tmp/*.log" , logs_path )
94
+ fio_json_path = Path (test_output_dir / "fio.json" )
95
+ with open (fio_json_path , "w" ) as f :
96
+ f .write (stdout )
97
+
98
+ microvm .ssh .scp_get ("/tmp/*.log" , test_output_dir )
101
99
microvm .ssh .check_output ("rm /tmp/*.log" )
102
100
103
- return logs_path , cpu_load_future .result ()
101
+ return cpu_load_future .result ()
104
102
105
103
106
- def process_fio_log_files (logs_glob ):
104
+ def process_fio_log_files (root_dir , logs_glob ):
107
105
"""Parses all fio log files matching the given glob and yields tuples of same-timestamp read and write metrics"""
108
106
data = [
109
- Path (pathname ).read_text ("UTF-8" ).splitlines ()
110
- for pathname in glob .glob (logs_glob )
107
+ Path (root_dir / pathname ).read_text ("UTF-8" ).splitlines ()
108
+ for pathname in glob .glob (logs_glob , root_dir = root_dir )
111
109
]
112
110
113
111
assert data , "no log files found!"
@@ -134,13 +132,13 @@ def process_fio_log_files(logs_glob):
134
132
135
133
def emit_fio_metrics (logs_dir , metrics ):
136
134
"""Parses the fio logs in `{logs_dir}/*_[clat|bw].*.log and emits their contents as CloudWatch metrics"""
137
- for bw_read , bw_write in process_fio_log_files (f" { logs_dir } / *_bw.*.log" ):
135
+ for bw_read , bw_write in process_fio_log_files (logs_dir , " *_bw.*.log" ):
138
136
if bw_read :
139
137
metrics .put_metric ("bw_read" , sum (bw_read ), "Kilobytes/Second" )
140
138
if bw_write :
141
139
metrics .put_metric ("bw_write" , sum (bw_write ), "Kilobytes/Second" )
142
140
143
- for lat_read , lat_write in process_fio_log_files (f" { logs_dir } / *_clat.*.log" ):
141
+ for lat_read , lat_write in process_fio_log_files (logs_dir , " *_clat.*.log" ):
144
142
# latency values in fio logs are in nanoseconds, but cloudwatch only supports
145
143
# microseconds as the more granular unit, so need to divide by 1000.
146
144
for value in lat_read :
@@ -164,6 +162,7 @@ def test_block_performance(
164
162
fio_engine ,
165
163
io_engine ,
166
164
metrics ,
165
+ test_output_dir ,
167
166
):
168
167
"""
169
168
Execute block device emulation benchmarking scenarios.
@@ -192,9 +191,9 @@ def test_block_performance(
192
191
193
192
vm .pin_threads (0 )
194
193
195
- logs_dir , cpu_util = run_fio (vm , fio_mode , fio_block_size , fio_engine )
194
+ cpu_util = run_fio (vm , fio_mode , fio_block_size , test_output_dir , fio_engine )
196
195
197
- emit_fio_metrics (logs_dir , metrics )
196
+ emit_fio_metrics (test_output_dir , metrics )
198
197
199
198
for thread_name , values in cpu_util .items ():
200
199
for value in values :
@@ -213,6 +212,7 @@ def test_block_vhost_user_performance(
213
212
fio_mode ,
214
213
fio_block_size ,
215
214
metrics ,
215
+ test_output_dir ,
216
216
):
217
217
"""
218
218
Execute block device emulation benchmarking scenarios.
@@ -242,9 +242,9 @@ def test_block_vhost_user_performance(
242
242
next_cpu = vm .pin_threads (0 )
243
243
vm .disks_vhost_user ["scratch" ].pin (next_cpu )
244
244
245
- logs_dir , cpu_util = run_fio (vm , fio_mode , fio_block_size )
245
+ cpu_util = run_fio (vm , fio_mode , fio_block_size , test_output_dir )
246
246
247
- emit_fio_metrics (logs_dir , metrics )
247
+ emit_fio_metrics (test_output_dir , metrics )
248
248
249
249
for thread_name , values in cpu_util .items ():
250
250
for value in values :
0 commit comments