forked from Themaister/Granite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsweep_stat_analysis.py
executable file
·162 lines (137 loc) · 5.49 KB
/
sweep_stat_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env python3
import sys
import os
import argparse
import json
import copy
def read_stat_file(path):
with open(path, 'r') as f:
json_data = f.read()
parsed = json.loads(json_data)
return parsed
def default_value(key):
if key == 'pcf_width':
return 1
else:
return False
def find_run(stat, config):
keys = [
'renderer',
'msaa',
'prepass',
'clustered',
'hdr_bloom',
'shadows',
'pos_shadows',
'stencil_culling',
'vsm',
'pcf_width'
]
# This run is irrelevant.
if config['renderer'] == 'forward' and not config['clustered']:
return None
for run in stat['runs']:
c = run['config']
equal = True
for key in keys:
compare_value = c[key] if key in c else default_value(key)
config_value = config[key] if key in config else default_value(key)
if compare_value != config_value:
equal = False
break
if equal:
return run
return None
def negative_run(stat, arg, run):
config = copy.deepcopy(run['config'])
if arg == 'renderer':
config[arg] = 'forward'
else:
config[arg] = False
neg_run = find_run(stat, config)
return neg_run
def shadow_type_to_tag(vsm, pcf):
if vsm:
return 'V'
else:
return str(pcf)
def main():
parser = argparse.ArgumentParser(description = 'Script for analyzing difference of changing parameters.')
parser.add_argument('--stat',
help = 'Stat file',
type = str)
parser.add_argument('--config',
help = 'Config option to be analyzed',
type = str)
parser.add_argument('--counter',
help = 'Counter to be analyzed',
type = str,
default = 'avg')
parser.add_argument('--ignore-large-pcf',
help = 'Ignore PCF variants larger than 1.',
action = 'store_true')
args = parser.parse_args()
if args.stat is None:
sys.exit(1)
if args.config is None:
sys.exit(1)
stat = read_stat_file(args.stat)
positive_runs = []
# First, try to find all runs which use our argument.
for run in stat['runs']:
if args.ignore_large_pcf:
if ('pcf_width' in run['config']) and (run['config']['pcf_width'] > 1):
continue
if args.config == 'renderer':
if run['config'][args.config] == 'deferred':
positive_runs.append(run)
else:
if run['config'][args.config]:
positive_runs.append(run)
# Then, find the negatives (or None if a negative does not exist).
negative_runs = [negative_run(stat, args.config, x) for x in positive_runs]
total_positive = 0.0
total_negative = 0.0
gpu_names = '{:<15}'.format('Test')
gpu_names += '{:>25}'.format(stat['runs'][0]['gpu'] + ' Off')
gpu_names += '{:>25}'.format(stat['runs'][0]['gpu'] + ' On')
print(gpu_names)
has_total = False
for i in range(len(positive_runs)):
if negative_runs[i] is None:
continue
c = positive_runs[i]['config']
type_str = ''
type_str += 'F' if c['renderer'] == 'forward' else 'D'
type_str += str(c['msaa'])
type_str += 'Z' if c['prepass'] else 'z'
type_str += 'C' if c['clustered'] else 'c'
type_str += 'S' if c['stencil_culling'] else 's'
type_str += 'H' if c['hdr_bloom'] else 'L'
type_str += 'SS' if c['shadows'] else 'ss'
type_str += 'PS' if c['pos_shadows'] else 'ps'
type_str += shadow_type_to_tag(c['vsm'] if 'vsm' in c else False, c['pcf_width'] if 'pcf_width' in c else 1)
result_string = '{:15}'.format(type_str)
neg_run = negative_runs[i]
pos_run = positive_runs[i]
has_total = True
total_positive += pos_run[args.counter]
total_negative += neg_run[args.counter]
if args.counter == 'avg':
result_string += '{:>25}'.format('{:.3f}'.format(neg_run[args.counter] / 1000.0) + ' ms')
result_string += '{:>25}'.format('{:.3f}'.format(pos_run[args.counter] / 1000.0) + ' ms ' + '({:6.2f} %)'.format(((pos_run[args.counter] - neg_run[args.counter]) / neg_run[args.counter]) * 100.0))
else:
result_string += '{:>25}'.format('{:.3f}'.format(neg_run[args.counter] / 1000000.0) + ' M/frame ')
result_string += '{:>25}'.format('{:.3f}'.format(pos_run[args.counter] / 1000000.0) + ' M/frame ' + '({:6.2f} %)'.format(((pos_run[args.counter] - neg_run[args.counter]) / neg_run[args.counter]) * 100.0))
print(result_string)
if has_total:
result_string = '{:15}'.format('Total')
if args.counter == 'avg':
result_string += '{:>25}'.format('{:.3f}'.format(total_negative / 1000.0) + ' ms')
result_string += '{:>25}'.format('{:.3f}'.format(total_positive / 1000.0) + ' ms ' + '({:6.2f} %)'.format(((total_positive - total_negative) / total_negative) * 100.0))
else:
result_string += '{:>25}'.format('{:.3f}'.format(total_negative / 1000000.0) + ' M/frame ')
result_string += '{:>25}'.format('{:.3f}'.format(total_positive / 1000000.0) + ' M/frame ' + '({:6.2f} %)'.format(((total_positive - total_negative) / total_negative) * 100.0))
print(result_string)
if __name__ == '__main__':
main()