#!/usr/bin/python """ INFO Sample READ-PRINT program for the Failure Trace Archive. PARAMETERS -h, --help Display help screen. --input= Set the input file to . Default: ../data/overnet_tab/event_trace.tab SAMPLE RUN FTA_ROOT/scripts> tab_event_trace_read-print.py Psyco FULL optimization PROG::Start... Config.InputFileName=..\data\overnet_tab\event_trace.tab Number of nodes=3000 Number of events=68892 (max events/node=213) Number of events for node id 0=39 Number of events for node id 1=1 Number of events for node id 2=1 Number of events for node id 3=1 Number of events for node id 4=1 PROG::All done! CONTACT INFO AIosup@gmail.com COPYRIGHT Copyright (c) 2009 by Alexandru IOSUP. All rights reserved. """ __author__ = 'Alexandru Iosup' __email__ = 'AIosup at gmail.com' __proggy = "tab_event_trace_read-print.py" __rev = "0.1" __version__ = '$Revision: 0.1$' __proggy_stamp__ = "%s v%s" % (__proggy, __rev) __file__ = 'sc-db_e5.py' __date__ = "$Date: 2009/06/29 16:36:18 $" __copyright__ = "Copyright (c) 2009 by Alexandru IOSUP. All rights reserved." __license__ = "Python" #--------------------------------------------------- # Log: # 29/06/2009 A.I. 0.1 Started this application #--------------------------------------------------- import sys, time, datetime, os def readEventInfo( FileName ): """ Reads events data and counts the number of events for each node. """ ## # uncomment the lines prefixed with ## in this method for debug info ## import traceback avai = 0 xa = 0 unavai = 0 xua = 0 x = 0; Info = {} fin = open( FileName, "rt" ) while 1: lines = fin.readlines(10000000) # 10M buffer if not lines: break #-- process lines for line in lines: if len(line) == 0 or line[0] == '#': continue try: # read fields event_id, component_id, node_id, platform_id, node_name,\ event_type, start_time, stop_time, event_end_reason, =\ line.strip().split('\t',9) # convert data node_id = int(node_id.strip()) start_time = int(start_time.strip()) stop_time = int(stop_time.strip()) if ((stop_time-start_time) <0): print "Wrong Event(stop_time>>", str(e) traceback.print_exc() except: pass fin.close() sys.stderr.write("Total availability time = %d (sec), # intervals =%d \n" % (avai, xa)) sys.stderr.write("Avg availability time = %f \n" % (avai/xa)) sys.stderr.write("Total unavailability time = %d (sec), #intervals =%d \n" % (unavai,xua)) sys.stderr.write("Avg unavailability time = %f \n" % (unavai/xua)) return Info def usage(progname): print __doc__ % vars() def version(): print "Version: ", __version__ print "Date: ", __date__ print __copyright__, "(", __email__, ")" def convertArgument( Arg, ConvertFunc, DefaultValue, ArgName = None ): try: tmpValue = ConvertFunc(Arg.strip()) if ArgName: print "%s set to %s.\n" % (str(ArgName), str(tmpValue)) except: # ValueError, e: tmpValue = DefaultValue if ArgName: print "%s set to default value (%s).\n" % (str(ArgName), str(tmpValue)) return tmpValue def main(argv): import getopt sys.stderr.write("PROG::Start...\n") ## single char params; suffix with ':' if they receive a value (they are not flags) OneCharOpts = "hi:" ## "hj:d:l:s:r:a:n:o:g:" ## multi char params; suffix with '=' if they receive a value (are not flags) MultiCharList = [ "help", # here params which receive a value (are not flags) "input=", # here the params with no single char version "version" ] try: opts, args = getopt.getopt( argv, OneCharOpts, MultiCharList ) except getopt.GetoptError, e: print "Unknown command:", str(e) usage(os.path.basename(sys.argv[0])) sys.exit(2) InputFileName = DefaultInputFileName = os.path.join('..', 'data', 'overnet_tab', 'event_trace.tab') for opt, arg in opts: if opt in ("--input"): InputFileName = str(arg) elif opt in ("-h", "--help"): usage(os.path.basename(sys.argv[0])) sys.exit() elif opt in ["--version"]: version() sys.exit() sys.stderr.write("Config.InputFileName = %s\n" % InputFileName) # parse data Info = readEventInfo( InputFileName ) # print very simple stats sys.stderr.write("Number of nodes = %d\n" % len(Info)) sys.stderr.write("Number of events = %d (max events/node=%d)\n" % ( sum(Info.values()), max(Info.values()) ) ) sys.stderr.write("Average number of events = %d \n" % ( (sum(Info.values()) / len(Info)) ) ) # print info for five nodes index, max_index = 1, 5 for NodeID in Info: sys.stderr.write("Number of events for node id %s = %d\n" % (str(NodeID), Info[NodeID])) index += 1 if index > max_index: break sys.stderr.write("PROG::All done!\n") if __name__ == "__main__": ##main(sys.argv[1:]) # Psyco FULL optimization sys.stderr.write("Psyco FULL optimization\n") try: import psyco psyco.full() except ImportError: sys.stderr.write("Could NOT load Psyco!\n") sys.stderr.flush() pass main(sys.argv[1:])