source: proto/xmlschema/src/perf.py @ 3545

Last change on this file since 3545 was 3545, checked in by shiyangy, 6 years ago

script updated

File size: 4.3 KB
Line 
1from subprocess import call, Popen
2import sys
3from collections import *
4import shiporder_gen
5
6outputpath = 'output'
7redirectoutput= ' 2>&1 | tee '+outputpath+'/output.txt >> perflog.txt'
8
9#To generate a instance file, first two numbers is the range of the number of the element shiporder
10#the last two number is the range of the numbers of each doublelist data content
11#n1 is the total byte of the file
12#n2 is the number of bytes of the doublelist data
13n1,n2 = shiporder_gen.gen(10000,11100,10,12,21,23)
14
15perfin = open("perflog.txt",'r')
16perfout = open("st.txt",'w')
17
18perfout.write('total byte:'+str(n1)+'\n')
19perfout.write('data byte:'+str(n2)+'\n')
20perfout.write('data percetage:'+str(float(n2)/n1)+'\n\n')
21
22def read_log(filename):
23        perfin = open(filename,'r')
24        for i in range(6):
25                line = perfin.readline()
26        ls = line.split(' ')
27#       print ls
28        for i in ls:
29                if len(i) >0 :
30                        break
31        ls2 = i.split(',')
32#       print ls2
33        cycle = 0
34        for j in range(len(ls2)):
35                cycle *= 1000
36                cycle += int(ls2[j])
37#       print cycle
38        line = perfin.readline()
39        ls = line.split(' ')
40        for i in ls:
41                if len(i) >0 :
42                        break
43        ls2 = i.split(',')
44#       print ls2
45        instruction = 0
46        for j in range(len(ls2)):
47                instruction *= 1000
48                instruction += int(ls2[j])
49#       print instruction
50        return cycle,instruction
51
52#read_log("perflog.txt")
53
54def print_st(perfout,cy,ins):
55        perfout.write('cycles:'+str(cy)+'\n')
56        perfout.write('instructions:'+str(ins)+'\n')
57        perfout.write('cycles per byte:'+str(float(cy)/n1)+'\n')
58        perfout.write('instructions per byte:'+str(float(ins)/n1)+'\n')
59        perfout.write('\n\n')
60
61def execute(execution,count):
62        #parabix parsing only
63        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out > ../s.out']
64        p = Popen(cmd,shell=True)
65        p.wait()
66        cy,ins = read_log("perflog.txt")
67        perfout.write('parabix parsing only\n')
68        print_st(perfout,cy,ins)
69        #parsing and symbol table processing
70        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out -s > ../s.out']
71        p = Popen(cmd,shell=True)
72        p.wait()
73        cy,ins = read_log("perflog.txt")
74        perfout.write('symbol table\n')
75        print_st(perfout,cy,ins)
76        #parsing and symbol table processing and datatype validation
77        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out -d > ../s.out']
78        p = Popen(cmd,shell=True)
79        p.wait()
80        cy,ins = read_log("perflog.txt")
81        perfout.write('datatype with symbol table\n')
82        print_st(perfout,cy,ins)
83        #parsing and symbol table processing and content model validation
84        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out -c > ../s.out']
85        p = Popen(cmd,shell=True)
86        p.wait()
87        cy,ins = read_log("perflog.txt")
88        perfout.write('content model with symbol\n')
89        print_st(perfout,cy,ins)
90        #all
91        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out -a > ../s.out']
92        p = Popen(cmd,shell=True)
93        p.wait()
94        cy,ins = read_log("perflog.txt")
95        perfout.write('all\n')
96        print_st(perfout,cy,ins)
97        #for datatype validation, without validation, just gathering
98        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out -g > ../s.out']
99        p = Popen(cmd,shell=True)
100        p.wait()
101        cy,ins = read_log("perflog.txt")
102        perfout.write('datatype without validation, just gathering\n')
103        print_st(perfout,cy,ins)
104        #for content model validation, without validating
105        cmd = ['perf stat -o perflog.txt -e cycles,instructions -r ' +str(count) +' '+ './xmlwf ' + execution.file +' xml.out -v > ../s.out']
106        p = Popen(cmd,shell=True)
107        p.wait()
108        cy,ins = read_log("perflog.txt")
109        perfout.write('content model without validation, just gathering\n')
110        print_st(perfout,cy,ins)
111       
112Execution = namedtuple('Execution',['file'])
113
114execution1 = Execution("shiporder_new.xml")
115
116execute(execution1,10)
117
118element_in = open('element.out','r')
119ls_ele = []
120for line in element_in:
121        ls_ele.append(int(line))
122ls_id = [2,4,9]
123total_ele = 0
124total_val = 0
125for i in range(len(ls_ele)):
126        total_ele += ls_ele[i]
127        if i in ls_id:
128                total_val += ls_ele[i]
129perfout.write('total number of element:'+str(total_ele)+'\n')
130perfout.write('total number of element validated:'+str(total_val)+'\n')
131perfout.write('element validated percetage:'+str(float(total_val)/total_ele)+'\n')
132
133
134print n1
135print n2
136print float(n2)/n1
Note: See TracBrowser for help on using the repository browser.