-
Notifications
You must be signed in to change notification settings - Fork 3
/
profuzzbench_plot.py
executable file
·131 lines (113 loc) · 4.79 KB
/
profuzzbench_plot.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
import argparse
import matplotlib.pyplot as plt
import pandas as pd
import statistics
CUT = True
LOG = False
def main(csv_file, put, runs, cut_off, step, out_file):
#Read the results
df = pd.read_csv(csv_file)
#Calculate the mean of code coverage
#Store in a list first for efficiency
mean_list = []
fuzzers = df.fuzzer.unique()
for subject in [put]:
# for fuzzer in ['aflnet', 'aflnwe']:
for fuzzer in fuzzers:
for cov_type in ['b_abs', 'b_per', 'l_abs', 'l_per']:
#get subject & fuzzer & cov_type-specific dataframe
df1 = df[(df['subject'] == subject) & (df['fuzzer'] == fuzzer)
& (df['cov_type'] == cov_type)]
mean_list.append((subject, fuzzer, cov_type, 0, 0.0))
agg_f = statistics.median if '_abs' in cov_type else statistics.mean
for time in range(1, cut_off + 1, step):
cov = []
for run in range(1, runs + 1, 1):
#get run-specific data frame
df2 = df1[df1['run'] == run]
if CUT:
#get the starting time for this run
start = df2.iloc[0, 0]
#get all rows given a cutoff time
df2 = df2[df2['time'] <= start + time * 60]
#update total coverage and #runs
cov.append(df2.iloc[-1, 5])
#add a new row
mean_list.append(
(subject, fuzzer, cov_type, time, agg_f(cov)))
#Convert the list to a dataframe
mean_df = pd.DataFrame(
mean_list, columns=['subject', 'fuzzer', 'cov_type', 'time', 'cov'])
fig, axes = plt.subplots(2, 2, figsize=(20, 10))
fig.suptitle("Code coverage analysis")
for key, grp in mean_df.groupby(['fuzzer', 'cov_type']):
if key[1] == 'b_abs':
axes[0, 0].plot(grp['time'], grp['cov'], label=key[0])
#axes[0, 0].set_title('Edge coverage over time (#edges)')
axes[0, 0].set_xlabel('Time (in min)')
axes[0, 0].set_ylabel('#edges')
if LOG:
axes[0, 0].set_yscale('log')
if key[1] == 'b_per':
axes[1, 0].plot(grp['time'], grp['cov'], label=key[0])
#axes[1, 0].set_title('Edge coverage over time (%)')
axes[1, 0].set_ylim([0, 100])
axes[1, 0].set_xlabel('Time (in min)')
axes[1, 0].set_ylabel('Edge coverage (%)')
if key[1] == 'l_abs':
axes[0, 1].plot(grp['time'], grp['cov'], label=key[0])
#axes[0, 1].set_title('Line coverage over time (#lines)')
axes[0, 1].set_xlabel('Time (in min)')
axes[0, 1].set_ylabel('#lines')
if LOG:
axes[0, 1].set_yscale('log')
if key[1] == 'l_per':
axes[1, 1].plot(grp['time'], grp['cov'], label=key[0])
#axes[1, 1].set_title('Line coverage over time (%)')
axes[1, 1].set_ylim([0, 100])
axes[1, 1].set_xlabel('Time (in min)')
axes[1, 1].set_ylabel('Line coverage (%)')
for i, ax in enumerate(fig.axes):
# ax.legend(('AFLNet', 'AFLNwe'), loc='upper left')
# ax.legend(fuzzers, loc='upper left')
ax.legend(loc='upper left')
ax.grid()
#Save to file
plt.savefig(out_file)
# Parse the input arguments
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i',
'--csv_file',
type=str,
required=True,
help="Full path to results.csv")
parser.add_argument('-p',
'--put',
type=str,
required=True,
help="Name of the subject program")
parser.add_argument('-r',
'--runs',
type=int,
required=True,
help="Number of runs in the experiment")
parser.add_argument('-c',
'--cut_off',
type=int,
required=True,
help="Cut-off time in minutes")
parser.add_argument('-s',
'--step',
type=int,
required=True,
help="Time step in minutes")
parser.add_argument('-o',
'--out_file',
type=str,
required=True,
help="Output file")
args = parser.parse_args()
main(args.csv_file, args.put, args.runs, args.cut_off, args.step,
args.out_file)