This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautotest.py
executable file
·1513 lines (1308 loc) · 45.7 KB
/
autotest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
# imports
from argparse import (ArgumentParser, ArgumentDefaultsHelpFormatter, Namespace,
FileType, ArgumentTypeError)
from argcomplete import autocomplete
from configparser import ConfigParser
from logging import (info, debug, error, warning,
DEBUG, INFO, WARN, ERROR)
from colorlog import ColoredFormatter, StreamHandler, getLogger
from sys import argv, stderr, modules
from time import sleep
from os import (access, R_OK, W_OK)
from os.path import isdir, isfile, join as path_join
import readline
from code import InteractiveConsole
# project imports
from server import Server, Host, Guest, LoadGen
from loadlatency import Machine, Interface, Reflector, LoadLatencyTestGenerator
# constants
THISMODULE: str = modules[__name__]
LOG_LEVELS: dict[int, int] = {
0: ERROR,
1: WARN,
2: INFO,
3: DEBUG,
}
# functions
def format_command(command: str) -> str:
"""
Format the given command.
This replaces linebreaks and trims lines.
Parameters
----------
command : str
The command to format.
Returns
-------
str
The formatted command.
See Also
--------
Example
-------
>>> cmd = '''
... echo "hello" &&
... echo "world";
... ls -lah
... '''
>>> format_command(cmd)
'echo "hello" && echo "world"; ls -lah'
"""
formatted = ''
for line in command.splitlines():
formatted += line.strip() + ' '
return formatted
def __do_nothing(variable: any) -> None:
"""
Do nothing with the given variable.
This is just to prevent linting errors for unused variables.
Parameters
----------
variable : any
The variable to do nothing with.
Returns
-------
"""
pass
def readable_dir(path: str) -> str:
"""
Check if the given path is a readable directory.
Parameters
----------
path : str
The path to check.
Returns
-------
str
The path if it is a readable directory.
"""
if not isdir(path):
raise ArgumentTypeError(f'{path} is not a directory.')
if not access(path, R_OK):
raise ArgumentTypeError(f'{path} is not readable.')
return path
def writable_dir(path: str) -> str:
"""
Check if the given path is a writable directory.
Parameters
----------
path : str
The path to check.
Returns
-------
str
The path if it is a writable directory.
"""
if not isdir(path):
raise ArgumentTypeError(f'{path} is not a directory.')
if not access(path, W_OK):
raise ArgumentTypeError(f'{path} is not writable.')
return path
def setup_parser() -> ArgumentParser:
"""
Setup the argument parser.
This function creates the argument parser and defines all the
arguments before returning it.
Parameters
----------
Returns
-------
ArgumentParser
The argument parser
See Also
--------
parse_args : Parse the command line arguments.
Examples
--------
>>> setup_parser()
ArgumentParser(...)
"""
# create the argument parser
parser = ArgumentParser(
description='''
This program automates performance testing of Qemu's virtio-net-pci
device for the vmuxIO project.''',
formatter_class=ArgumentDefaultsHelpFormatter,
)
# define all the arguments
parser.add_argument('-c',
'--config',
default='./autotest.cfg',
type=FileType('r'),
help='Configuration file path',
)
parser.add_argument('-v',
'--verbose',
dest='verbosity',
action='count',
default=0,
help='''Verbosity, can be given multiple times to set
the log level (0: error, 1: warn, 2: info, 3:
debug)''',
)
subparsers = parser.add_subparsers(help='commands', dest='command')
ping_parser = subparsers.add_parser(
'ping',
formatter_class=ArgumentDefaultsHelpFormatter,
help='''Ping all servers.'''
)
# TODO a status command would be cool. It should tell us, which nodes
# are running and how the device status is maybe
# TODO note this is just temporary, we will have more generic commands
# later
run_guest_parser = subparsers.add_parser(
'run-guest',
formatter_class=ArgumentDefaultsHelpFormatter,
help='Run the guest VM.'
)
run_guest_parser.add_argument('-i',
'--interface',
type=str,
choices=['brtap', 'macvtap'],
default='brtap',
help='Test network interface type.',
)
run_guest_parser.add_argument('-m',
'--machine',
type=str,
choices=['pc', 'microvm'],
default='pc',
help='Machine type of the guest',
)
run_guest_parser.add_argument('-D',
'--disk',
type=FileType('rw'),
help='Disk image path for the guest\'s ' +
'root partition.',
)
run_guest_parser.add_argument('-d',
'--debug',
action='store_true',
help='''Attach GDB to Qemu. The GDB server
will listen on port 1234.''',
)
run_guest_parser.add_argument('-I',
'--ioregionfd',
action='store_true',
help='''Use the IORegionFD enhanced
virtio-net-device for the test interface.'''
)
run_guest_parser.add_argument('-V', '--vhost',
action='store_true',
help='''Use the vhost-net backend for the
test interface.'''
)
run_guest_parser.add_argument('-r', '--rx-queue-size',
type=int,
default=256,
help='''The size of the receive queue for
the test interface.'''
)
run_guest_parser.add_argument('-t', '--tx-queue-size',
type=int,
default=256,
help='''The size of the transmit queue for
the test interface.'''
)
run_guest_parser.add_argument('-q',
'--qemu-path',
type=str,
default='/home/gierens/qemu-build',
help='QEMU build path',
)
kill_guest_parser = subparsers.add_parser(
'kill-guest',
formatter_class=ArgumentDefaultsHelpFormatter,
help='Kill the guest VM.'
)
setup_network_parser = subparsers.add_parser(
'setup-network',
formatter_class=ArgumentDefaultsHelpFormatter,
help='''Just setup the network
for the guest.'''
)
setup_network_parser.add_argument('-i',
'--interface',
type=str,
choices=['brtap', 'macvtap'],
default='brtap',
help='Test network interface type.',
)
teardown_network_parser = subparsers.add_parser(
'teardown-network',
formatter_class=ArgumentDefaultsHelpFormatter,
help='''Teardown the guest
network.'''
)
test_file_parser = subparsers.add_parser(
'test-load-lat-file',
formatter_class=ArgumentDefaultsHelpFormatter,
help='Run load latency tests defined in a test config file.'
)
test_file_parser.add_argument('-t',
'--testconfigs',
default=['./tests.cfg'],
nargs='+',
type=FileType('r'),
help='Test configuration file paths',
)
test_file_parser.add_argument('-d',
'--dry-run',
action='store_true',
default=False,
help='''Just generate tests, but do not
run them.''',
)
acc_file_parser = subparsers.add_parser(
'acc-load-lat-file',
formatter_class=ArgumentDefaultsHelpFormatter,
help='Force accumulation of all load latency tests defined in a ' +
'test config file.'
)
acc_file_parser.add_argument('-t',
'--testconfigs',
default=['./tests.cfg'],
nargs='+',
type=FileType('r'),
help='Test configuration file paths',
)
test_cli_parser = subparsers.add_parser(
'test-load-lat-cli',
formatter_class=ArgumentDefaultsHelpFormatter,
help='Run load latency tests defined in the command line.'
)
test_cli_parser.add_argument('-N',
'--name',
type=str,
default='l2-load-latency',
help='Test name.',
)
test_cli_parser.add_argument('-i',
'--interfaces',
nargs='+',
default=['pnic'],
help='Test network interface type. ' +
'Can be pnic, brtap or macvtap.',
)
test_cli_parser.add_argument('-o',
'--outdir',
type=writable_dir,
default='./outputs',
help='Test output directory.',
)
test_cli_parser.add_argument('-f',
'--reflector',
type=str,
choices=['xdp', 'moongen'],
default='xdp',
help='Test network interface type. ' +
'Can be pnic, brtap or macvtap.',
)
test_cli_parser.add_argument('-L',
'--loadprog',
type=FileType('r'),
default='./moonprogs/l2-load-latency.lua',
help='Load generator program.',
)
test_cli_parser.add_argument('-R',
'--reflprog',
type=FileType('r'),
default='./moonprogs/reflector.lua',
help='Reflector program.',
)
test_cli_parser.add_argument('-r',
'--rates',
nargs='+',
default=[10000],
help='List of throughput rates.',
)
test_cli_parser.add_argument('-T',
'--threads',
nargs='+',
default=[1],
help='List of number of threads.',
)
test_cli_parser.add_argument('-u',
'--runtime',
type=int,
default=60,
help='Test runtime.',
)
test_cli_parser.add_argument('-e',
'--reps',
type=int,
default=1,
help='Number of repetitions.',
)
test_cli_parser.add_argument('-a',
'--accumulate',
action='store_true',
default=False,
help='Accumulate the histograms of the ' +
'repetitions.',
)
test_cli_parser.add_argument('--yes-i-want-to-run-this',
action='store_true',
default=False,
help='''Confirm that you want to run this
deprecated code.''',
)
# TODO maybe we want to alter test parameters directly via the arguments
shell_parser = subparsers.add_parser(
'shell',
formatter_class=ArgumentDefaultsHelpFormatter,
help='''Enter a Python3 shell with access to the Server objects.
This is useful for development and debugging.'''
)
shell_parser.add_argument('-H',
'--exclude-host',
action='store_false',
default=True,
dest='host',
help='''Do not create the Host object.''',
)
shell_parser.add_argument('-G',
'--exclude-guest',
action='store_false',
default=True,
dest='guest',
help='''Do not create the Guest object.''',
)
shell_parser.add_argument('-L',
'--exclude-loadgen',
action='store_false',
default=True,
dest='loadgen',
help='''Do not create the LoadGen object.''',
)
# TODO command to upload moonprogs
shell_parser = subparsers.add_parser(
'upload-moonprogs',
formatter_class=ArgumentDefaultsHelpFormatter,
help='''Upload the MoonGen programs to the servers.'''
)
__do_nothing(ping_parser)
__do_nothing(kill_guest_parser)
__do_nothing(teardown_network_parser)
# return the parser
return parser
def parse_args(parser: ArgumentParser) -> Namespace:
"""
Parse the command line arguments.
This function takes the argument parser, parses the arguments, does the
auto-completion, and some further argument manipulations.
Parameters
----------
parser : ArgumentsParser
The argparse argument parser.
Returns
-------
Namespace
The argparse namespace containing the parsed arguments.
See Also
--------
setup_parser : Setup the argument parser.
Examples
--------
>>> parser_args(parser)
Namespace(...)
"""
autocomplete(parser)
args = parser.parse_args()
args.verbosity = min(args.verbosity, len(LOG_LEVELS)-1)
if not args.command:
parser.print_usage(stderr)
print(f'{argv[0]}: error: argument missing.', file=stderr)
exit(1)
if args.command == 'run-load-lat-cli':
for interface in args.interfaces:
if interface not in ['pnic', 'brtap', 'macvtap']:
parser.print_usage(stderr)
print(f'{argv[0]}: error: invalid interface type. ' +
'Must be one of: pnic, brtap, macvtap', file=stderr)
exit(1)
for rate in args.rates:
if rate < 1:
parser.print_usage(stderr)
print(f'{argv[0]}: error: invalid rate. Must be >= 1',
file=stderr)
exit(1)
for thread in args.threads:
if thread < 1:
parser.print_usage(stderr)
print(f'{argv[0]}: error: invalid thread. Must be >= 1',
file=stderr)
exit(1)
if args.runtime < 1:
parser.print_usage(stderr)
print(f'{argv[0]}: error: invalid runtime. Must be >= 1',
file=stderr)
exit(1)
if args.reps < 1:
parser.print_usage(stderr)
print(f'{argv[0]}: error: invalid number of repetitions. ' +
'Must be >= 1', file=stderr)
exit(1)
return args
def setup_and_parse_config(args: Namespace) -> ConfigParser:
"""
Setup and parse the config file.
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
Returns
-------
ConfigParser
The config parser.
See Also
--------
Example
-------
>>> setup_and_parse_config(args)
ConfigParser(...)
"""
conf = ConfigParser()
conf.read(args.config.name)
debug(f'configuration read from config file: {conf._sections}')
return conf
def setup_logging(args: Namespace) -> None:
"""
Setup the logging.
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
Returns
-------
See Also
--------
Example
-------
>>> setup_logging(args)
"""
logformat = '%(log_color)s%(asctime)s %(levelname)-8s %(message)s'
formatter = ColoredFormatter(
logformat,
datefmt=None,
reset=True,
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
},
secondary_log_colors={},
style='%'
)
handler = StreamHandler()
handler.setFormatter(formatter)
logger = getLogger()
logger.addHandler(handler)
logger.setLevel(LOG_LEVELS[args.verbosity])
def create_servers(conf: ConfigParser,
host: bool = True,
guest: bool = True,
loadgen: bool = True) -> dict[str, Server]:
"""
Create the servers.
Note that the insertion order of the servers is host, guest and finally
loadgen.
Parameters
----------
conf : ConfigParser
The config parser.
host : bool
Create the host server.
guest : bool
Create the guest server.
loadgen : bool
Create the loadgen server.
Returns
-------
Dict[Server]
A dictionary of servers.
See Also
--------
Example
-------
>>> create_servers(conf)
{'host': Host(...), ...}
"""
servers = {}
if host:
servers['host'] = Host(
conf['host']['fqdn'],
conf['host']['admin_bridge'],
conf['host']['admin_bridge_ip_net'],
conf['host']['admin_tap'],
conf['host']['test_iface'],
conf['host']['test_iface_addr'],
conf['host']['test_iface_mac'],
conf['host']['test_iface_driv'],
conf['host']['test_bridge'],
conf['host']['test_tap'],
conf['host']['test_macvtap'],
conf['host']['root_disk_file'],
conf['guest']['admin_iface_mac'],
conf['guest']['test_iface_mac'],
conf['host']['moongen_dir'],
conf['host']['moonprogs_dir'],
conf['host']['xdp_reflector_dir']
)
if guest:
servers['guest'] = Guest(
conf['guest']['fqdn'],
conf['guest']['test_iface'],
conf['guest']['test_iface_addr'],
conf['guest']['test_iface_mac'],
conf['guest']['test_iface_driv'],
conf['guest']['moongen_dir'],
conf['guest']['moonprogs_dir'],
conf['guest']['xdp_reflector_dir']
)
if loadgen:
servers['loadgen'] = LoadGen(
conf['loadgen']['fqdn'],
conf['loadgen']['test_iface'],
conf['loadgen']['test_iface_addr'],
conf['loadgen']['test_iface_mac'],
conf['loadgen']['test_iface_driv'],
conf['loadgen']['moongen_dir'],
conf['loadgen']['moonprogs_dir']
)
return servers
def ping(args: Namespace, conf: ConfigParser) -> None:
"""
Ping all servers.
This a command function and is therefore called by execute_command().
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
conf : ConfigParser
The config parser.
Returns
-------
See Also
--------
execute_command : Execute the command.
Example
-------
>>> ping(args, conf)
"""
name: str
server: Server
# TODO here type annotation could be difficult
for name, server in create_servers(conf).items():
print(f'{name}: ' +
f"{'reachable' if server.is_reachable() else 'unreachable'}")
def run_guest(args: Namespace, conf: ConfigParser) -> None:
"""
Run the guest VM.
This a command function and is therefore called by execute_command().
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
conf : ConfigParser
The config parser.
Returns
-------
See Also
--------
execute_command : Execute the command.
Example
-------
>>> run_guest(args, conf)
"""
host: Host = create_servers(conf, guest=False, loadgen=False)['host']
try:
host.setup_admin_tap()
if args.interface == 'brtap':
host.setup_test_br_tap()
else:
host.setup_test_macvtap()
disk = args.disk if args.disk else None
host.run_guest(args.interface, args.machine, disk, args.debug,
args.ioregionfd, args.qemu_path, args.vhost,
args.rx_queue_size, args.tx_queue_size)
except Exception:
host.kill_guest()
host.cleanup_network()
def kill_guest(args: Namespace, conf: ConfigParser) -> None:
"""
Kill the guest VM.
This a command function and is therefore called by execute_command().
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
conf : ConfigParser
The config parser.
Returns
-------
See Also
--------
execute_command : Execute the command.
Example
-------
>>> kill_guest(args, conf)
"""
host: Host = create_servers(conf, guest=False, loadgen=False)['host']
host.kill_guest()
host.cleanup_network()
def setup_network(args: Namespace, conf: ConfigParser) -> None:
"""
Just setup the network for the guest.
This a command function and is therefore called by execute_command().
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
conf : ConfigParser
The config parser.
Returns
-------
See Also
--------
execute_command : Execute the command.
Example
-------
>>> run_guest(args, conf)
"""
host: Host = create_servers(conf, guest=False, loadgen=False)['host']
try:
host.setup_admin_bridge()
host.setup_admin_tap()
if args.interface == 'brtap':
host.setup_test_br_tap()
else:
host.setup_test_macvtap()
except Exception:
error('Failed to setup network')
host.cleanup_network()
def teardown_network(args: Namespace, conf: ConfigParser) -> None:
"""
Just teardown the guest's network.
This a command function and is therefore called by execute_command().
Parameters
----------
args : Namespace
The argparse namespace containing the parsed arguments.
conf : ConfigParser
The config parser.
Returns
-------
See Also
--------
execute_command : Execute the command.
Example
-------
>>> kill_guest(args, conf)
"""
host: Host = create_servers(conf, guest=False, loadgen=False)['host']
host.cleanup_network()
def test_infix(interface: str, reflector: str, rate: int, nthreads: int,
rep: int) -> str:
"""
Create a test infix for the test.
Parameters
----------
interface : str
The interface name.
reflector : str
The reflector name.
rate : int
The rate in Mbit/s.
nthreads : int
The number of threads.
rep : int
The number of repetitions.
"""
return f'{interface}_{reflector}_r{rate}_t{nthreads}_{rep}'
def output_filepath(outdir: str, interface: str, reflector, rate: int,
nthreads: int, rep: int) -> str:
"""
Create the output filename.
Parameters
----------
outdir : str
The output directory.
interface : str
The interface name.
reflector : str
The reflector name.
rate : int
The rate in Mbit/s.
nthreads : int
The number of threads.
rep : int
The repetition number.
Returns
-------
str
The output filename.
"""
infix = test_infix(interface, reflector, rate, nthreads, rep)
filename = f'output_{infix}.log'
return path_join(outdir, filename)
def histogram_filepath(outdir: str, interface: str, reflector: str, rate: int,
nthreads: int, rep: int) -> str:
"""
Create the histogram filename.
Parameters
----------
outdir : str
The output directory.
interface : str
The interface name.
reflector : str
The reflector name.
rate : int
The rate in Mbit/s.
nthreads : int
The number of threads.
rep : int
The repetition number.
Returns
-------
str
The histogram filename.
"""
infix = test_infix(interface, reflector, rate, nthreads, rep)
filename = f'histogram_{infix}.csv'
return path_join(outdir, filename)
def test_done(outdir: str, interface: str, reflector: str, rate: int,
nthreads: int, rep: int) -> bool:
"""
Check if the test result is already available.
Parameters
----------
interface : str
The interface to use.
reflector : str
The reflector to use.
rate : int
The rate to use.
nthreads : int
The number of threads to use.
rep : int
The iteration of the test.
outdir : str
The output directory.
Returns
-------
bool
True if the test result is already available.
"""
output_file = output_filepath(outdir, interface, reflector, rate, nthreads,
rep)
histogram_file = histogram_filepath(outdir, interface, reflector, rate,
nthreads, rep)
return isfile(output_file) and isfile(histogram_file)
def accumulate_histograms(outdir: str, interface: str, reflector: str,
rate: int, nthreads: int, reps: int) -> None:
"""
Accumulate the histograms for all repetitions.
Parameters
----------
outdir : str
The output directory.
interface : str
The interface to use.
reflector : str
The reflector to use.
rate : int
The rate to use.
nthreads : int
The number of threads to use.
reps : int
The number of repetitions.
"""
info("Accumulating histograms.")
assert reps > 0, 'Reps must be greater than 0'
if reps == 1:
debug(f'Skipping accumulation: {interface} {reflector} {rate} ' +
f'{nthreads}, there is only one repetition')
return
acc_hist_filename = \
f'acc_histogram_{interface}_{reflector}_r{rate}_t{nthreads}.csv'
acc_hist_filepath = path_join(outdir, acc_hist_filename)
if isfile(acc_hist_filepath):
debug(f'Skipping accumulation: {interface} {reflector} {rate} ' +
f'{nthreads}, already done')
return
histogram = {}
for rep in range(reps):
assert test_done(outdir, interface, reflector, rate, nthreads, rep), \
'Test not done yet'
with open(histogram_filepath(outdir, interface, reflector, rate,
nthreads, rep)
) as f:
for line in f:
if line.startswith('#'):
continue
key, value = [int(n) for n in line.split(',')]
if key not in histogram:
histogram[key] = 0
histogram[key] += value
with open(acc_hist_filepath, 'w') as f:
for key, value in histogram.items():
f.write(f'{key},{value}\n')
def accumulate_all_histograms(
outdir: str,
reflector: str,
test_done: dict[str, dict[int, dict[int, bool]]]
) -> None:
"""
Accumulate the histograms for all repetitions.
Parameters
----------
outdir : str