File: plot

package info (click to toggle)
elpi 2.0.7-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 50,296 kB
  • sloc: ml: 18,791; makefile: 229; python: 95; sh: 7
file content (106 lines) | stat: -rwxr-xr-x 3,226 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/env lua5.1

file = assert(io.open(arg[1]),"Argument missing: .csv file name")
data = {}
for l in file:lines() do
	local runner,job,it,wc,mem =
	 l:match('^([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)$')
	assert(runner and job and wc and mem and it, "format error: " .. l)
	it = math.floor(tonumber(it) * 100)
	wc = math.floor(tonumber(wc) * 100)
	local item = data[job] or {}
	local wcl = (item[runner] or {}).time or {}
	wcl[#wcl+1] = wc
	local itl = (item[runner] or {}).itime or {}
	itl[#itl+1] = it
	item[runner] = { time = wcl; mem = tonumber(mem); itime = itl }
	data[job] = item
end

all_runners = {}
all_jobs = {}
for job, runners in pairs(data) do
	for runner, _ in pairs(runners) do
		all_runners[runner] = true
	end
	all_jobs[#all_jobs+1] = job
end
table.sort(all_jobs,function(j1,j2) return j1 < j2 end)

pname = arg[2] or arg[1]
out = assert(io.open(pname..'.dat','w'), 'Unable to open output file')

function average(l)
	local t = 0
	for _,v in ipairs(l) do t = t + v end
	return t / #l
end

for i,job in ipairs(all_jobs) do
	local runners = data[job]
	out:write(i,' ',job,' ')
	local fastest = 99999999999999
	for runner, _ in pairs(all_runners) do
		local runner_data =
		  runners[runner] or { time = {0}; mem = 0; itime = {0} }
                local t = average(runner_data.itime)
		if t < fastest and runner_data.mem ~= 0 then fastest = t end
	end
	for runner, _ in pairs(all_runners) do
		local runner_data =
		  runners[runner] or { time = {0}; mem = 0; itime = {0} }
	 	local delta = -(average(runner_data.itime) - fastest)
		if runner_data.mem == 0 then delta = 0 end
		out:write(runner,' ',average(runner_data.time),' ',
		                     average(runner_data.itime),' ',
		                     delta,' ',
				     runner_data.mem,' ')
	end
	out:write('\n')
end
out:close()

plot = assert(io.open(pname..'.plot','w'), 'Unable to write to output file')
plot:write([[
set terminal svg background rgb 'white' size ]]..math.max(#all_jobs*30,300)..[[, 2000
set xrange [0:]]..(#all_jobs+2)..[[]
set y2range [0:]
set xtics rotate by 90 right
set xlabel "test"
set y2tics
set grid mytics 
set grid ytics
set grid y2tics
set mytics
set linetype 1 lc rgb "#FF0000"
set linetype 2 lc rgb "#006600"
set linetype 3 lc rgb "#3300CC"
set linetype 4 lc rgb "#DDDD66"
set linetype 5 lc rgb "#66FFFF"
set linetype 6 lc rgb "#6666FF"
set style fill solid 0.4
set key right bottom
set boxwidth 0.1 absolute
set output "]]..pname..[[.svg"
plot \
]])
i=1
for runner, _ in pairs(all_runners) do
	local tics = ""
	if i == 1 then tics = ':xtic(2)' end
	local pos = '$1+' .. string.format("%3.1f",(i-1) * 0.2)
        plot:write('"'..pname..'.dat" \\\n')
	local start = string.format("%d:%d",2+(i-1)*5+3,2+(i-1)*5+2)
	local stop = string.format("%d:(0)",2+(i-1)*5+4)
	plot:write('using ('..pos..'):'..start..':'..stop..tics..' with candlesticks title "'..  runner..'", \\\n')
	i=i+1
end
i=1
for runner, _ in pairs(all_runners) do
	local pos = '$1+' .. string.format("%3.1f",(i-1) * 0.2)
        plot:write('"'..pname..'.dat" \\\n')
	local start = string.format("%d",2+(i-1)*5+5)
	plot:write('using ('..pos..'):'..start..' with boxes lw 0 fill solid 0.2 axes x1y2 title "'..  runner..'", \\\n')
	i=i+1
end
plot:close()