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

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

script updated

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