Statistics on the total throughput/average latency/real-time throughput of each stream in qualnet. Trace should be useful for qualnet simulation.
Using lxml for parsing, the memory usage is half that of the built-in elementtree, and the speed is superb.
It is better to use the data stored in dict to change it to a class, but it is not difficult to change it. You can use it.
# Import XML. etree. elementtree as etreefrom lxml import etreeimport stringtp = dict () TPS = dict () start_time = dict () end_time = dict () Delay = dict () pkgs = dict () node = dict () cbr_num = dict () dt = 0.2 tree = etree. parse ('qualnet. trace ') print "load success" root = tree. getroot () RECs = root [1]. findall ('rec ') print "traverse REC" for REC in RECs: rechdr = rec. find ('rechdr ') Head = STR (rechdr. text ). split () # print ("head" + rechdr. text) now_time = float (head [2]) # print ("first_time" + first_time) Action = int (STR (rechdr. find ('action '). text ). split () [0]) # print (Action) If action = 2: recbody = rec. find ('recbody') cbrs = recbody. findall ('cbr ') for CBR in cbrs: cbrstr = STR (CBR. text ). split () name = cbrstr [0] size = float (cbrstr [3]) size * = 8 send_time = float (cbrstr [4]) If name not in node: node [name] = head [4] If name not in cbr_num: cbr_num [name] = cbrstr [0] If name not in start_time: start_time [name] = now_time end_time [name] = now_time if name in TP: TP [name] + = size else: TP [name] = size PPS = dict () for I in range (0, INT (250/dt): PPS [I] = 0 TPS [name] = PPS TPS [name] [int (now_time/dt)] + = size if name in delay: delay [name] + = now_time-send_time else: delay [name] = now_time-send_time if name in pkgs: pkgs [name] + = 1 else: pkgs [name] = 1 # print (size) for K in TP: TP [k] = TP [k]/(end_time [k]-start_time [k]) delay [k] = delay [k]/pkgs [k] For m in TPS [k]: TPS [k] [m]/= DT print "% S. % s: % F "% (node [K], cbr_num [K], TP [K], delay [k]) # print TPS [k] f = file (STR (node [k]) + '. '+ cbr_num [K], 'w') for N in TPS [k]: # print> F, "% 10.3f \ n" % (TPs [k] [N]) F. write (STR (TPs [k] [N]) + '\ n') F. close () # print (TP [k]) # print (delay [k]) print tpprint Delay