-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog_analysis.rb
executable file
·139 lines (123 loc) · 2.88 KB
/
log_analysis.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
$file_path = ARGV[0]
$base_log = $file_path.split("/").last
$dir = $file_path.split("/").first
$log_date = $base_log.split(".")[0]
$ors = []
$crs = []
$tps = []
$dls = []
$mps = []
$buffers = []
$caches = []
$memalls = []
$times = []
$critical = []
$we = []
$rpss = []
$weights = []
def write_log(arr, str)
File.open($dir + "/" + $log_date + "_" + str + ".csv", "w") do |f|
arr.each { |s| f.puts(s);}
end
end
def sort_log(arr, str)
tmp = []
arr.each do |line|
items = line.split(",")
len = items.length
sorted = Array.new(len)
for i in 0..len-1 do
if items[i] == nil
next
end
if i == 0
sorted[i] = items[i]
next
elsif i == 1
next
end
br_o_i = items[i].index("[")
br_c_i = items[i].index("]")
id = items[i][br_o_i + 1 .. br_c_i - 1]
sorted[id.to_i + 1] = items[i][br_c_i + 1 .. -1].chomp
end
sorted.each do |x|
if x == nil
sorted.delete(x)
end
end
s = sorted.join(",")
tmp.push(s)
end
write_log(tmp, str)
end
def sort_weights(arr, str)
tmp = []
arr.each do |line|
items = line.split(",")
len = items.length
sorted = Array.new(len)
for i in 0..len-1 do
if i == 0
sorted[i] = items[i]
next
end
if items[i].index("weights") != nil
next
end
datas = items[i].split(" ")
number = datas[0].split("-").last
sorted[number.to_i + 1] = datas[1].chomp
end
sorted.each do |x|
if x == nil
sorted.delete(x)
end
end
s = sorted.join(",")
tmp.push(s)
end
write_log(tmp, str)
end
def sort_dls
# todo
end
begin
File.open($file_path) do |file|
file.each_line do |line|
case line.split(",")[1]
when "ors" then $ors.push(line)
when "crs" then $crs.push(line)
when "tps" then $tps.push(line)
when "dls" then $dls.push(line)
when "mps" then $mps.push(line)
when "buffers" then $buffers.push(line)
when "caches" then $caches.push(line)
when "memalls" then $memalls.push(line)
when "times" then $times.push(line)
when "rpss" then $rpss.push(line)
when "critical" then $critical.push(line)
when "we" then $we.push(line)
end
if line.index("weights") != nil
$weights.push(line)
end
end
end
sort_log($ors, "ors")
sort_log($crs, "crs")
sort_log($tps, "tps")
sort_log($mps, "mps")
sort_log($buffers, "buffers")
sort_log($caches, "caches")
write_log($memalls, "memalls")
sort_log($times, "times")
sort_log($rpss, "rpss")
write_log($critical, "critical")
write_log($we, "we")
sort_weights($weights, "weights")
rescue SystemCallError => e
puts %Q(class=[#{e.class}] message=[#{e.message}])
rescue IOError => e
puts %Q(class=[#{e.class}] message=[#{e.message}])
end