stats.py

来自「linux下基于c++的处理器仿真平台。具有处理器流水线」· Python 代码 · 共 527 行 · 第 1/2 页

PY
527
字号
#!/usr/bin/env python# Copyright (c) 2003, 2004# The Regents of The University of Michigan# All Rights Reserved## This code is part of the M5 simulator, developed by Nathan Binkert,# Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions# from Ron Dreslinski, Dave Greene, Lisa Hsu, Kevin Lim, Ali Saidi,# and Andrew Schultz.## Permission is granted to use, copy, create derivative works and# redistribute this software and such derivative works for any purpose,# so long as the copyright notice above, this grant of permission, and# the disclaimer below appear in all copies made; and so long as the# name of The University of Michigan is not used in any advertising or# publicity pertaining to the use or distribution of this software# without specific, written prior authorization.## THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE# UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND WITHOUT# WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER EXPRESS OR# IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE REGENTS OF# THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE FOR ANY DAMAGES,# INCLUDING DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL# DAMAGES, WITH RESPECT TO ANY CLAIM ARISING OUT OF OR IN CONNECTION# WITH THE USE OF THE SOFTWARE, EVEN IF IT HAS BEEN OR IS HEREAFTER# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.from __future__ import divisionimport re, sys, mathdef usage():    print '''\Usage: %s [-E] [-F] [ -G <get> ] [-d <db> ] [-g <graphdir> ] [-h <host>] [-p]       [-s <system>] [-r <runs> ] [-T <samples>] [-u <username>]        <command> [command args]       commands    extra parameters   description       ----------- ------------------ ---------------------------------------       bins        [regex]            List bins (only matching regex)       formula     <formula>          Evaluated formula specified       formulas    [regex]            List formulas (only matching regex)       runs        none               List all runs in database       samples     none               List samples present in database       stability   <pairnum> <stats>  Calculated statistical info about stats       stat        <regex>            Show stat data (only matching regex)       stats       [regex]            List all stats (only matching regex)              database    <command>          Where command is drop, init, or clean     ''' % sys.argv[0]    sys.exit(1)def getopts(list, flags):    import getopt    try:        opts, args = getopt.getopt(list, flags)    except getopt.GetoptError:        usage()    return opts, argsclass CommandException(Exception):    passdef commands(options, command, args):    if command == 'database':        if len(args) == 0: raise CommandException        import dbinit        mydb = dbinit.MyDB(options)        if args[0] == 'drop':            if len(args) > 2: raise CommandException            mydb.admin()            mydb.drop()            if len(args) == 2 and args[1] == 'init':                mydb.create()                mydb.connect()                mydb.populate()            mydb.close()            return        if args[0] == 'init':            if len(args) > 1: raise CommandException            mydb.admin()            mydb.create()            mydb.connect()            mydb.populate()            mydb.close()            return        if args[0] == 'clean':            if len(args) > 1: raise CommandException            mydb.connect()            mydb.clean()            return        raise CommandException    import db, info    info.source = db.Database()    info.source.host = options.host    info.source.db = options.db    info.source.passwd = options.passwd    info.source.user = options.user    info.source.connect()    #info.source.update_dict(globals())    if type(options.get) is str:        info.source.get = options.get            if options.runs is None:        runs = info.source.allRuns    else:        rx = re.compile(options.runs)        runs = []        for run in info.source.allRuns:            if rx.match(run.name):                runs.append(run)    info.display_run = runs[0].run    if command == 'runs':        user = None        opts, args = getopts(args, '-u')        if len(args):            raise CommandException        for o,a in opts:            if o == '-u':                user = a        info.source.listRuns(user)        return       if command == 'stats':        if len(args) == 0:            info.source.listStats()        elif len(args) == 1:            info.source.listStats(args[0])        else:            raise CommandException        return        if command == 'bins':        if len(args) == 0:            info.source.listBins()        elif len(args) == 1:            info.source.listBins(args[0])        else:            raise CommandException        return        if command == 'formulas':        if len(args) == 0:            info.source.listFormulas()        elif len(args) == 1:            info.source.listFormulas(args[0])        else:            raise CommandException        return        if command == 'samples':        if len(args):            raise CommandException        info.source.listTicks(runs)        return    if command == 'stability':        if len(args) < 2:            raise CommandException                   try:            merge = int(args[0])        except ValueError:            usage()        stats = info.source.getStat(args[1])        info.source.get = "sum"                def disp(*args):            print "%-20s %12s %12s %4s %5s %5s %5s %10s" % args                # temporary variable containing a bunch of dashes        d = '-' * 100        #loop through all the stats selected        for stat in stats:            print "%s:" % stat.name            disp("run name", "average", "stdev", ">10%", ">1SDV", ">2SDV",                 "SAMP", "CV")            disp(d[:20], d[:12], d[:12], d[:4], d[:5], d[:5], d[:5], d[:10])            #loop through all the selected runs            for run in runs:                info.display_run = run.run;                runTicks = info.source.retTicks([ run ])                #throw away the first one, it's 0                runTicks.pop(0)                info.globalTicks = runTicks                avg = 0                stdev = 0                numoutsideavg  = 0                numoutside1std = 0                numoutside2std = 0                pairRunTicks = []                if float(stat) == 1e300*1e300:                    continue                for t in range(0, len(runTicks)-(merge-1), merge):                    tempPair = []                    for p in range(0,merge):                        tempPair.append(runTicks[t+p])                    pairRunTicks.append(tempPair)                #loop through all the various ticks for each run                for tick in pairRunTicks:                    info.globalTicks = tick                    avg += float(stat)                avg /= len(pairRunTicks)                for tick in pairRunTicks:                    info.globalTicks = tick                    val = float(stat)                    stdev += pow((val-avg),2)                stdev = math.sqrt(stdev / len(pairRunTicks))                for tick in pairRunTicks:                    info.globalTicks = tick                    val = float(stat)                    if (val < (avg * .9)) or (val > (avg * 1.1)):                        numoutsideavg += 1                    if (val < (avg - stdev)) or (val > (avg + stdev)):                        numoutside1std += 1                    if (val < (avg - (2*stdev))) or (val > (avg + (2*stdev))):                        numoutside2std += 1                if avg > 1000:                     disp(run.name, "%.1f" % avg, "%.1f" % stdev,                         "%d" % numoutsideavg, "%d" % numoutside1std,                         "%d" % numoutside2std, "%d" % len(pairRunTicks),                         "%.3f" % (stdev/avg*100))                elif avg > 100:                     disp(run.name, "%.1f" % avg, "%.1f" % stdev,                         "%d" % numoutsideavg, "%d" % numoutside1std,                         "%d" % numoutside2std, "%d" % len(pairRunTicks),                         "%.5f" % (stdev/avg*100))                else:                    disp(run.name, "%.5f" % avg, "%.5f" % stdev,                         "%d" % numoutsideavg, "%d" % numoutside1std,                         "%d" % numoutside2std, "%d" % len(pairRunTicks),                         "%.7f" % (stdev/avg*100))        return        if command == 'all':        if len(args):            raise CommandException        all = [ 'bps', 'rxbps', 'txbps', 'bpt',                'misses', 'mpkb',                'ipkb',                'pps', 'bpp', 'txbpp', 'rxbpp',                'rtp', 'rtb' ]        for command in all:            commands(options, command, args)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?