refactor: make osatsum.py use corpus.getStats() rather than filtering the by stat name itself

This commit also allows ostasum.py to load more than one stats log and taken an --action=sum, though this is not yet implemented
This commit is contained in:
Justin Clark-Casey
2014-07-17 20:48:46 +01:00
parent cb60558fdd
commit f41626bb53
3 changed files with 54 additions and 42 deletions
@@ -5,15 +5,33 @@ import pprint
import re
import sys
#######################
### OSimStatsHelper ###
#######################
class OSimStatsHelper:
@staticmethod
def sumStats(stats):
totals = []
for stat in stats.values():
absValues = stat['abs']['values']
for i in range(0, len(absValues)):
if i + 1 > len(totals):
totals.append(absValues[i])
else:
totals[i] += absValues[i]
return totals
#lineRe = re.compile("(.* .*) - (.*) : (\d+)[ ,]([^:]*)")
#lineRe = re.compile("(.* .*) - (.*) : (?P<abs>[\d\.-]+)(?: (?:\D+))?(?P<delta>[\d\.-]+)?")
lineRe = re.compile("(.* .*) - (.*) : (?P<abs>[^,]+)(?:, )?(?P<delta>[^,]+)?")
statsReportStartRe = re.compile(" - \*\*\* STATS REPORT AT")
valueRe = re.compile("([^ %/]+)(.*)")
############
### Osta ###
############
#######################
### OSimStatsCorpus ###
#######################
class OSimStatsCorpus:
_data = {}
@@ -45,12 +63,17 @@ class OSimStatsCorpus:
return self._data[category][container][name]
else:
return None
"""
Returns a dictionary of matching stats where fullName => stat
If no match stats are found then an empty dictionary is returned.
Returns a dictionary of stats where fullName => stat.
If glob is specified then this is used to match stats using their full name
If no stats are found then an empty dictionary is returned.
"""
def getStats(self, glob):
def getStats(self, glob = "*"):
# FIXME: Doing far more work than necessary here if we simply want all stats without matching.
if glob == None:
glob = "*"
matchingStats = collections.OrderedDict()
for category, containers in self._data.items():
@@ -14,16 +14,7 @@ def plotNoneAction(stats):
plt.plot(stat['abs']['values'], label=stat['container'])
def plotSumAction(stats):
totals = []
for stat in stats.values():
absValues = stat['abs']['values']
for i in range(0, len(absValues)):
if i + 1 > len(totals):
totals.append(absValues[i])
else:
totals[i] += absValues[i]
totals = OSimStatsHelper.sumStats(stats)
plt.plot(totals, label="Total")
############
@@ -16,40 +16,38 @@ parser.add_argument(
help = "Select a subset of stats by their fullname using a glob pattern. E.g. \"*Threads\" will only select stats ending in \"Threads\"",
default = argparse.SUPPRESS)
parser.add_argument(
'--action',
help = "Perform an action on the stat or stats. Only current action is none or sum. Default is none.",
default = "none")
parser.add_argument(
'statsLogPath',
help = "Path to the stats log file.",
metavar = "stats-log-path")
metavar = "stats-log-path",
nargs='*')
opts = parser.parse_args()
corpus = OSimStatsCorpus()
corpus.parse(opts.statsLogPath)
data = corpus.data
fullNames = []
for category, containers in data.items():
for container, stats in containers.items():
for statName, stat in stats.items():
fullNames.append(stat['fullName'])
for path in opts.statsLogPath:
corpus.parse(path)
stats = corpus.getStats()
longestKey = max(fullNames, key = len)
longestKey = max(stats, key = len)
for stat in stats.values():
absValues = stat['abs']['values']
sys.stdout.write(
"%-*s: %s to %s%s" % (
len(longestKey), stat['fullName'], min(absValues), max(absValues), stat['abs']['units']))
for category, containers in sorted(data.items()):
for container, stats in sorted(containers.items()):
for statName, stat in sorted(stats.items()):
if 'select' in opts and not fnmatch.fnmatch(stat['fullName'], opts.select):
continue
absValues = stat['abs']['values']
sys.stdout.write(
"%-*s: %s to %s%s" % (
len(longestKey), stat['fullName'], min(absValues), max(absValues), stat['abs']['units']))
if 'delta' in stat:
deltaValues = stat['delta']['values']
print ", %s to %s%s" % (min(deltaValues), max(deltaValues), stat['delta']['units'])
else:
print
if 'delta' in stat:
deltaValues = stat['delta']['values']
print ", %s to %s%s" % (min(deltaValues), max(deltaValues), stat['delta']['units'])
else:
print
print "\nFrom %s samples" % (len(corpus))