Script generating module statistics from module logs.
The script generates statistics of all loaded modules including a given pattern within a given time interval.
This commit is contained in:
parent
53415f9852
commit
087f1668a3
1 changed files with 62 additions and 0 deletions
62
module_stats.py
Executable file
62
module_stats.py
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env python2.6
|
||||
#
|
||||
# Copyright(c) 2013 Christoph Niethammer <niethammer@hlrs.de>
|
||||
#
|
||||
|
||||
import os
|
||||
import datetime
|
||||
from optparse import OptionParser
|
||||
|
||||
|
||||
modules = list()
|
||||
modulestats = dict()
|
||||
|
||||
logdir = '/sw/laki/hlrs/system/modules/logs/'
|
||||
enddate = datetime.date.today()
|
||||
startdate = datetime.date(enddate.year, enddate.month, 1)
|
||||
modulepattern=""
|
||||
|
||||
parser = OptionParser(usage="%prog [options] [pattern]")
|
||||
parser.add_option("--logdir", metavar="DIR", dest="logdir")
|
||||
parser.add_option("--startdate", metavar="YYYY-MM-DD", dest="startdate")
|
||||
parser.add_option("--enddate", metavar="YYYY-MM-DD", dest="enddate")
|
||||
(options, args) = parser.parse_args()
|
||||
if options.logdir :
|
||||
logdir = options.logdir
|
||||
if options.startdate :
|
||||
d = options.startdate
|
||||
startdate = datetime.date(int(d[0:4]),int(d[5:7]),int(d[8:10]))
|
||||
if options.enddate :
|
||||
d = options.enddate
|
||||
enddate = datetime.date(int(d[0:4]),int(d[5:7]),int(d[8:10]))
|
||||
if len(args) > 0 :
|
||||
modulepattern = args[0]
|
||||
|
||||
|
||||
for logfilename in os.listdir(logdir) :
|
||||
d = datetime.date(int(logfilename[0:4]),int(logfilename[4:6]),int(logfilename[6:8]))
|
||||
if d < startdate :
|
||||
continue
|
||||
if d > enddate :
|
||||
continue
|
||||
date = d.strftime('%Y-%m-%d')
|
||||
logfile = os.path.join(logdir, logfilename)
|
||||
f = open(logfile)
|
||||
for line in f :
|
||||
if ' load' in line and modulepattern in line :
|
||||
module = line.split()[-1]
|
||||
if module not in modules:
|
||||
modules.append(module)
|
||||
modulestats[module] = 1
|
||||
else :
|
||||
modulestats[module] = modulestats[module] + 1
|
||||
# if ' swap' in line :
|
||||
# print line.split()
|
||||
|
||||
|
||||
print "-"*78
|
||||
print "Module statistics for " + startdate.strftime('%Y-%m-%d') + " - " + enddate.strftime('%Y-%m-%d')
|
||||
print "-"*78
|
||||
for (v,m) in sorted( ((v,k) for k,v in modulestats.iteritems()), reverse=True) :
|
||||
print "{0:70s}{1:>8d}".format(m, v)
|
||||
|
Loading…
Reference in a new issue