-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmassage_benchmark_info.rb
More file actions
128 lines (109 loc) · 3.27 KB
/
Copy pathmassage_benchmark_info.rb
File metadata and controls
128 lines (109 loc) · 3.27 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
dir_name = "/var/log/seph_benchmarks"
current_timestamp = Time.now.strftime("%Y_%m_%d_%H_%M")
FileUtils.mkdir_p "build/performance_report"
def read_bench_file(f, names, collated_results)
raw_results = Hash.new do |h, k|
h[k] = []
end
open(f) do |f|
f.each_line do |line|
name, time_taken = line.chomp.split(/\|/)
raw_results[name] << Float(time_taken)
end
end
missing_names = names.dup
raw_results.each do |name, times|
missing_names.delete(name)
collated_results[name] << times.min
end
missing_names.each do |name|
collated_results[name] << nil
end
end
groups = {}
all_names = []
Dir["bench/bench_*.sp"].each do |f|
current_bench = []
open(f) do |of|
of.each_line do |l|
if l =~ /^benchmark\("(.*?)",/
current_bench << $1
end
end
all_names |= current_bench
groups[f] = current_bench.sort
end
end
collated_results = Hash.new do |h, k|
h[k] = []
end
entries = []
Dir["#{dir_name}/all_bench_results*"].sort.each do |f|
f =~ /all_bench_results-(.*?)$/
entries << $1
read_bench_file(f, all_names, collated_results)
end
open("build/performance_report/index.html", "w") do |ixh|
ixh.puts <<HTML
<html>
<head>
<title>Seph performance report (#{current_timestamp.gsub("_", "-")})</title>
</head>
<body>
<h1>Seph performance report (#{current_timestamp.gsub("_", "-")})</h1>
HTML
group_index = 0
groups.keys.sort.each do |group|
unless groups[group].empty?
Tempfile.open("seph_benchmark_plot_load") do |pf|
pf.puts <<STR
set terminal svg
set xdata time
set timefmt "%Y-%m-%d-%H-%M"
set output "build/performance_report/benchmark_group_#{group_index}.svg"
# time range must be in same format as data file
set xrange ["#{entries.first.gsub("_", "-")}":"#{entries.last.gsub("_", "-")}"]
set grid
set xlabel "Timestamp"
set ylabel "Best time (s)"
set title "Benchmark: #{group.gsub("&", "&").gsub(">", ">").gsub("<", "<")}"
set key left box
STR
first = true
plot = ""
table = "<table border='1'>"
Tempfile.open("seph_benchmark_data") do |f|
ix = 0
groups[group].sort.each do |bname|
unless collated_results[bname].compact.empty?
table << "#{first ? "<tr>#{bname.gsub("&", "&").gsub(">", ">").gsub("<", "<")}</tr><tr>" : "</tr><tr>"}"
entries.zip(collated_results[bname]).each do |timestamp, entry|
f.puts "#{timestamp.gsub("_", "-")}\t#{entry}"
table << "<td>#{entry}</td>"
end
f.puts ""
f.puts ""
plot << "#{first ? "plot " : ", "}\"#{f.path}\" using 1:2 index #{ix} title \"#{bname.gsub("&", "&").gsub(">", ">").gsub("<", "<")}\" with linespoints"
first = false
ix += 1
end
end
pf.puts plot
f.flush
pf.flush
unless first
ixh.puts "<img src=\"benchmark_group_#{group_index}.svg\"/>"
ixh.puts "#{table}</tr></table>"
system("cat #{pf.path} | gnuplot")
group_index += 1
end
end
end
end
end
ixh.puts " </body>"
ixh.puts "</html>"
end