-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_graph.rb
executable file
·123 lines (110 loc) · 2.43 KB
/
plot_graph.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
#!/usr/bin/env ruby
#
# Create graph to plot data by gnuplot
#
require 'erb'
unless File.exist?('tmp/cov.csv')
puts <<USAGE
tmp/cov.csv does not exist.
Please run ./collect_data.rb first.
USAGE
exit!
end
def run command
puts command
system command
end
run "rm tmp/*.plt"
run "rm tmp/*.png"
tmpl1 = <<TMPL
set datafile separator ","
set terminal png
set output "<%= h[:name] %>.png"
set title "<%= h[:title] %>"
set xlabel "<%= h[:xlabel] %>"
set ylabel "<%= h[:ylabel] %>"
set label 1 "percentage"
plot "<%= h[:filename] %>" using 1:3 title "coverage" with lines
TMPL
tmpl2 = <<TMPL
set datafile separator ","
set terminal png
set output "<%= h[:name] %>.png"
set title "<%= h[:title] %>"
set xlabel "<%= h[:xlabel] %>"
set ylabel "<%= h[:ylabel] %>"
set label 1 "covered"
set label 2 "total"
plot "<%= h[:filename] %>" using 1:4 title "covered" with lines, "<%= h[:filename] %>" using 1:5 title "total" with lines
TMPL
blk = proc { |tmpl, h|
plot = ERB.new(tmpl).result binding
open("tmp/#{h[:name]}.plt", "w") {|f| f.write plot }
run("cd tmp && gnuplot #{h[:name]}.plt")
# system("open #{h[:name]}.png")
}
[
{
name: "statements-percentage",
title: "Statements Coverages (Percentage)",
xlabel: "Build Number",
ylabel: "Percentage",
filename: "cov-s.csv"
},
{
name:
"branches-percentage",
title: "Branches Coverages (Percentage)",
xlabel: "Build Number",
ylabel: "Percentage",
filename: "cov-b.csv"
},
{
name: "functions-percentage",
title: "Functions Coverages (Percentage)",
xlabel: "Build Number",
ylabel: "Percentage",
filename: "cov-f.csv"
},
{
name: "lines-percentage",
title: "Lines Coverages (Percentage)",
xlabel: "Build Number",
ylabel: "Percentage",
filename: "cov-l.csv"
},
].each do |h|
blk.call(tmpl1, h)
end
[
{
name: "statements-lines",
title: "Statements Coverages",
xlabel: "Build Number",
ylabel: "Statements",
filename: "cov-s.csv"
},
{
name: "branches-lines",
title: "Branches Coverages",
xlabel: "Build Number",
ylabel: "Branches",
filename: "cov-b.csv"
},
{
name: "functions-lines",
title: "Functions Coverages",
xlabel: "Build Number",
ylabel: "Functions",
filename: "cov-f.csv"
},
{
name: "lines-lines",
title: "Lines Coverages",
xlabel: "Build Number",
ylabel: "Lines",
filename: "cov-l.csv"
},
].each do |h|
blk.call(tmpl2, h)
end