Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change metrics names
  • Loading branch information
SBOne-Kenobi committed Nov 9, 2022
commit dfef0ea63860f1ff0a6613297309de5d74e3e619
43 changes: 42 additions & 1 deletion monitoring/prepare_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,47 @@
from utils import load


def remove_in_class(name: str) -> str:
in_class = "_in_class"
idx = name.find(in_class)
if idx == -1:
return name
return name[:idx] + name[idx:].removeprefix(in_class)


def update_from_counter_name(key_word: str, name: str, labels: dict) -> str:
if name == f"total_{key_word}":
labels["type"] = "total"
return key_word
if name.startswith(key_word):
labels["type"] = name.removeprefix(f"{key_word}_")
return key_word
return name


def update_from_coverage(name: str, labels: dict) -> str:
coverage_key = "bytecode_instruction_coverage"
idx = name.find(coverage_key)
if idx == -1:
return name
labels["type"] = name[:idx - 1]
source = name[idx:].removeprefix(f"{coverage_key}")
if len(source) > 0:
source = source.removeprefix("_by_")
if source == "classes":
labels["type"] = "averaged_by_classes"
else:
labels["source"] = source
return coverage_key


def build_metric_struct(name: str, value: any, labels: dict) -> dict:
name = remove_in_class(name)
name = update_from_counter_name("classes", name, labels)
name = update_from_counter_name("methods", name, labels)
name = update_from_coverage(name, labels)

name = f"utbot_{name}"
return {
"metric": name,
"labels": labels,
Expand All @@ -22,7 +62,7 @@ def build_metrics_from_data(data: dict, labels: dict) -> List[dict]:
}
metrics = data["metrics"]
for metric in metrics:
result.append(build_metric_struct(metric, metrics[metric], new_labels))
result.append(build_metric_struct(metric, metrics[metric], new_labels.copy()))
return result


Expand Down Expand Up @@ -86,6 +126,7 @@ def main():
stats = load(args.stats_file)
runner = stats["metadata"]["environment"]["host"]
metrics = build_metrics_from_targets(stats["targets"], runner)
metrics.sort(key=lambda x: x["metric"])
with open(args.output_file, "w") as f:
json.dump(metrics, f, indent=4)

Expand Down