-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbottleneck2graph.rb
More file actions
68 lines (57 loc) · 1.95 KB
/
bottleneck2graph.rb
File metadata and controls
68 lines (57 loc) · 1.95 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
#!/usr/bin/ruby
require "optparse"
require "csv"
require "time"
require "gnuplot"
params = ARGV.getopts("f:t:").map { |k, v| [k.to_sym, v] }.to_h
params[:f] = if params[:f].nil? then 0 else params[:f].to_i end
params[:t] = if params[:t].nil? then -1 else params[:t].to_i end
unless ARGV.size == 2
raise "Usage: ruby bottleneck2graph.rb [-f START-CLOCK] [-t END-CLOCK] FASTSTAT-LOG-FILE KVSP-LOG-FILE"
end
faststat_log_file = ARGV[0]
kvsp_log_file = ARGV[1]
faststat_log = CSV.read(faststat_log_file)[1..-1].map { |row|
[Time.strptime(row[0], "%Y-%m-%d %H:%M:%S.%L")] + row[1..-1].map(&:to_f)
}
kvsp_log = CSV.read(kvsp_log_file).map { |row|
[Time.strptime(row[0], "%Y-%m-%d %H:%M:%S.%L"), row[1]]
}.select { |row| row[1] == "start" }
unless faststat_log.size > 0 and kvsp_log.size > 0
raise "Invalid log files"
end
epoch_time = kvsp_log[0][0]
start_time = kvsp_log[params[:f]][0]
end_time = kvsp_log[params[:t]][0]
faststat_log = faststat_log.select { |row| start_time <= row[0] and row[0] <= end_time }
kvsp_log = kvsp_log.select { |row| start_time <= row[0] and row[0] <= end_time }
cpu_stat = faststat_log.map { |row|
[
row[0] - epoch_time,
100 - row[4], # total - idle
]
}.transpose
gpu_stat = faststat_log.map { |row| [row[0] - epoch_time, row[11]] }.transpose
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.title "#{faststat_log_file}, #{kvsp_log_file}"
plot.ylabel "Usage"
plot.xlabel "Time"
plot.xrange "[#{start_time - epoch_time}:#{end_time - epoch_time}]"
plot.set "size ratio 0.25"
kvsp_log.each do |row|
x = row[0] - epoch_time
plot.arrow "from first #{x}, graph 0 to #{x}, graph 1 nohead lw 1 lc rgb 'red'"
end
plot.data << Gnuplot::DataSet.new(cpu_stat) do |ds|
ds.title = "CPU"
ds.with = "lines"
ds.linewidth = 0.5
end
plot.data << Gnuplot::DataSet.new(gpu_stat) do |ds|
ds.title = "GPU"
ds.with = "lines"
ds.linewidth = 0.5
end
end
end