Skip to content

Commit

Permalink
Add timeline with deciminutes
Browse files Browse the repository at this point in the history
  • Loading branch information
Komzpa committed Apr 11, 2020
1 parent 813065c commit 51abf66
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions make_profiler/dot_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
import datetime
import os
import math
from subprocess import Popen, PIPE

def critical_path(influences, dependencies, inputs, timing):
Expand All @@ -21,6 +22,9 @@ def critical_path(influences, dependencies, inputs, timing):
duration = 1
targets[t]["duration"] = duration
targets[t]["early_end"] = targets[t]["early_start"] + duration
# add timing tag as hour number from very start
targets[t]["timing_tag"] = math.ceil(targets[t]["early_end"]/60/10)
targets[t]["pin_timing_tag"] = True
for z in influences[t]:
update_queue.append(z)
if z not in targets:
Expand All @@ -39,6 +43,9 @@ def critical_path(influences, dependencies, inputs, timing):
targets[t]["late_start"] = targets[t]["late_end"] - targets[t]["duration"]
for d in dependencies.get(t, []):
for z in d:
# don't pin timing tags for dependencies if they're at the same tag
if targets[z]["timing_tag"] == targets[t]["timing_tag"]:
targets[z]["pin_timing_tag"] = False
if z not in update_queue:
update_queue.append(z)
if "late_end" not in targets[z]:
Expand All @@ -47,10 +54,17 @@ def critical_path(influences, dependencies, inputs, timing):
targets[z]["late_end"] = min(targets[t]["late_start"], targets[z]["late_end"])

cp = set()
timing_tags = {}
for t, z in targets.items():
if z["early_start"] == z["late_start"]:
cp.add(t)
return cp
if z["pin_timing_tag"]:
if z["timing_tag"] not in timing_tags:
timing_tags[z["timing_tag"]] = [t]
else:
timing_tags[z["timing_tag"]].append(t)

return cp, timing_tags


def classify_target(name, influences, dependencies, inputs, order_only):
Expand Down Expand Up @@ -86,7 +100,7 @@ def dot_node(name, performance, docstring, cp):
node['URL'] = target_performance['log']
if timing != '0:00:00':
node['label'] += '\\n%s\\r' % timing
node['fontsize'] = min(max(timing_sec ** .5, node['fontsize']), 100)
node['fontsize'] = min(max(timing_sec ** .5, node['fontsize']), 150)
if name in cp:
node['color'] = '#cc0000'
node['group'] = '/'.join(name.split('/')[:2])
Expand All @@ -107,6 +121,7 @@ def export_dot(f, influences, dependencies, order_only, performance, indirect_in
rankdir="BT"
ratio=0.5625
node [shape="box"]
newrank=true
""")
groups = collections.defaultdict(set)

Expand All @@ -116,7 +131,7 @@ def export_dot(f, influences, dependencies, order_only, performance, indirect_in
for t in v:
inputs.discard(t)

cp = critical_path(influences, dependencies, inputs, performance)
cp, timing_tags = critical_path(influences, dependencies, inputs, performance)

# cluster labels
labels = {
Expand All @@ -127,6 +142,8 @@ def export_dot(f, influences, dependencies, order_only, performance, indirect_in
'cluster_tools': 'Tools'
}

hidden_nodes = []

for target, infls in influences.items():
group = classify_target(target, infls, dependencies, inputs, order_only)
groups[group].add(target)
Expand All @@ -135,24 +152,50 @@ def export_dot(f, influences, dependencies, order_only, performance, indirect_in
label = ''
if k in labels:
label = 'label="%s"' % labels[k]

nodes = [dot_node(t, performance, docs.get(t, t), cp) for t in v]
nodes.append('\"%s_DUMMY\" [shape=point style=invis]' % k)
if k == 'cluster_result':
nodes.append('rank=sink;')
#if k == 'cluster_inputs':
#nodes.append('rank=source;')
if k == 'cluster_tools':
nodes.append('rank=source;')
if k == 'cluster_order_only':
hidden_nodes = v
continue

nodes.append('style=invis;')


f.write('subgraph "%s" { %s graph[style=dotted] %s }\n' % (k, label, ';\n'.join(nodes)))

for k, v in influences.items():
for t in sorted(v):
if t in indirect_influences[k]:
f.write('"%s" -> "%s" [color="#00000033",weight="0",style="dashed"];\n' % (k, t))
elif k in cp and t in cp:
f.write('"%s" -> "%s" [color="#cc0000",weight="3",penwidth="3",headclip="true"];\n' % (k, t))
f.write('"%s" -> "%s" [color="#cc0000",weight="10",penwidth="3",headclip="true"];\n' % (k, t))
else:
f.write('"%s" -> "%s";\n' % (k, t))

f.write('cluster_inputs_DUMMY -> cluster_tools_DUMMY -> cluster_result_DUMMY [ style=invis ];')

if 'cluster_not_implemented' in groups:
f.write('cluster_inputs_DUMMY -> cluster_not_implemented_DUMMY -> cluster_tools_DUMMY [ style=invis ];')
f.write('cluster_result_DUMMY -> cluster_not_implemented_DUMMY -> cluster_order_only_DUMMY [ style=invis ];')
f.write('cluster_not_implemented_DUMMY -> cluster_order_only_DUMMY [ style=invis ];')

def format_deciminutes(k):
hrs = math.floor(k / 6)
min = (k %6)*10
return '%s:%02d'%(hrs,min)

for k,v in timing_tags.items():
f.write('{ rank=same; ' + '%s [label="%s"]'%(k,format_deciminutes(k)) + ' [fontsize=50];' + ';'.join(['"%s"' % t for t in v if t not in hidden_nodes]) + '}')
tags = sorted(timing_tags.keys())

f.write('->'.join([ '%s' % k for k in tags]))

f.write('}')


Expand Down

0 comments on commit 51abf66

Please sign in to comment.