#!/usr/bin/python

import argparse
import matplotlib.pyplot as plt
import sys
from pylab import *
from osta.osta import *

############
### MAIN ###
############
parser = argparse.ArgumentParser(formatter_class = argparse.RawTextHelpFormatter)

parser.add_argument(
    '--select', 
    help = "Select the full name of a stat to graph (e.g. \"scene.Keynote 1.RootAgents\")")

parser.add_argument(
    '--out',
    help = "Path to output the graph rather the interactively display.  Filename extension determines graphics type (e.g. \"graph.jpg\")",
    default = argparse.SUPPRESS)

parser.add_argument(
    'statsLogPath', 
    help = "Path to the stats log file.", 
    metavar = "stats-log-path",
    nargs='*')

opts = parser.parse_args()

corpus = OSimStatsCorpus()

for path in opts.statsLogPath:
    corpus.parse(path)

stats = corpus.getStats(opts.select)

if len(stats) <= 0:
    print "No stats matching %s" % (opts.select)
    sys.exit(1)

plt.title(opts.select)

# Arbitrarily use the first stat for this
plt.ylabel(stats[stats.keys()[0]]['name'])

for stat in stats.values():
    plt.plot(stat['abs']['values'], label=stat['container'])    
    plt.xlabel("samples")
    
plt.legend()        
    
if 'out' in opts:
    savefig(opts.out)
else:
    plt.show()      
@@ -116,16 +116,195 @@
 port *%0A%0A
+#################%0A### FUNCTIONS ###%0A#################%0Adef plotNoneAction(stats):%0A    for stat in stats.values():%0A        plt.plot(stat%5B'abs'%5D%5B'values'%5D, label=stat%5B'container'%5D)%0A%0A
 ########
@@ -548,16 +548,185 @@
 s%5C%22)%22)%0A%0A
+parser.add_argument(%0A    '--action',%0A    help = %22Perform an action on the stat or stats.  Only current action is none or sum.  Default is none.%22,%0A    default = %22none%22)%0A%0A
 parser.a
@@ -1296,118 +1296,222 @@
 1)%0A%0A
-plt.title(opts.select)%0A%0A# Arbitrarily use the first stat for this%0Aplt.ylabel(stats%5Bstats.keys()%5B0%5D%5D%5B'name'%5D)%0A%0A
+# Used to fetch data that will be the same for all stats%0AoneStat = stats%5Bstats.keys()%5B0%5D%5D%0A%0Aplt.title(opts.select)%0Aplt.ylabel(oneStat%5B'name'%5D)%0Aplt.xlabel(%22samples%22)%0A%0Aif opts.action == 'sum':    %0A    totals = %5B%5D%0A    
 for 
@@ -1534,33 +1534,40 @@
 lues():%0A    
-plt.plot(
+    absValues = 
 stat%5B'abs'%5D%5B
@@ -1579,63 +1579,284 @@
 es'%5D
-, label=stat%5B'container'%5D)    %0A    plt.xlabel(%22samples%22
+%0A        %0A        for i in range(0, len(absValues)):%0A            if i + 1 %3E len(totals):%0A                totals.append(absValues%5Bi%5D)%0A            else:%0A                totals%5Bi%5D += absValues%5Bi%5D%0A                %0A    plt.plot(totals, label=%22Total%22)%0Aelse:%0A    plotNoneAction(stats
 )%0A  

Implement --action=sum option that will sum selected stats