OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright 2014 Google Inc. | 3 # Copyright 2014 Google Inc. |
4 # | 4 # |
5 # Use of this source code is governed by a BSD-style license that can be | 5 # Use of this source code is governed by a BSD-style license that can be |
6 # found in the LICENSE file. | 6 # found in the LICENSE file. |
7 | 7 |
8 """Script to test out suitableForGpuRasterization (via gpuveto)""" | 8 """Script to test out suitableForGpuRasterization (via gpuveto)""" |
9 | 9 |
10 import argparse | 10 import argparse |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 output, _ = proc.communicate() | 50 output, _ = proc.communicate() |
51 errcode = proc.returncode | 51 errcode = proc.returncode |
52 return (errcode, output) | 52 return (errcode, output) |
53 | 53 |
54 | 54 |
55 class GpuVeto(object): | 55 class GpuVeto(object): |
56 | 56 |
57 def __init__(self): | 57 def __init__(self): |
58 self.bench_pictures = find_run_binary.find_path_to_program( | 58 self.bench_pictures = find_run_binary.find_path_to_program( |
59 'bench_pictures') | 59 'bench_pictures') |
60 sys.stdout.write('Running: %s\n' % (self.bench_pictures)) | |
60 self.gpuveto = find_run_binary.find_path_to_program('gpuveto') | 61 self.gpuveto = find_run_binary.find_path_to_program('gpuveto') |
61 assert os.path.isfile(self.bench_pictures) | 62 assert os.path.isfile(self.bench_pictures) |
62 assert os.path.isfile(self.gpuveto) | 63 assert os.path.isfile(self.gpuveto) |
64 self.indeterminate = 0 | |
63 self.truePositives = 0 | 65 self.truePositives = 0 |
64 self.falsePositives = 0 | 66 self.falsePositives = 0 |
65 self.trueNegatives = 0 | 67 self.trueNegatives = 0 |
66 self.falseNegatives = 0 | 68 self.falseNegatives = 0 |
67 | 69 |
68 def process_skps(self, dir_or_file): | 70 def process_skps(self, dir_or_file, timer): |
71 if ('c' == timer): | |
72 timer_str = 'CPU' | |
bsalomon
2014/06/18 13:26:25
This is going away, Joe is going to remove the CPU
| |
73 elif ('w' == timer): | |
74 timer_str = 'Wall' | |
75 else: | |
76 sys.stderr.write('Invalid timer parameter. Must be either \'c\' or \ 'w\'\n') | |
77 return | |
78 sys.stdout.write('Using Timer: %s\n' % (timer_str)) | |
79 | |
69 for skp in enumerate(dir_or_file): | 80 for skp in enumerate(dir_or_file): |
70 self.process_skp(skp[1]) | 81 self.process_skp(skp[1], timer) |
71 | 82 |
72 sys.stdout.write('TP %d FP %d TN %d FN %d\n' % (self.truePositives, | 83 sys.stdout.write('TP %d FP %d TN %d FN %d IND %d\n' % (self.truePositive s, |
73 self.falsePositives, | 84 self.falsePositiv es, |
74 self.trueNegatives, | 85 self.trueNegative s, |
75 self.falseNegatives)) | 86 self.falseNegativ es, |
87 self.indeterminat e)) | |
76 | 88 |
77 | 89 |
78 def process_skp(self, skp_file): | 90 def process_skp(self, skp_file, timer): |
79 assert os.path.isfile(skp_file) | 91 assert os.path.isfile(skp_file) |
92 #print skp_file | |
80 | 93 |
81 # run gpuveto on the skp | 94 # run gpuveto on the skp |
82 args = [self.gpuveto, '-r', skp_file] | 95 args = [self.gpuveto, '-r', skp_file] |
83 returncode, output = execute_program(args) | 96 returncode, output = execute_program(args) |
84 if (returncode != 0): | 97 if (returncode != 0): |
85 return | 98 return |
86 | 99 |
87 if ('unsuitable' in output): | 100 if ('unsuitable' in output): |
88 suitable = False | 101 suitable = False |
89 else: | 102 else: |
90 assert 'suitable' in output | 103 assert 'suitable' in output |
91 suitable = True | 104 suitable = True |
92 | 105 |
93 # run raster config | 106 # run raster config |
94 args = [self.bench_pictures, '-r', skp_file, | 107 args = [self.bench_pictures, '-r', skp_file, |
95 '--repeat', '20', | 108 '--repeat', '20', |
109 '--timers', timer, | |
96 '--config', '8888'] | 110 '--config', '8888'] |
97 returncode, output = execute_program(args) | 111 returncode, output = execute_program(args) |
98 if (returncode != 0): | 112 if (returncode != 0): |
99 return | 113 return |
100 | 114 |
101 matches = re.findall('[\d.]+', output) | 115 matches = re.findall('[\d]+\.[\d]+', output) |
102 if len(matches) != 4: | 116 if len(matches) != 1: |
103 return | 117 return |
104 | 118 |
105 rasterTime = float(matches[3]) | 119 rasterTime = float(matches[0]) |
106 | 120 |
107 # run gpu config | 121 # run gpu config |
108 args2 = [self.bench_pictures, '-r', skp_file, | 122 args2 = [self.bench_pictures, '-r', skp_file, |
109 '--repeat', '20', | 123 '--repeat', '20', |
124 '--timers', timer, | |
110 '--config', 'gpu'] | 125 '--config', 'gpu'] |
111 returncode, output = execute_program(args2) | 126 returncode, output = execute_program(args2) |
112 if (returncode != 0): | 127 if (returncode != 0): |
113 return | 128 return |
114 | 129 |
115 matches = re.findall('[\d.]+', output) | 130 matches = re.findall('[\d]+\.[\d]+', output) |
116 if len(matches) != 4: | 131 if len(matches) != 1: |
117 return | 132 return |
118 | 133 |
119 gpuTime = float(matches[3]) | 134 gpuTime = float(matches[0]) |
120 | 135 |
121 sys.stdout.write('%s: gpuveto: %d raster %.2f gpu: %.2f\n' % ( | 136 # happens if page is too big it will not render |
122 skp_file, suitable, rasterTime, gpuTime)) | 137 if 0 == gpuTime: |
138 return | |
123 | 139 |
124 if suitable: | 140 tolerance = 0.05 |
141 tol_range = tolerance * gpuTime | |
142 | |
143 | |
144 if rasterTime > gpuTime - tol_range and rasterTime < gpuTime + tol_range : | |
145 result = "NONE" | |
146 self.indeterminate += 1 | |
147 elif suitable: | |
125 if gpuTime < rasterTime: | 148 if gpuTime < rasterTime: |
126 self.truePositives += 1 | 149 self.truePositives += 1 |
150 result = "TP" | |
127 else: | 151 else: |
128 self.falsePositives += 1 | 152 self.falsePositives += 1 |
153 result = "FP" | |
129 else: | 154 else: |
130 if gpuTime < rasterTime: | 155 if gpuTime < rasterTime: |
131 self.falseNegatives += 1 | 156 self.falseNegatives += 1 |
157 result = "FN" | |
132 else: | 158 else: |
133 self.trueNegatives += 1 | 159 self.trueNegatives += 1 |
160 result = "TN" | |
161 | |
134 | 162 |
163 sys.stdout.write('%s: gpuveto: %d raster %.2f gpu: %.2f Result: %s\n' % ( | |
164 skp_file, suitable, rasterTime, gpuTime, result)) | |
135 | 165 |
136 def main(main_argv): | 166 def main(main_argv): |
137 parser = argparse.ArgumentParser() | 167 parser = argparse.ArgumentParser() |
138 parser.add_argument('--skp_path', | 168 parser.add_argument('--skp_path', |
139 help='Path to the SKP(s). Can either be a directory ' \ | 169 help='Path to the SKP(s). Can either be a directory ' \ |
140 'containing SKPs or a single SKP.', | 170 'containing SKPs or a single SKP.', |
141 required=True) | 171 required=True) |
172 parser.add_argument('--timer', | |
173 help='Timer to use in bench pictures. Can either be \'c\ ' ' \ | |
174 'for cpu timer or \'w\' for wall time. Default = c', | |
175 required=False, default='c') | |
142 | 176 |
143 args = parser.parse_args() | 177 args = parser.parse_args() |
144 GpuVeto().process_skps(list_files(args.skp_path)) | 178 GpuVeto().process_skps(list_files(args.skp_path), args.timer) |
145 | 179 |
146 if __name__ == '__main__': | 180 if __name__ == '__main__': |
147 sys.exit(main(sys.argv[1])) | 181 sys.exit(main(sys.argv[1])) |
OLD | NEW |