1
1
import matplotlib .pyplot as plt
2
- import numpy as np
3
- from math import ceil
4
2
import os
5
3
6
- from test import extract_last_decimal
7
-
8
- for d in os .listdir ():
9
- if d .startswith ('f' ):
10
- r = {}
11
-
12
- fw_size = np .array ([])
13
- patch_size = np .array ([])
14
- n_frag_patch = np .array ([])
15
- n_frag_fw = np .array ([])
16
- ovh_nbd = np .array ([])
17
- ovh_nbc = np .array ([])
18
- ovh_nba = np .array ([])
19
- ovh_tot = np .array ([])
20
- n_nba = np .array ([])
21
-
22
- if os .path .exists (d + '/testout' ):
23
- for report in os .listdir (d + '/testout' ):
24
- if report .startswith ('report' ):
25
- # extract version
26
- version = extract_last_decimal (report )
27
- # add to dictionary
28
- r [version ] = report
29
-
30
- # check if there are report in the folder
31
- if r :
32
- fw_versions = sorted (r .keys ())
33
- for v in fw_versions :
34
- with open (d + '/testout/' + r [v ], 'r' ) as f :
35
- f .readline ()
36
- fields = f .readline ().split (',' )
37
-
38
- fw_size = np .append (fw_size , int (fields [0 ]))
39
- patch_size = np .append (patch_size , int (fields [1 ]))
40
- n_frag_patch = np .append (n_frag_patch , ceil (int (fields [1 ])/ 112 ))
41
- n_frag_fw = np .append (n_frag_fw , ceil (int (fields [0 ])/ 112 ))
42
- n_nba = np .append (n_nba , int (fields [4 ]))
43
- ovh_nbd = np .append (ovh_nbd , float (fields [5 ]))
44
- ovh_nbc = np .append (ovh_nbc , float (fields [6 ]))
45
- ovh_nba = np .append (ovh_nba , float (fields [7 ]))
46
- ovh_tot = np .append (ovh_tot , float (fields [8 ]))
47
-
48
- # fig, axs = plt.subplots(2, 2, figsize=(15, 10))
49
- fig , axs = plt .subplots (2 , 2 )
50
- fig .suptitle (f'Statistics folder: { d } ' )
51
-
52
- axs [0 , 0 ].set_title ('Compression' )
53
- axs [0 , 0 ].plot (fw_versions , patch_size / fw_size * 100 )
54
- axs [0 , 0 ].set_xlabel ('FW version' )
55
- axs [0 , 0 ].set_ylabel ('Patch compression [%]' )
56
- axs [0 , 0 ].grid ()
57
-
58
- axs [0 , 1 ].set_title ('New Bytes' )
59
- axs [0 , 1 ].plot (fw_versions , np .ceil (n_nba / 1024 ))
60
- axs [0 , 1 ].set_xlabel ('FW version' )
61
- axs [0 , 1 ].set_ylabel ('kB' )
62
- axs [0 , 1 ].grid ()
63
-
64
- axs [1 , 0 ].set_title ('Overhead' )
65
- axs [1 , 0 ].plot (fw_versions , ovh_nbd , fw_versions , ovh_nbc , fw_versions , ovh_nba , fw_versions , ovh_tot )
66
- axs [1 , 0 ].set_xlabel ('FW version' )
67
- axs [1 , 0 ].set_ylabel ('Overhead respect new bytes [%]' )
68
- axs [1 , 0 ].legend (['nbd' , 'nbc' , 'nba' , 'total' ])
69
- axs [1 , 0 ].grid ()
70
-
71
- width = 0.3 # the width of the bars
72
- species = np .arange (len (fw_versions ))
73
-
74
- p1 = axs [1 , 1 ].bar (species - width / 2 , n_frag_fw , width , label = 'FW' )
75
- axs [1 , 1 ].bar_label (p1 , label_type = 'edge' )
76
- p2 = axs [1 , 1 ].bar (species + width / 2 , n_frag_patch , width , label = 'Patch' )
77
- axs [1 , 1 ].bar_label (p2 , label_type = 'edge' )
78
-
79
- axs [1 , 1 ].set_title ('Number of fragment comparison' )
80
- axs [1 , 1 ].set_xticks (species )
81
- axs [1 , 1 ].set_xticklabels (fw_versions )
82
- axs [1 , 1 ].legend ()
83
-
84
- plt .tight_layout ()
85
- plt .show ()
86
-
87
- exit ()
4
+ from test import extract_last_decimal , TESTOUT_FOLDER , TESTIN_FOLDER
5
+
6
+ # exit if TESTOUT_FOLDER does not exist
7
+ if not os .path .exists (TESTOUT_FOLDER ):
8
+ exit (0 )
9
+
10
+ # iterate over all directories in TESTOUT_FOLDER
11
+ for d in os .listdir (TESTOUT_FOLDER ):
12
+ # create patch dict with patch name and version
13
+ p = {}
14
+
15
+ for patch in os .listdir (f"{ TESTOUT_FOLDER } /{ d } " ):
16
+ # extract the version from the firmware name
17
+ version = extract_last_decimal (patch )
18
+ # add patch in dict
19
+ p [version ] = os .path .getsize (f"{ TESTOUT_FOLDER } /{ d } /{ patch } " ) / 1024
20
+
21
+ # create firmware dict with fw name and version
22
+ fw = {}
23
+
24
+ for f in os .listdir (f"{ TESTIN_FOLDER } /{ d } " ):
25
+ # extract the version from the firmware name
26
+ version = extract_last_decimal (f )
27
+ # add patch in dict
28
+ fw [version ] = os .path .getsize (f"{ TESTIN_FOLDER } /{ d } /{ f } " ) / 1024
29
+
30
+ # sort the patch and firmware dicts by version
31
+ versions = sorted (p .keys ())
32
+ p_sizes = [p [v ] for v in versions ]
33
+ f_sizes = [fw [v ] for v in versions ]
34
+
35
+ # plot the firmwares and patch sizes
36
+ plt .figure ()
37
+ plt .title (f"{ d } " )
38
+ plt .xlabel ('Firmware Version' )
39
+ plt .ylabel ('KBytes' )
40
+ plt .grid ()
41
+ plt .plot (versions , p_sizes , 'o-' , label = 'Patch Size' )
42
+ plt .plot (versions , f_sizes , 'o-' , label = 'Firmware Size' )
43
+ plt .legend ()
44
+ plt .show ()
0 commit comments