-
Notifications
You must be signed in to change notification settings - Fork 6
/
update_bench_traces.rb
executable file
·292 lines (275 loc) · 9.48 KB
/
update_bench_traces.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
#!/usr/bin/ruby
require 'fileutils'
Dir.chdir(File.dirname(__FILE__))
goblint = File.expand_path("../analyzer/goblint")
goblint_conf = File.expand_path("../analyzer/conf/traces.json")
compare = File.expand_path("../analyzer/privPrecCompare")
fail "Please run script from goblint dir!" unless File.exist?(goblint)
$vrsn = `#{goblint} --version`
results = "bench_result"
Dir.mkdir(results) unless Dir.exist?(results)
$testresults = File.expand_path("bench_result") + "/"
bench = "./"
linux = bench + "linux/"
cmds = {"code2html" => lambda {|f,o| "code2html -l c -n #{f} 2> /dev/null 1> #{o}"},
"source-highlight" => lambda {|f,o| "source-highlight -n -i #{f} -o #{o}"},
"pygmentize" => lambda {|f,o| "pygmentize -O full,linenos=1 -o #{o} #{f}"}
}
highlighter = nil
cmds.each do |name, cmd|
# if `which #{cmd} 2> /dev/null`.empty? then
if ENV['PATH'].split(':').map {|f| File.executable? "#{f}/#{name}"}.include?(true) then
highlighter = cmd
break
end
end
if highlighter.nil? then
puts "Warning: No syntax highlighter installed (code2html, source-highlight, pygmentize)."
highlighter = lambda {|f,o| "cp #{f} #{o}"}
end
class Project
attr_reader :id, :name, :group, :path
attr_accessor :url, :params
def initialize(id, name, size, url, group, path, params)
@id = id
@name = name
@size = size
@url = url
@group = group
@path = path
@params = params
end
def to_html
"<td>#{@id}</td><td><a href=\"#{@url}\">#{@name}</a></td>\n" + "<td>#{@size}</td>\n"
end
def to_s
"#{@name}"
end
end
$projects = []
$header = <<END
<head>
<title>Benchmarks on #{`uname -n`.chomp}</title>
<style type="text/css">
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_res (i)
File.open($theresultfile, "w") do |f|
f.puts "<html>"
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 then
gname = p.group
f.puts "<tr><th colspan=#{4+$analyses.size+1}>#{gname}</th></tr>"
if $print_desc then
f.puts "<tr><th>#</th><th>Name</th><th>Description</th><th>Size</th>"
else
f.puts "<tr><th>#</th><th>Name</th><th>Size</th>"
end
$analyses.each do |a|
aname = a[0]
f.puts "<th>#{aname}</th>"
end
f.puts "<th>compare</th>"
end
f.puts "<tr>"
f.puts p.to_html
$analyses.each do |a|
aname = a[0]
outfile = File.basename(p.path,".c") + ".#{aname}.txt"
if File.exists?($testresults + outfile) then
File.open($testresults + outfile, "r") do |g|
lines = g.readlines
# 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
uncalled = lines.grep(/is uncalled/).reject {|x| x =~ /__check/}.size
live = lines.grep(/live:[ ]*([0-9]*)/) { |x| $1.to_i } .first
dead = lines.grep(/dead:[ ]*([0-9]*)/) { |x| $1.to_i } .first
total = live.nil? || dead.nil? ? nil : live + dead
res = lines.grep(/^TIMEOUT\s*(\d*) s.*$/) { |x| $1 }
if res == [] then
dur = lines.grep(/^Duration: (.*) s/) { |x| $1 }
cod = lines.grep(/^EXITCODE\s*(.*)$/) { |x| $1 }
if cod == [] and not dur == [] then
# thenumbers = "<font color=\"green\" title=\"safe memory locations\">#{safely}</font>; "
# thenumbers << "<font color=\"orange\" title=\"vulnerable memory locations\">#{vulner}</font> + "
# thenumbers << "<font color=\"red\" title=\"unsafe memory locations\">#{unsafe}</font>; "
thenumbers = ""
thenumbers << "<font color=\"magenta\" title=\"uncalled functions\">#{uncalled}</font>; " if uncalled > 0
thenumbers << "<b><font color=\"red\" title=\"dead lines\">#{dead}</font></b>+"
thenumbers << "<b title=\"live lines\">#{live}</b>="
thenumbers << "<span title=\"total (logical) lines\">#{total}</span>"
f.puts "<td><a href=\"#{outfile}.html\">#{"%.2f" % dur} s</a> (#{thenumbers})</td>"
else
f.puts "<td><a href=\"#{outfile}\">failed (code: #{cod.first.to_s})</a></td>"
end
else
f.puts "<td><a href=\"#{outfile}\">#{res.first.to_s} s</a> (limit)</td>"
end
end
else
f.puts "<td>N/A</a></td>"
end
end
comparefile = File.basename(p.path,".c") + ".compare.txt"
f.puts "<td><a href=\"#{comparefile}\">compare</a></td>"
f.puts "</tr>"
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 "#{$vrsn}"
f.puts "</p>"
f.puts "</body>"
f.puts "</html>"
end
end
#Command line parameters
timeout = 900
timeout = ARGV[0].to_i unless ARGV[0].nil?
only = ARGV[1] unless ARGV[1].nil?
if only == "group" then
only = nil
thegroup = ARGV[2]
end
#processing the input file
skipgrp = []
file = "bench.txt"
$linuxroot = "https://elixir.bootlin.com/linux/v4.0/source/"
File.symlink("index/traces.txt",file) unless FileTest.exists? file
FileUtils.cp(file,File.join($testresults, "bench.txt"))
$analyses = []
File.open(file, "r") do |f|
id = 0
while line = f.gets
next if line =~ /^\s*$/
if line =~ /Group: (.*)/
gname = $1.chomp
skipgrp << gname if line =~ /SKIP/
elsif line =~ /(.*): ?(.*)/
$analyses << [$1,$2]
else
name = line.chomp
url = f.gets.chomp
path = f.gets.chomp
params = f.gets.chomp
params = "" if params == "-"
if url == "linux!" then
params = "--enable kernel " + params
url = $linuxroot + path
path = File.expand_path(path, linux)
else
path = File.expand_path(path, bench)
end
size = `wc -l #{path}`.split[0] + " lines"
id += 1
p = Project.new(id,name,size,url,gname,path,params)
$projects << p
end
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_linux_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.sub!(/\@(#{filename}:(\d+))/, "@<a href=\" #{url}#L\\2\">\\1</a>")
if line =~ /race with/
o.puts '<font color="red">' + line.chop + "</font>"
else
o.puts line
end
end
o.puts "</body>"
o.puts "</html>"
end
end
end
#analysing the files
gname = ""
maxlen = $analyses.map { |x| x[0].length }.max + 1
$projects.each do |p|
next if skipgrp.member? p.group
next unless thegroup.nil? or p.group == thegroup
next unless only.nil? or p.name == only
if p.group != gname then
gname = p.group
puts gname
end
filepath = p.path
dirname = File.dirname(filepath)
filename = File.basename(filepath)
Dir.chdir(dirname)
outfiles = $testresults + File.basename(filename,".c") + ".*"
`rm -f #{outfiles}`
if p.url == "generate!" then
system(highlighter.call(p.path, $testresults + p.name + ".html"))
p.url = p.name + ".html"
end
puts "Analysing #{filename} (#{p.id}/#{$projects.length})"
precfiles = []
$analyses.each do |a|
aname = a[0]
aparam = a[1]
print " #{format("%*s", -maxlen, aname)}"
STDOUT.flush
outfile = $testresults + File.basename(filename,".c") + ".#{aname}.txt"
precfile = $testresults + File.basename(filename,".c") + ".#{aname}.prec"
starttime = Time.now
#Add --sets cilout /dev/null to ignore CIL output.
cmd = "#{goblint} --conf #{goblint_conf} --set dbg.timeout #{timeout} #{aparam} #{filename} #{p.params} --enable allglobs --enable dbg.timing.enabled --enable warn.debug -v --sets exp.priv-prec-dump #{precfile} 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 then
if status == 124 then
puts "-- Timeout!"
`echo "TIMEOUT #{timeout} s" >> #{outfile}`
else
puts "-- Failed!"
`echo "EXITCODE #{status}" >> #{outfile}`
end
else
puts "-- Done!"
precfiles << precfile
end
print_res p.id
proc_linux_res(outfile, p.url, filename)
end
puts "Comparing..."
comparefile = $testresults + File.basename(filename,".c") + ".compare.txt"
system("#{compare} #{precfiles.join(" ")} 2>&1 1> #{comparefile}")
end
print_res nil
puts ("Results: " + $theresultfile)