-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainWindow.py
More file actions
executable file
·153 lines (136 loc) · 5.67 KB
/
Copy pathmainWindow.py
File metadata and controls
executable file
·153 lines (136 loc) · 5.67 KB
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
#!/usr/bin/python
import gtk
import pango
from collections import defaultdict
from appWindow import AppWindow
from flameWindow import FlameWindow
from parse import struct
class MainWindow(AppWindow):
def __init__(self, data, fn):
AppWindow.__init__(self, data.starttime, data.endtime, fn)
self.window.connect("delete_event",gtk.main_quit)
self.window.connect("destroy_event",gtk.main_quit)
self.window.set_title('Runs and Links View [%s]' % fn)
self.data=data
self.boxes=data.boxes
self.links=data.links
self.show_sleeps=False
ts=gtk.ToggleButton('Show Sleeps')
ts.connect('clicked', self.toggle_sleeps)
self.toolbar.add(ts)
self.summary=False
ts=gtk.ToggleButton('Summary View')
ts.connect('clicked', self.toggle_summary)
self.toolbar.add(ts)
self.gcByType['run']=self.gc
self.pick_heights()
self.zoom(None,1)
self.redraw()
self.window.show_all()
def toggle_summary(self, event):
if 'includeInSummary' not in self.__dict__:
self.includeInSummary={}
for p in self.data.procs:
time=0
for r in self.data.runs[p]:
time+=r.end-r.start
self.includeInSummary[p]=(time>(self.data.endtime-self.data.starttime)/300);
self.real_links = self.links
self.fake_links = []
for p in self.data.runs:
if self.includeInSummary[p]:
for r in self.data.runs[p]:
if 'inlink' in r.__dict__ and 'sourcerun' in r.inlink.__dict__:
source=r.inlink.sourcerun
istransfer=r.inlink.istransfer
start=r.inlink.start
while not self.includeInSummary[source.proc]:
if 'inlink' in source.__dict__ and 'sourcerun' in source.inlink.__dict__:
istransfer&=source.inlink.istransfer
start=source.inlink.start
source=source.inlink.sourcerun
else:
source=False
break
if source:
self.fake_links.append(struct(source=source.proc, sourcerun=source, target=p, targetrun=r, start=start, end=r.inlink.end, istransfer=istransfer))
self.summary=not self.summary
if self.summary:
self.links=self.fake_links
else:
self.links=self.real_links
self.pick_heights()
self.content.set_size_request(self.width, self.height)
self.redraw()
self.redraw_time()
def pick_heights(self):
# This whole connectedness thing is just to pick heights that group related processes together
connectedness=defaultdict(lambda:defaultdict(lambda:0))
for p1 in self.data.procs:
prefix1=p1.split('/')[0].split('(')[0]
for p2 in self.data.procs:
prefix2=p2.split('/')[0].split('(')[0]
if prefix1==prefix2:
connectedness[p1][p2]+=20
connectedness[p2][p1]+=20
for l in self.links:
connectedness[l.source][l.target]+=1
connectedness[l.target][l.source]+=1
# Assign heights to processes with a simple greedy algorithm
self.heights={}
h=0
p='swapper/0(0)'
self.rowheight=40
for child in self.legend.get_children():
self.legend.remove(child)
while True:
self.heights[p]=h
button=gtk.Button(label=p)
button.connect('clicked', self.launchFlameWindow, p)
self.legend.pack_start(button, expand=False, fill=False)
bh=button.size_request()[1]
if bh-1<self.rowheight:
self.rowheight=bh-5
h+=bh
bestv=-1
bestp=''
for nextp in self.data.procs:
if nextp in self.heights:
continue
if self.summary and not self.includeInSummary[nextp]:
continue
conn=connectedness[p][nextp]
if conn>bestv:
bestv=conn
bestp=nextp
if bestv==-1: # Nothing left to assign
break
p=bestp
self.height=h
self.legend.show_all()
def toggle_sleeps(self, event):
self.show_sleeps = not self.show_sleeps
self.redraw()
def redraw(self):
self.content.set_size_request(self.width, self.height)
self.pixmap.draw_rectangle(self.white_gc, True, 0, 0, self.width, self.height)
for b in self.boxes:
if b.proc not in self.heights:
continue
h=self.heights[b.proc]
if b.type=='sleep' and not self.show_sleeps:
continue
if 'repframe' in b.__dict__:
text=b.repframe
else:
text=''
self.draw_rectangle(self.gcByType[b.type], b.start, b.end, h, text)
for l in self.links:
if l.source not in self.heights or l.target not in self.heights:
continue
y1=self.heights[l.source]+int(self.rowheight/2)
y2=self.heights[l.target]+int(self.rowheight/2)
self.draw_line(self.red_gc, l.start, y1, l.end, y2)
self.content.queue_draw_area(0, 0, self.width, self.height)
def launchFlameWindow(self, ev, p):
flame=FlameWindow(self.data, p, self.fn)