forked from hgarrereyn/frameshift-eval
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.py
More file actions
76 lines (56 loc) · 1.97 KB
/
Copy pathreport.py
File metadata and controls
76 lines (56 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import argparse
import subprocess
from pathlib import Path
import yaml
import pandas as pd
from config import Config, Workdir
def make_report(workdir: Workdir):
print(f"Generating coverage report for {workdir.path}")
corpus = workdir.output() / 'queue'
covdir = workdir.coverage()
corpus_files = []
if corpus.exists():
corpus_files += list(corpus.iterdir())
else:
for subdir in workdir.output().iterdir():
subcorpus = subdir / 'queue'
if subcorpus.exists():
corpus_files += list(subcorpus.iterdir())
# Iterate over corpus in order of edit time
corpus_files = sorted(
[x for x in corpus_files if x.is_file() and not x.name.startswith('.')],
key=lambda x: x.stat().st_mtime
)
start_time = corpus_files[0].stat().st_mtime - 1
# Metrics
branch_cov = [0]
corpus_size = [0]
time = [0]
cov = set()
corp_size = 0
for file in corpus_files:
cov_file = covdir / f'{file.name}.cov'
if not cov_file.exists():
print('Warning: coverage file not found for', file)
continue
with open(cov_file) as f:
branches = set(f.read().strip().split('\n'))
cov |= branches
corp_size += 1
branch_cov.append(len(cov))
corpus_size.append(corp_size)
time.append(file.stat().st_mtime - start_time)
df = pd.DataFrame({
'time': time,
'branch_cov': branch_cov,
'corpus_size': corpus_size
})
df.to_csv(workdir.path / 'report.csv', index=False)
print('Total branches covered:', len(cov))
print('Total corpus size:', corp_size)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate coverage report for a workdir')
parser.add_argument('workdir', type=str, help='The workdir to use')
args = parser.parse_args()
workdir = Workdir(Path(args.workdir), ensure_exists=True)
make_report(workdir)