Repository navigation
Expand file tree
/
Copy pathprofuzzbench_plot.py
More file actions
executable file
·110 lines (90 loc) · 3.8 KB
/
Copy pathprofuzzbench_plot.py
File metadata and controls
executable file
·110 lines (90 loc) · 3.8 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
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
#!/usr/bin/env python
import argparse
from pandas import read_csv
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot as plt
import pandas as pd
def main(csv_file, put, runs, cut_off, step, out_file):
#Read the results
df = read_csv(csv_file)
#Calculate the mean of code coverage
#Store in a list first for efficiency
mean_list = []
fuzzers = sorted(list(set(df['fuzzer'])))
for subject in [put]:
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)]
# if len(df1) == 0: continue
mean_list.append((subject, fuzzer, cov_type, 0, 0.0))
for time in range(1, cut_off + 1, step):
cov_total = 0
run_count = 0
for run in range(1, runs + 1, 1):
#get run-specific data frame
df2 = df1[df1['run'] == run]
#get the starting time for this run
start = df2.iloc[0, 0]
#get all rows given a cutoff time
df3 = df2[df2['time'] <= start + time*60]
#update total coverage and #runs
cov_total += df3.tail(1).iloc[0, 5]
run_count += 1
#add a new row
mean_list.append((subject, fuzzer, cov_type, time, cov_total / run_count))
#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, ax = plt.subplots()
fig.suptitle("Code coverage analysis for " + put)
fuzznames = []
for key, grp in mean_df.groupby(['fuzzer', 'cov_type']):
if key[0] not in fuzznames:
fuzznames.append(key[0])
if key[1] == 'b_abs':
ax.plot(grp['time'], grp['cov'])
ax.set_title('Edge coverage over time (#edges)')
ax.set_xlabel('Time (in min)')
ax.set_ylabel('#edges')
# if key[1] == 'b_per':
# ax.plot(grp['time'], grp['cov'])
# ax.set_title('Edge coverage over time (%)')
# ax.set_ylim([0,100])
# ax.set_xlabel('Time (in min)')
# ax.set_ylabel('Edge coverage (%)')
# if key[1] == 'l_abs':
# axes[0, 1].plot(grp['time'], grp['cov'])
# #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 key[1] == 'l_per':
# axes[1, 1].plot(grp['time'], grp['cov'])
# #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 (%)')
assert fuzznames == fuzzers
for i, ax in enumerate(fig.axes):
if '#' in ax.get_ylabel():
leg_loc = 'lower right'
else:
leg_loc = 'upper left'
ax.legend(fuzznames, loc=leg_loc)
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)