Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d14dca

Browse files
committed
Code formatting
1 parent 94260ff commit 2d14dca

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

specgraph.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ def parse_trace(src, program):
4949
for label, obs_str in zip(trace_lines[1::2], trace_lines[2::2]):
5050
label = int(label)
5151
obs = [o.strip() for o in obs_str.split('\n')]
52-
obs = list(filter(None, obs)) # drop empty obs
52+
obs = list(filter(None, obs)) # drop empty obs
5353
if len(combined_trace_lines) > 0 and combined_trace_lines[-1][0] == label:
54-
combined_trace_lines[-1] = (label, combined_trace_lines[-1][1] + obs) # append obs to last line
54+
# append obs to last line
55+
combined_trace_lines[-1] = (label,
56+
combined_trace_lines[-1][1] + obs)
5557
else:
5658
combined_trace_lines.append((label, obs))
5759

@@ -62,8 +64,10 @@ def parse_trace(src, program):
6264
for label, obs in combined_trace_lines:
6365
def filter_obs(obs, matcher):
6466
return [ob for ob in obs if matcher.match(ob)]
67+
6568
def extract_obs_info(obs, matcher, group):
66-
res = [int(matcher.match(ob).group(group)) for ob in filter_obs(obs, matcher)]
69+
res = [int(matcher.match(ob).group(group))
70+
for ob in filter_obs(obs, matcher)]
6771
return list_without_duplicates(res)
6872

6973
targets = program[label]['targets']
@@ -72,7 +76,7 @@ def extract_obs_info(obs, matcher, group):
7276
if pc_targets:
7377
assert(len(pc_targets) == 1)
7478
to = pc_targets[0]
75-
elif len(targets) == 0: # end
79+
elif len(targets) == 0: # end
7680
to = label
7781
else:
7882
assert(len(targets) == 1)
@@ -177,7 +181,8 @@ def main(inputfile, outputfile, show_inital_final_config):
177181
sys.exit(-3)
178182

179183
graph = Digraph(format='svg')
180-
graph.node_attr.update(style='filled', fontcolor='#4a4a4a', fillcolor='#e6e6e6', color='#4a4a4a')
184+
graph.node_attr.update(style='filled', fontcolor='#4a4a4a',
185+
fillcolor='#e6e6e6', color='#4a4a4a')
181186

182187
# cfg
183188
program = spectector_out['program']
@@ -186,7 +191,8 @@ def main(inputfile, outputfile, show_inital_final_config):
186191
graph.node(str(label), label='{}: {}'.format(label, instr['text']),
187192
shape='doubleoctagon' if is_end else 'rect')
188193
for target in instr['targets']:
189-
graph.edge(str(label), str(target), color='#a2a2a2', penwidth='1.5')
194+
graph.edge(str(label), str(target),
195+
color='#a2a2a2', penwidth='1.5')
190196

191197
# trace
192198
trace = spectector_out['trace']
@@ -195,7 +201,8 @@ def main(inputfile, outputfile, show_inital_final_config):
195201
label='@{}\n{}'.format(entry['t'], '\n'.join(entry['obs'])))
196202

197203
# transactions
198-
transaction_colors = ['#00934a', '#4363d8', '#F96714', '#2A4B7C', '#CE5B78', '#800000', '#797B3A']
204+
transaction_colors = ['#00934a', '#4363d8', '#F96714',
205+
'#2A4B7C', '#CE5B78', '#800000', '#797B3A']
199206
for entry in trace:
200207
for tid in entry['running_transactions']:
201208
color = transaction_colors[tid % len(transaction_colors)]
@@ -209,7 +216,8 @@ def annotate_node_with_config(node_id, conf, draw_on_top=False):
209216
label='mem: {}\nreg: {}'.format(str(conf['m']), str(conf['a'])))
210217
f = conf_node_id if draw_on_top else node_id
211218
t = node_id if draw_on_top else conf_node_id
212-
graph.edge(f, t, color='grey', penwidth='2.0', style='dotted', arrowhead='none')
219+
graph.edge(f, t, color='grey', penwidth='2.0',
220+
style='dotted', arrowhead='none')
213221

214222
if show_inital_final_config:
215223
annotate_node_with_config(
@@ -223,7 +231,8 @@ def annotate_node_with_config(node_id, conf, draw_on_top=False):
223231
if __name__ == '__main__':
224232
def print_help_and_exit():
225233
print('Tool for visualizing Spectector traces.')
226-
print('\nUSAGE:\n {} [-i <inputfile>] -o <outputfile>'.format(sys.argv[0]))
234+
print(
235+
'\nUSAGE:\n {} [-i <inputfile>] -o <outputfile>'.format(sys.argv[0]))
227236
options = [
228237
'-i, --in\tInput text-file containing the output of Spectector (will read from stdin if not set)',
229238
'-o, --out\tOutput file containing the graph (will create SVG- and DOT-files)',

0 commit comments

Comments
 (0)