-
Notifications
You must be signed in to change notification settings - Fork 6
/
update_bench_incremental.rb
executable file
·327 lines (306 loc) · 11.2 KB
/
update_bench_incremental.rb
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/usr/bin/ruby
require 'fileutils'
require 'yaml'
Dir.chdir(File.dirname(__FILE__))
$goblint = File.expand_path('../analyzer/goblint')
$messagesCompare = File.expand_path('../analyzer/_build/default/src/messagesCompare.exe')
fail 'Please run script from goblint dir!' unless File.exist?($goblint)
$goblint_version = `#{$goblint} --version`
$bench_version = `git describe --all --long --dirty 2> /dev/null`
results = 'bench_result'
Dir.mkdir(results) unless Dir.exist?(results)
$testresults = File.expand_path('bench_result') + '/'
$bench_path = File.expand_path('.') + '/'
$repo_url = 'https://github.com/goblint/bench/blob/master/'
class Project
attr_reader :id, :name, :group, :path, :patches, :size
attr_accessor :info, :params, :url
def initialize(id, name, size, info, group, path, params, patches)
@id = id
@name = name
@size = size
@info = info
@group = group
@path = path
@params = params
@patches = patches
end
def url
$repo_url + @path
end
def to_html
name = "<div title=\"#{@info}\"><a href=\"#{url}\">#{@name}</a></div>"
"<td>#{@id}</td><td>#{name}</td>\n" + "<td>#{@size}</td>\n"
end
def to_s
@name.to_s
end
end
$projects = []
$header = <<END
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Benchmarks on #{`uname -n`.chomp}</title>
<style>
A:link {text-decoration: none}
A:visited {text-decoration: none}
A:active {text-decoration: none}
A:hover {text-decoration: underline}
</style>
</head>
END
$theresultfile = File.join($testresults, 'index.html')
def print_file_res (f, path)
first = true
$analyses.each do |a|
aname = a[0]
outfile = File.basename(path,'.c') + ".#{aname}.txt"
if File.exists?($testresults + outfile)
File.open($testresults + outfile, 'r') do |g|
lines = g.readlines
vars, evals = lines.grep(/vars = (\d*).*evals = (\d+)/) { |x| [$1.to_i, $2.to_i] } .first
res = lines.grep(/^TIMEOUT\s*(.*) s.*$/) { |x| $1 }
if res == []
dur = lines.grep(/^Duration: (.*) s/) { |x| $1 }
cod = lines.grep(/^EXITCODE\s*(.*)$/) { |x| $1 }
if cod == [] and not dur == []
if $compare
unless first
compfile = "#{outfile}.compare.txt"
complines = File.readlines($testresults + compfile)
verdict = complines.grep(/comparison summary: original (.*) increment/) { |x| $1 }.first
msg = case verdict
when 'equal to' then '='
when 'more precise than' then '⊑'
when 'incomparable to' then '≸'
when 'less precise than' then '⊒'
end
thenumbers = "<a href=\"#{compfile}\">#{msg} </a>"
thenumbers << " <a href=\"#{outfile}.compare.messages.txt\">M</a>"
end
else
safely = lines.grep(/[^n]safe:[ ]*([0-9]*)/) { |x| $1.to_i } .first
vulner = lines.grep(/vulnerable:[ ]*([0-9]*)/) { |x| $1.to_i } .first
unsafe = lines.grep(/unsafe:[ ]*([0-9]*)/) { |x| $1.to_i } .first
total = lines.grep(/total:[ ]*([0-9]*)/) { |x| $1.to_i } .first
uncalled = lines.grep(/will never be called/).reject {|x| x =~ /__check/}.size
deadlock = lines.grep(/\[Deadlock\]/).size
thenumbers = "<font color=\"green\">#{safely}</font>+"
thenumbers << "<font color=\"orange\">#{vulner}</font>+"
thenumbers << "<font color=\"red\">#{unsafe}</font>="
thenumbers << "#{total}"
thenumbers << "; <font color=\"blue\">#{deadlock}</font>"
thenumbers << "; <font color=\"magenta\">#{uncalled}</font>" if uncalled > 0
end
thenumbers = " (#{thenumbers})" unless thenumbers.nil?
f.puts "<td><a href=\"#{outfile}.html\">#{"%.2f" % dur} s / #{vars} vars / #{evals} evals</a>#{thenumbers}</td>"
else
f.puts "<td><a href=\"#{outfile}.html\">failed (code: #{cod.first.to_s})</a></td>"
end
else
f.puts "<td><a href=\"#{outfile}.html\">#{res.first.to_s} s</a> (limit)</td>"
end
end
else
f.puts '<td>N/A</a></td>'
end
first = false
end
end
def print_res (i)
File.open($theresultfile, 'w') do |f|
f.puts $header
f.puts '<body>'
f.puts "<p>Benchmarking in progress: #{i}/#{$projects.length} <progress value=\"#{i}\" max=\"#{$projects.length}\" /></p>" unless i.nil?
f.puts '<table border=2 cellpadding=4 style="font-size: 90%">'
gname = ''
$projects.each do |p|
if p.group != gname
gname = p.group
f.puts "<tr><th colspan=#{3+$analyses.size}>#{gname}</th></tr>"
f.puts '<tr><th>#</th><th>Name</th><th>Size</th>'
$analyses.each do |a|
aname = a[0]
f.puts "<th>#{aname}</th>"
end
end
f.puts '<tr>'
f.puts p.to_html
print_file_res(f, p.path)
f.puts '</tr>'
p.patches.each do |pfile|
f.puts '<tr>'
pname = File.basename(pfile)
`cp #{pfile} #{$testresults + pname}`
f.puts "<td>-</td><td><a href=\"#{pname}\">#{pname}</a></td>\n" + "<td><a href=\"#{pname}.html\">patched</a></td>\n"
print_file_res(f, pfile)
f.puts '</tr>'
end
end
f.puts '</table>'
f.print '<p style="font-size: 80%; white-space: pre-line">'
f.puts "Last updated: #{Time.now.strftime("%Y-%m-%d %H:%M:%S %z")}"
f.puts "Bench version: #{$bench_version}"
f.puts "#{$goblint_version}"
f.puts "Goblint base configuration: <a href=\"#{$goblint_conf_name}\">#{$goblint_conf_name}</a>."
f.puts "Analysis definitions: <a href=\"#{$conf_name}\">#{$conf_name}</a>."
f.puts '</p>'
f.puts '</body>'
f.puts '</html>'
end
end
#Command line parameters
if ARGV[2].nil?
puts 'You must run command with timout, conf, and at least one benchmark set, e.g.:'
puts './update_bench_incremental.rb 60 index/defs/incremental.yaml index/sets/posix.yaml'
exit 1
end
$timeout = ARGV[0].to_i
conf_file = ARGV[1]
groups = ARGV[2..-1]
#processing the input file
$analyses = []
conf = YAML.load_file(conf_file)
$conf_name = File.basename(conf_file)
$goblint_conf = File.expand_path(conf['baseconf'])
$goblint_conf_name = File.basename($goblint_conf)
abort("Configuration lacks base conf: #{$goblint_conf}") unless File.exist?($goblint_conf)
$compare = conf['compare']
$incremental = conf['incremental']
conf.delete('compare')
conf.delete('baseconf')
conf.delete('incremental')
conf.each { |(key, value)| $analyses << [key, value.nil? ? '' : value] }
id = 0
groups.each do |group|
benchmarks = YAML.load_file(group)
gname = File.basename(group, '.yaml').upcase
#TODO: name is ignored because it breaks patch hacks.
benchmarks.each do |name, spec|
info = spec['info']
path = spec['path']
params = spec['param']
params = '' if params.nil?
fullpath = File.expand_path(path, $bench_path)
size = "#{`wc -l #{path}`.split[0]} lines"
patches = $incremental ? Dir["#{fullpath.chomp('.c')}*.patch"] : []
name = File.basename(path, '.c')
id += 1
$projects << Project.new(id,name,size,info,gname,path,params,patches.sort)
end
end
#Process linux results!
$fileheader = <<END
<html>
<head>
<title>Benchmarks on #{`uname -n`.chomp}</title>
<style type="text/css">
body { white-space: pre; font-family: monospace }
a { color: inherit }
</style>
</head>
<body>
END
def proc_res(resultfile, url, filename)
File.open(resultfile, 'r') do |f|
File.open(resultfile + '.html', 'w') do |o|
o.puts $fileheader
while (line = f.gets)
line.gsub!(/(#{filename}:(\d+))/, "<a href=\" #{url}#L\\2\">\\1</a>")
if line =~ /race with|\[Warning\]/
o.puts '<font color="red">' + line.chop + '</font>'
elsif line =~ /\[Success\]/
o.puts '<font color="green">' + line.chop + '</font>'
else
o.puts line
end
end
o.puts '</body>'
o.puts '</html>'
end
end
end
$maxlen = $analyses.map { |x| x[0].length }.max + 1
def analyze_project(p, save)
filepath = File.expand_path(p.path, $bench_path)
dirname = File.dirname(filepath)
filename = File.basename(filepath)
resname = File.basename(p.name,'.c')
Dir.chdir(dirname)
puts "Analysing #{resname} (#{p.id}/#{$projects.length})"
first = true
$analyses.each do |a|
aname = a[0]
aparam = a[1]
if first
aparam += ' --enable incremental.save ' if save
aparam += ' --enable incremental.only-rename ' unless save
aparam += ' --set save_run original ' if $compare
aparam += ' --set outfile original.messages.json ' if $compare
else
aparam += ' --enable incremental.load ' if $incremental
aparam += ' --set save_run increment ' if $compare
aparam += ' --set outfile increment.messages.json ' if $compare
end
print " #{format("%*s", -$maxlen, aname)}"
STDOUT.flush
outfile = $testresults + resname + ".#{aname}.txt"
starttime = Time.now
#Add --sets cilout /dev/null to ignore CIL output.
cmd = "#{$goblint} --conf #{$goblint_conf} -v --set dbg.timeout #{$timeout} #{aparam} #{filename} #{p.params} --enable allglobs --enable dbg.timing.enabled --set result json-messages 1>#{outfile} 2>&1"
system(cmd)
status = $?.exitstatus
endtime = Time.now
File.open(outfile, 'a') do |f|
f.puts "\n=== APPENDED BY BENCHMARKING SCRIPT ==="
f.puts "Analysis began: #{starttime}"
f.puts "Analysis ended: #{endtime}"
f.puts "Duration: #{format("%.02f", endtime-starttime)} s"
f.puts "Goblint params: #{cmd}"
f.puts $vrsn
end
if status != 0
if status == 124
puts '-- Timeout!'
`echo "TIMEOUT #{$timeout} s" >> #{outfile}`
else
puts '-- Failed!'
`echo "EXITCODE #{status}" >> #{outfile}`
end
else
system("#{$goblint} --conf #{$goblint_conf} -v --enable dbg.compare_runs.diff --compare_runs original increment #{filename} #{p.params} 2>&1 | sed '2000,/comparison summary/{/comparison summary/!d;}' > #{outfile}.compare.txt") if $compare and not first
system("#{$messagesCompare} --no-colors original.messages.json increment.messages.json > #{outfile}.compare.messages.txt") if $compare and not first
puts '-- Done!'
end
first = false
print_res p.id
proc_res(outfile, p.url, filename)
end
`rm -rf original increment` if $compare
`rm original.messages.json increment.messages.json` if $compare
end
#analysing the files
gname = ''
system("rm -f #{$testresults}/*")
FileUtils.cp(conf_file, File.join($testresults, $conf_name))
system("#{$goblint} --conf #{$goblint_conf} --writeconf #{$testresults}/#{$goblint_conf_name}")
$projects.each do |p|
if p.group != gname
gname = p.group
puts gname
end
analyze_project(p, true)
path = File.expand_path(p.path, $bench_path)
p.patches.each do |pfile|
`patch -b #{path} #{pfile}`
pp = Project.new(p.id,pfile,p.size,'patch',nil,path,p.params,nil)
analyze_project(pp, false)
`patch -b -R #{path} #{pfile}`
`rm #{path}.orig`
end
`rm -rf incremental_data`
end
print_res nil
puts ('Results: ' + $theresultfile)