Skip to content
Merged
Show file tree
Hide file tree
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
update monitoring scripts
  • Loading branch information
SBOne-Kenobi committed Nov 9, 2022
commit ca911d39870fc4ad7c6637849dd612e4d591c3ed
129 changes: 0 additions & 129 deletions monitoring/build_aggregated_data.py

This file was deleted.

138 changes: 132 additions & 6 deletions monitoring/insert_metadata.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import argparse
import json
import re
import subprocess
from collections import OrderedDict
from datetime import datetime
from os import environ
from os.path import exists
from platform import uname
from time import time
from typing import Optional
from typing import Optional, List

from monitoring_settings import JSON_VERSION
from utils import *


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


def build_target(target_name: str) -> dict:
return {
"target": target_name,
"summarised": [],
"by_class": OrderedDict()
}


def transform_metrics(metrics: dict) -> dict:
"""
Transform given metrics with calculation coverage
:param metrics: given metrics
:return: transformed metrics
"""
result = OrderedDict()

instr_count_prefix = "covered_bytecode_instructions"
total_instr_count_prefix = "total_bytecode_instructions"

coverage_prefix = "total_bytecode_instruction_coverage"

total_count = 0
for metric in metrics:
if metric.startswith(total_instr_count_prefix):
total_count = metrics[metric]
break

for metric in metrics:
if metric.startswith(total_instr_count_prefix):
continue
if metric.startswith(instr_count_prefix):
coverage = metrics[metric] / total_count if total_count > 0 else 0.0
result[coverage_prefix + metric.removeprefix(instr_count_prefix)] = coverage
else:
result[metric] = metrics[metric]

return result


def build_data(parameters: dict, metrics: dict) -> dict:
return {
"parameters": {
**parameters
},
"metrics": {
**transform_metrics(metrics)
}
}


def build_by_class(class_name: str) -> dict:
return {
"class_name": class_name,
"data": []
}


def update_from_class(by_class: dict, class_item: dict, parameters: dict):
"""
Update class object using given class_item
:param by_class: dictionary with classname keys
:param class_item: class metrics of current run
:param parameters: parameters of current run
"""
class_name = class_item["class_name"]
if class_name not in by_class:
by_class[class_name] = build_by_class(class_name)

metrics = class_item["metrics"]
by_class[class_name]["data"].append(
build_data(parameters, metrics)
)


def update_from_target(targets: dict, target_item: dict, parameters: dict):
"""
Update targets using given target_item
:param targets: dictionary with target keys
:param target_item: metrics of current run
:param parameters: parameters of current run
"""
target_name = target_item["target"]
if target_name not in targets:
targets[target_name] = build_target(target_name)

summarised_metrics = target_item["summarised_metrics"]
targets[target_name]["summarised"].append(
build_data(parameters, summarised_metrics)
)

for class_item in target_item["metrics_by_class"]:
update_from_class(targets[target_name]["by_class"], class_item, parameters)


def update_from_stats(targets: dict, stats: dict):
"""
Updates targets using given statistics
:param targets: dictionary with target keys
:param stats: target object
"""
parameters = stats["parameters"]
for target_item in stats["targets"]:
update_from_target(targets, target_item, parameters)


def postprocess_by_class(by_class: dict) -> List[dict]:
"""
Transform dictionary with classname keys into array with class objects
:param by_class: dictionary with classname keys
:return: array of class objects
"""
return list(by_class.values())


def postprocess_targets(targets: dict) -> List[dict]:
"""
Transform dictionary with target keys into array with target objects
:param targets: dictionary with target keys
:return: array of targets
"""
result = []
for target in targets.values():
target["by_class"] = postprocess_by_class(target["by_class"])
result.append(target)
return result


def build_targets(stats_array: List[dict]) -> List[dict]:
"""
Collect and group statistics by target
:param stats_array: list of dictionaries with parameters and metrics
:return: list of metrics and parameters grouped by target
"""
result = get_default_metrics_dict()
result = OrderedDict()
for stats in stats_array:
target = stats['parameters']['target']
del stats['parameters']['target']
update_target(result[target], stats)
update_from_stats(result, stats)

return postprocess_targets(result)

Expand Down
8 changes: 4 additions & 4 deletions monitoring/monitoring.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project=guava
classTimeoutMillis=20
runTries=1
runTimeoutMinutes=20
projects=guava
classTimeoutSeconds=20
runTimeoutMinutes=20
fuzzingRatios=0.0;0.1;1.0
7 changes: 1 addition & 6 deletions monitoring/monitoring_settings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
"""
Json format version.
"""
JSON_VERSION = 1

"""
Default version for projects without it.
"""
DEFAULT_PROJECT_VERSION = "0"
JSON_VERSION = 2
56 changes: 0 additions & 56 deletions monitoring/utils.py

This file was deleted.