Skip to content

Commit 08a62a0

Browse files
committed
update monitoring scripts
1 parent 112659d commit 08a62a0

File tree

5 files changed

+137
-201
lines changed

5 files changed

+137
-201
lines changed

monitoring/build_aggregated_data.py

Lines changed: 0 additions & 129 deletions
This file was deleted.

monitoring/insert_metadata.py

Lines changed: 132 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import argparse
22
import json
3+
import re
34
import subprocess
5+
from collections import OrderedDict
46
from datetime import datetime
57
from os import environ
68
from os.path import exists
79
from platform import uname
810
from time import time
9-
from typing import Optional
11+
from typing import Optional, List
1012

1113
from monitoring_settings import JSON_VERSION
12-
from utils import *
1314

1415

1516
def load(json_file: str) -> Optional[any]:
@@ -91,17 +92,142 @@ def build_metadata(args: argparse.Namespace) -> dict:
9192
return metadata
9293

9394

95+
def build_target(target_name: str) -> dict:
96+
return {
97+
"target": target_name,
98+
"summarised": [],
99+
"by_class": OrderedDict()
100+
}
101+
102+
103+
def transform_metrics(metrics: dict) -> dict:
104+
"""
105+
Transform given metrics with calculation coverage
106+
:param metrics: given metrics
107+
:return: transformed metrics
108+
"""
109+
result = OrderedDict()
110+
111+
instr_count_prefix = "covered_bytecode_instructions"
112+
total_instr_count_prefix = "total_bytecode_instructions"
113+
114+
coverage_prefix = "total_bytecode_instruction_coverage"
115+
116+
total_count = 0
117+
for metric in metrics:
118+
if metric.startswith(total_instr_count_prefix):
119+
total_count = metrics[metric]
120+
break
121+
122+
for metric in metrics:
123+
if metric.startswith(total_instr_count_prefix):
124+
continue
125+
if metric.startswith(instr_count_prefix):
126+
coverage = metrics[metric] / total_count if total_count > 0 else 0.0
127+
result[coverage_prefix + metric.removeprefix(instr_count_prefix)] = coverage
128+
else:
129+
result[metric] = metrics[metric]
130+
131+
return result
132+
133+
134+
def build_data(parameters: dict, metrics: dict) -> dict:
135+
return {
136+
"parameters": {
137+
**parameters
138+
},
139+
"metrics": {
140+
**transform_metrics(metrics)
141+
}
142+
}
143+
144+
145+
def build_by_class(class_name: str) -> dict:
146+
return {
147+
"class_name": class_name,
148+
"data": []
149+
}
150+
151+
152+
def update_from_class(by_class: dict, class_item: dict, parameters: dict):
153+
"""
154+
Update class object using given class_item
155+
:param by_class: dictionary with classname keys
156+
:param class_item: class metrics of current run
157+
:param parameters: parameters of current run
158+
"""
159+
class_name = class_item["class_name"]
160+
if class_name not in by_class:
161+
by_class[class_name] = build_by_class(class_name)
162+
163+
metrics = class_item["metrics"]
164+
by_class[class_name]["data"].append(
165+
build_data(parameters, metrics)
166+
)
167+
168+
169+
def update_from_target(targets: dict, target_item: dict, parameters: dict):
170+
"""
171+
Update targets using given target_item
172+
:param targets: dictionary with target keys
173+
:param target_item: metrics of current run
174+
:param parameters: parameters of current run
175+
"""
176+
target_name = target_item["target"]
177+
if target_name not in targets:
178+
targets[target_name] = build_target(target_name)
179+
180+
summarised_metrics = target_item["summarised_metrics"]
181+
targets[target_name]["summarised"].append(
182+
build_data(parameters, summarised_metrics)
183+
)
184+
185+
for class_item in target_item["metrics_by_class"]:
186+
update_from_class(targets[target_name]["by_class"], class_item, parameters)
187+
188+
189+
def update_from_stats(targets: dict, stats: dict):
190+
"""
191+
Updates targets using given statistics
192+
:param targets: dictionary with target keys
193+
:param stats: target object
194+
"""
195+
parameters = stats["parameters"]
196+
for target_item in stats["targets"]:
197+
update_from_target(targets, target_item, parameters)
198+
199+
200+
def postprocess_by_class(by_class: dict) -> List[dict]:
201+
"""
202+
Transform dictionary with classname keys into array with class objects
203+
:param by_class: dictionary with classname keys
204+
:return: array of class objects
205+
"""
206+
return list(by_class.values())
207+
208+
209+
def postprocess_targets(targets: dict) -> List[dict]:
210+
"""
211+
Transform dictionary with target keys into array with target objects
212+
:param targets: dictionary with target keys
213+
:return: array of targets
214+
"""
215+
result = []
216+
for target in targets.values():
217+
target["by_class"] = postprocess_by_class(target["by_class"])
218+
result.append(target)
219+
return result
220+
221+
94222
def build_targets(stats_array: List[dict]) -> List[dict]:
95223
"""
96224
Collect and group statistics by target
97225
:param stats_array: list of dictionaries with parameters and metrics
98226
:return: list of metrics and parameters grouped by target
99227
"""
100-
result = get_default_metrics_dict()
228+
result = OrderedDict()
101229
for stats in stats_array:
102-
target = stats['parameters']['target']
103-
del stats['parameters']['target']
104-
update_target(result[target], stats)
230+
update_from_stats(result, stats)
105231

106232
return postprocess_targets(result)
107233

monitoring/monitoring.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project=guava
2-
classTimeoutMillis=20
3-
runTries=1
4-
runTimeoutMinutes=20
1+
projects=guava
2+
classTimeoutSeconds=20
3+
runTimeoutMinutes=20
4+
fuzzingRatios=0.0;0.1;1.0

monitoring/monitoring_settings.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
"""
22
Json format version.
33
"""
4-
JSON_VERSION = 1
5-
6-
"""
7-
Default version for projects without it.
8-
"""
9-
DEFAULT_PROJECT_VERSION = "0"
4+
JSON_VERSION = 2

monitoring/utils.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)