5
5
from utils import load
6
6
7
7
8
+ def remove_in_class (name : str ) -> str :
9
+ in_class = "_in_class"
10
+ idx = name .find (in_class )
11
+ if idx == - 1 :
12
+ return name
13
+ return name [:idx ] + name [idx :].removeprefix (in_class )
14
+
15
+
16
+ def update_from_counter_name (key_word : str , name : str , labels : dict ) -> str :
17
+ if name == f"total_{ key_word } " :
18
+ labels ["type" ] = "total"
19
+ return key_word
20
+ if name .startswith (key_word ):
21
+ labels ["type" ] = name .removeprefix (f"{ key_word } _" )
22
+ return key_word
23
+ return name
24
+
25
+
26
+ def update_from_coverage (name : str , labels : dict ) -> str :
27
+ coverage_key = "bytecode_instruction_coverage"
28
+ idx = name .find (coverage_key )
29
+ if idx == - 1 :
30
+ return name
31
+ labels ["type" ] = name [:idx - 1 ]
32
+ source = name [idx :].removeprefix (f"{ coverage_key } " )
33
+ if len (source ) > 0 :
34
+ source = source .removeprefix ("_by_" )
35
+ if source == "classes" :
36
+ labels ["type" ] = "averaged_by_classes"
37
+ else :
38
+ labels ["source" ] = source
39
+ return coverage_key
40
+
41
+
8
42
def build_metric_struct (name : str , value : any , labels : dict ) -> dict :
43
+ name = remove_in_class (name )
44
+ name = update_from_counter_name ("classes" , name , labels )
45
+ name = update_from_counter_name ("methods" , name , labels )
46
+ name = update_from_coverage (name , labels )
47
+
48
+ name = f"utbot_{ name } "
9
49
return {
10
50
"metric" : name ,
11
51
"labels" : labels ,
@@ -22,7 +62,7 @@ def build_metrics_from_data(data: dict, labels: dict) -> List[dict]:
22
62
}
23
63
metrics = data ["metrics" ]
24
64
for metric in metrics :
25
- result .append (build_metric_struct (metric , metrics [metric ], new_labels ))
65
+ result .append (build_metric_struct (metric , metrics [metric ], new_labels . copy () ))
26
66
return result
27
67
28
68
@@ -86,6 +126,7 @@ def main():
86
126
stats = load (args .stats_file )
87
127
runner = stats ["metadata" ]["environment" ]["host" ]
88
128
metrics = build_metrics_from_targets (stats ["targets" ], runner )
129
+ metrics .sort (key = lambda x : x ["metric" ])
89
130
with open (args .output_file , "w" ) as f :
90
131
json .dump (metrics , f , indent = 4 )
91
132
0 commit comments