-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcEffiency.py
executable file
·114 lines (91 loc) · 3.81 KB
/
gcEffiency.py
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
#!/usr/bin/env python
#
# This script is used calculate the efficiency of the Garbage Collector.
# It analyzes the input java garbage collector and calculates how much time the JVM is spending doing garbage collection
# This script can be used to define a garbage collection baseline and to find how different tuning are affecting its effiency
#
import sys, os
import argparse
def analyzeLog(log):
totalgccount=shortgccount=fullgccount=0
totalgctime=shortgctime=fullgctime=0
longestshortgc=longestfullgc=0
apptime=previoustime=0
with open(log) as f:
for line in f:
line = line.replace("\r","").replace("\n","")
#print line
try:
totalgccount += 1
pos = line.find(" secs]")
if pos != -1:
line = line[:pos]
time = float(line.split(" ")[-1])
currenttime = float(line.split(" ")[0][:-1])
totalgctime += time
# print time
if line.find("[GC") != -1:
shortgccount += 1
shortgctime += time
if time > longestshortgc:
longestshortgc = time
if line.find("[Full GC") != -1:
fullgccount += 1
fullgctime += time
if time > longestfullgc:
longestfullgc = time
if previoustime != 0:
if previoustime < currenttime:
apptime += (currenttime - previoustime)
else:
#If JVM has restarted
apptime += currenttime
previoustime = currenttime
except Exception as e:
print >> sys.stderr, "Error processing line: " + line
print >> sys.stderr, e
efficency = "{0:.4f}".format(1 - (totalgctime/apptime))
if totalgccount != 0:
totalgcavg = "{0:.4f}".format(totalgctime/totalgccount)
else:
totalgcavg = "0"
totalgctime = "{0:.4f}".format(totalgctime)
totalgccount = str(totalgccount)
if shortgccount != 0:
shortgcavg = "{0:.4f}".format(shortgctime/shortgccount)
else:
shortgcavg = "0"
shortgctime = "{0:.4f}".format(shortgctime)
shortgccount = str(shortgccount)
longestshortgc = str(longestshortgc)
if fullgccount != 0:
fullgcavg = "{0:.4f}".format(fullgctime/fullgccount)
else:
fullgcavg = "0"
fullgctime = "{0:.4f}".format(fullgctime)
fullgccount = str(fullgccount)
longestfullgc = str(longestfullgc)
apptime = "{0:.4f}".format(apptime)
if args.csv:
print log + ";" + efficency + ";" + apptime + ";" + totalgccount + ";" + totalgctime + ";" + totalgcavg + ";" + shortgccount + ";" + shortgctime + ";" + shortgcavg + ";" + longestshortgc + ";" + fullgccount + ";" + fullgctime + ";" + fullgcavg + ";" + longestfullgc
else:
print "Log: " + log
print "Application execution time = " + apptime + " secs"
print "Efficency = " + efficency + "%"
print "Total GC: Count = " + totalgccount.ljust(8) + " Total time = " + totalgctime + " secs".ljust(10) + " Average time = " + totalgcavg + " secs".ljust(10)
print "Short GC: Count = " + shortgccount.ljust(8) + " Total time = " + shortgctime + " secs".ljust(10) + " Average time = " + shortgcavg + " secs".ljust(10) + " Longest GC = " + longestshortgc + " secs".ljust(8)
print "Full GC: Count = " + fullgccount.ljust(8) + " Total time = " + fullgctime + " secs".ljust(10) + " Average time = " + fullgcavg + " secs".ljust(10) + " Longest GC = " + longestfullgc + " secs".ljust(8)
print
parser = argparse.ArgumentParser(description='Calculate the GC efficency for Java GC logs.')
parser.add_argument('logs', metavar='log', type=str, nargs='+',
help='garbage logs')
parser.add_argument('-c','--csv', dest='csv', action='store_true',
# const=sum, default=max,
help='Show output as CSV')
args = parser.parse_args()
#print args.accumulate(args.integers)
if args.csv:
print "log;efficency;apptime;totalgccount;totalgctime;totalgcavg;shortgccount;shortgctime;shortgcavg;longestshortgc;fullgccount;fullgctime;fullgcavg;longestfullgc"
for log in args.logs:
if os.path.exists(log):
analyzeLog(log)