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): |
69 for skp in enumerate(dir_or_file): | 71 for skp in enumerate(dir_or_file): |
70 self.process_skp(skp[1]) | 72 self.process_skp(skp[1]) |
71 | 73 |
72 sys.stdout.write('TP %d FP %d TN %d FN %d\n' % (self.truePositives, | 74 sys.stdout.write('TP %d FP %d TN %d FN %d IND %d\n' % (self.truePositive
s, |
73 self.falsePositives, | 75 self.falsePositiv
es, |
74 self.trueNegatives, | 76 self.trueNegative
s, |
75 self.falseNegatives)) | 77 self.falseNegativ
es, |
| 78 self.indeterminat
e)) |
76 | 79 |
77 | 80 |
78 def process_skp(self, skp_file): | 81 def process_skp(self, skp_file): |
79 assert os.path.isfile(skp_file) | 82 assert os.path.isfile(skp_file) |
| 83 #print skp_file |
80 | 84 |
81 # run gpuveto on the skp | 85 # run gpuveto on the skp |
82 args = [self.gpuveto, '-r', skp_file] | 86 args = [self.gpuveto, '-r', skp_file] |
83 returncode, output = execute_program(args) | 87 returncode, output = execute_program(args) |
84 if (returncode != 0): | 88 if (returncode != 0): |
85 return | 89 return |
86 | 90 |
87 if ('unsuitable' in output): | 91 if ('unsuitable' in output): |
88 suitable = False | 92 suitable = False |
89 else: | 93 else: |
90 assert 'suitable' in output | 94 assert 'suitable' in output |
91 suitable = True | 95 suitable = True |
92 | 96 |
93 # run raster config | 97 # run raster config |
94 args = [self.bench_pictures, '-r', skp_file, | 98 args = [self.bench_pictures, '-r', skp_file, |
95 '--repeat', '20', | 99 '--repeat', '20', |
| 100 '--timers', 'w', |
96 '--config', '8888'] | 101 '--config', '8888'] |
97 returncode, output = execute_program(args) | 102 returncode, output = execute_program(args) |
98 if (returncode != 0): | 103 if (returncode != 0): |
99 return | 104 return |
100 | 105 |
101 matches = re.findall('[\d.]+', output) | 106 matches = re.findall('[\d]+\.[\d]+', output) |
102 if len(matches) != 4: | 107 if len(matches) != 1: |
103 return | 108 return |
104 | 109 |
105 rasterTime = float(matches[3]) | 110 rasterTime = float(matches[0]) |
106 | 111 |
107 # run gpu config | 112 # run gpu config |
108 args2 = [self.bench_pictures, '-r', skp_file, | 113 args2 = [self.bench_pictures, '-r', skp_file, |
109 '--repeat', '20', | 114 '--repeat', '20', |
| 115 '--timers', 'w', |
110 '--config', 'gpu'] | 116 '--config', 'gpu'] |
111 returncode, output = execute_program(args2) | 117 returncode, output = execute_program(args2) |
112 if (returncode != 0): | 118 if (returncode != 0): |
113 return | 119 return |
114 | 120 |
115 matches = re.findall('[\d.]+', output) | 121 matches = re.findall('[\d]+\.[\d]+', output) |
116 if len(matches) != 4: | 122 if len(matches) != 1: |
117 return | 123 return |
118 | 124 |
119 gpuTime = float(matches[3]) | 125 gpuTime = float(matches[0]) |
120 | 126 |
121 sys.stdout.write('%s: gpuveto: %d raster %.2f gpu: %.2f\n' % ( | 127 # happens if page is too big it will not render |
122 skp_file, suitable, rasterTime, gpuTime)) | 128 if 0 == gpuTime: |
| 129 return |
123 | 130 |
124 if suitable: | 131 tolerance = 0.05 |
| 132 tol_range = tolerance * gpuTime |
| 133 |
| 134 |
| 135 if rasterTime > gpuTime - tol_range and rasterTime < gpuTime + tol_range
: |
| 136 result = "NONE" |
| 137 self.indeterminate += 1 |
| 138 elif suitable: |
125 if gpuTime < rasterTime: | 139 if gpuTime < rasterTime: |
126 self.truePositives += 1 | 140 self.truePositives += 1 |
| 141 result = "TP" |
127 else: | 142 else: |
128 self.falsePositives += 1 | 143 self.falsePositives += 1 |
| 144 result = "FP" |
129 else: | 145 else: |
130 if gpuTime < rasterTime: | 146 if gpuTime < rasterTime: |
131 self.falseNegatives += 1 | 147 self.falseNegatives += 1 |
| 148 result = "FN" |
132 else: | 149 else: |
133 self.trueNegatives += 1 | 150 self.trueNegatives += 1 |
| 151 result = "TN" |
| 152 |
134 | 153 |
| 154 sys.stdout.write('%s: gpuveto: %d raster %.2f gpu: %.2f Result: %s\n' %
( |
| 155 skp_file, suitable, rasterTime, gpuTime, result)) |
135 | 156 |
136 def main(main_argv): | 157 def main(main_argv): |
137 parser = argparse.ArgumentParser() | 158 parser = argparse.ArgumentParser() |
138 parser.add_argument('--skp_path', | 159 parser.add_argument('--skp_path', |
139 help='Path to the SKP(s). Can either be a directory ' \ | 160 help='Path to the SKP(s). Can either be a directory ' \ |
140 'containing SKPs or a single SKP.', | 161 'containing SKPs or a single SKP.', |
141 required=True) | 162 required=True) |
142 | 163 |
143 args = parser.parse_args() | 164 args = parser.parse_args() |
144 GpuVeto().process_skps(list_files(args.skp_path)) | 165 GpuVeto().process_skps(list_files(args.skp_path)) |
145 | 166 |
146 if __name__ == '__main__': | 167 if __name__ == '__main__': |
147 sys.exit(main(sys.argv[1])) | 168 sys.exit(main(sys.argv[1])) |
OLD | NEW |