2004-12-26 00:13:07 +00:00
|
|
|
#!/usr/local/bin/python
|
|
|
|
|
2009-01-22 06:21:30 +00:00
|
|
|
# Copyright (c) 2002-2003, 2009, Jeffrey Roberson <jeff@freebsd.org>
|
2004-12-26 00:13:07 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice unmodified, this list of conditions, and the following
|
|
|
|
# disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
2009-01-17 07:24:25 +00:00
|
|
|
import random
|
2004-12-26 00:13:07 +00:00
|
|
|
from Tkinter import *
|
|
|
|
|
2004-12-28 00:49:02 +00:00
|
|
|
# To use:
|
2007-11-19 04:46:37 +00:00
|
|
|
# - Install the ports/x11-toolkits/py-tkinter package; e.g.
|
|
|
|
# portinstall x11-toolkits/py-tkinter package
|
|
|
|
# - Add KTR_SCHED to KTR_COMPILE and KTR_MASK in your KERNCONF; e.g.
|
|
|
|
# options KTR
|
|
|
|
# options KTR_ENTRIES=32768
|
|
|
|
# options KTR_COMPILE=(KTR_SCHED)
|
|
|
|
# options KTR_MASK=(KTR_SCHED)
|
|
|
|
# - It is encouraged to increase KTR_ENTRIES size to gather enough
|
|
|
|
# information for analysis; e.g.
|
|
|
|
# options KTR_ENTRIES=262144
|
2008-01-13 22:46:24 +00:00
|
|
|
# as 32768 entries may only correspond to a second or two of profiling
|
|
|
|
# data depending on your workload.
|
2007-04-22 06:20:12 +00:00
|
|
|
# - Rebuild kernel with proper changes to KERNCONF and boot new kernel.
|
|
|
|
# - Run your workload to be profiled.
|
|
|
|
# - While the workload is continuing (i.e. before it finishes), disable
|
|
|
|
# KTR tracing by setting 'sysctl debug.ktr.mask=0'. This is necessary
|
|
|
|
# to avoid a race condition while running ktrdump, i.e. the KTR ring buffer
|
|
|
|
# will cycle a bit while ktrdump runs, and this confuses schedgraph because
|
|
|
|
# the timestamps appear to go backwards at some point. Stopping KTR logging
|
|
|
|
# while the workload is still running is to avoid wasting log entries on
|
|
|
|
# "idle" time at the end.
|
2004-12-28 00:49:02 +00:00
|
|
|
# - Dump the trace to a file: 'ktrdump -ct > ktr.out'
|
2009-01-17 07:24:25 +00:00
|
|
|
# - Run the python script: 'python schedgraph.py ktr.out' optionally provide
|
|
|
|
# your cpu frequency in ghz: 'python schedgraph.py ktr.out 2.4'
|
2004-12-28 00:49:02 +00:00
|
|
|
#
|
|
|
|
# To do:
|
2009-01-17 07:24:25 +00:00
|
|
|
# Add a per-source summary display
|
|
|
|
# "Vertical rule" to help relate data in different rows
|
|
|
|
# Mouse-over popup of full thread/event/row label (currently truncated)
|
|
|
|
# More visible anchors for popup event windows
|
2007-04-22 06:20:12 +00:00
|
|
|
#
|
|
|
|
# BUGS: 1) Only 8 CPUs are supported, more CPUs require more choices of
|
|
|
|
# colours to represent them ;-)
|
2009-01-17 07:24:25 +00:00
|
|
|
|
|
|
|
eventcolors = [
|
|
|
|
("count", "red"),
|
|
|
|
("running", "green"),
|
|
|
|
("idle", "grey"),
|
|
|
|
("yielding", "yellow"),
|
|
|
|
("swapped", "violet"),
|
|
|
|
("suspended", "purple"),
|
|
|
|
("iwait", "grey"),
|
|
|
|
("sleep", "blue"),
|
|
|
|
("blocked", "dark red"),
|
|
|
|
("runq add", "yellow"),
|
|
|
|
("runq rem", "yellow"),
|
|
|
|
("thread exit", "grey"),
|
|
|
|
("proc exit", "grey"),
|
|
|
|
("callwheel idle", "grey"),
|
|
|
|
("callout running", "green"),
|
|
|
|
("lock acquire", "blue"),
|
|
|
|
("lock contest", "purple"),
|
|
|
|
("failed lock try", "red"),
|
|
|
|
("lock release", "grey"),
|
2009-01-18 05:44:31 +00:00
|
|
|
("statclock", "black"),
|
2009-01-17 07:24:25 +00:00
|
|
|
("prio", "black"),
|
|
|
|
("lend prio", "black"),
|
|
|
|
("wokeup", "black")
|
|
|
|
]
|
|
|
|
|
|
|
|
cpucolors = [
|
|
|
|
("CPU 0", "light grey"),
|
|
|
|
("CPU 1", "dark grey"),
|
|
|
|
("CPU 2", "light blue"),
|
|
|
|
("CPU 3", "light pink"),
|
|
|
|
("CPU 4", "blanched almond"),
|
|
|
|
("CPU 5", "slate grey"),
|
|
|
|
("CPU 6", "tan"),
|
|
|
|
("CPU 7", "thistle"),
|
|
|
|
("CPU 8", "white")
|
|
|
|
]
|
|
|
|
|
|
|
|
colors = [
|
|
|
|
"white", "thistle", "blanched almond", "tan", "chartreuse",
|
|
|
|
"dark red", "red", "pale violet red", "pink", "light pink",
|
|
|
|
"dark orange", "orange", "coral", "light coral",
|
|
|
|
"goldenrod", "gold", "yellow", "light yellow",
|
|
|
|
"dark green", "green", "light green", "light sea green",
|
|
|
|
"dark blue", "blue", "light blue", "steel blue", "light slate blue",
|
|
|
|
"dark violet", "violet", "purple", "blue violet",
|
|
|
|
"dark grey", "slate grey", "light grey",
|
|
|
|
"black",
|
|
|
|
]
|
|
|
|
colors.sort()
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
ticksps = None
|
|
|
|
status = None
|
2009-01-17 07:24:25 +00:00
|
|
|
colormap = None
|
|
|
|
ktrfile = None
|
|
|
|
clockfreq = None
|
|
|
|
sources = []
|
2007-11-19 04:46:37 +00:00
|
|
|
lineno = -1
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-18 05:44:31 +00:00
|
|
|
Y_BORDER = 10
|
|
|
|
X_BORDER = 10
|
|
|
|
Y_COUNTER = 80
|
|
|
|
Y_EVENTSOURCE = 10
|
|
|
|
XY_POINT = 4
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class Colormap:
|
|
|
|
def __init__(self, table):
|
|
|
|
self.table = table
|
|
|
|
self.map = {}
|
|
|
|
for entry in table:
|
|
|
|
self.map[entry[0]] = entry[1]
|
|
|
|
|
|
|
|
def lookup(self, name):
|
|
|
|
try:
|
|
|
|
color = self.map[name]
|
|
|
|
except:
|
|
|
|
color = colors[random.randrange(0, len(colors))]
|
|
|
|
print "Picking random color", color, "for", name
|
|
|
|
self.map[name] = color
|
|
|
|
self.table.append((name, color))
|
|
|
|
return (color)
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def ticks2sec(ticks):
|
2009-01-22 06:21:30 +00:00
|
|
|
ticks = float(ticks)
|
|
|
|
ns = float(ticksps) / 1000000000
|
|
|
|
ticks /= ns
|
2004-12-26 00:13:07 +00:00
|
|
|
if (ticks < 1000):
|
2009-01-22 06:21:30 +00:00
|
|
|
return ("%.2fns" % ticks)
|
2004-12-26 00:13:07 +00:00
|
|
|
ticks /= 1000
|
|
|
|
if (ticks < 1000):
|
2009-01-22 06:21:30 +00:00
|
|
|
return ("%.2fus" % ticks)
|
2004-12-26 00:13:07 +00:00
|
|
|
ticks /= 1000
|
2009-01-22 06:21:30 +00:00
|
|
|
if (ticks < 1000):
|
|
|
|
return ("%.2fms" % ticks)
|
|
|
|
ticks /= 1000
|
|
|
|
return ("%.2fs" % ticks)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
class Scaler(Frame):
|
|
|
|
def __init__(self, master, target):
|
|
|
|
Frame.__init__(self, master)
|
2009-01-20 12:33:04 +00:00
|
|
|
self.scale = None
|
|
|
|
self.target = target
|
2004-12-26 00:13:07 +00:00
|
|
|
self.label = Label(self, text="Ticks per pixel")
|
|
|
|
self.label.pack(side=LEFT)
|
2009-01-20 12:33:04 +00:00
|
|
|
self.resolution = 100
|
|
|
|
self.setmax(10000)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def scaleset(self, value):
|
|
|
|
self.target.scaleset(int(value))
|
|
|
|
|
|
|
|
def set(self, value):
|
|
|
|
self.scale.set(value)
|
|
|
|
|
2009-01-20 12:33:04 +00:00
|
|
|
def setmax(self, value):
|
|
|
|
#
|
|
|
|
# We can't reconfigure the to_ value so we delete the old
|
|
|
|
# window and make a new one when we resize.
|
|
|
|
#
|
|
|
|
if (self.scale != None):
|
|
|
|
self.scale.pack_forget()
|
|
|
|
self.scale.destroy()
|
|
|
|
self.scale = Scale(self, command=self.scaleset,
|
|
|
|
from_=100, to_=value, orient=HORIZONTAL,
|
|
|
|
resolution=self.resolution)
|
|
|
|
self.scale.pack(fill="both", expand=1)
|
|
|
|
self.scale.set(self.target.scaleget())
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
class Status(Frame):
|
|
|
|
def __init__(self, master):
|
|
|
|
Frame.__init__(self, master)
|
|
|
|
self.label = Label(self, bd=1, relief=SUNKEN, anchor=W)
|
|
|
|
self.label.pack(fill="both", expand=1)
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
def set(self, str):
|
|
|
|
self.label.config(text=str)
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
self.label.config(text="")
|
|
|
|
|
|
|
|
def startup(self, str):
|
|
|
|
self.set(str)
|
|
|
|
root.update()
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class ColorConf(Frame):
|
|
|
|
def __init__(self, master, name, color):
|
2004-12-26 00:13:07 +00:00
|
|
|
Frame.__init__(self, master)
|
2009-01-17 07:24:25 +00:00
|
|
|
if (graph.getstate(name) == "hidden"):
|
|
|
|
enabled = 0
|
|
|
|
else:
|
|
|
|
enabled = 1
|
2004-12-26 00:13:07 +00:00
|
|
|
self.name = name
|
|
|
|
self.color = StringVar()
|
|
|
|
self.color_default = color
|
|
|
|
self.color_current = color
|
|
|
|
self.color.set(color)
|
|
|
|
self.enabled = IntVar()
|
|
|
|
self.enabled_default = enabled
|
|
|
|
self.enabled_current = enabled
|
|
|
|
self.enabled.set(enabled)
|
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.label = Label(self, text=self.name, anchor=W)
|
|
|
|
self.sample = Canvas(self, width=24, height=24,
|
|
|
|
bg='grey')
|
|
|
|
self.rect = self.sample.create_rectangle(0, 0, 24, 24,
|
|
|
|
fill=self.color.get())
|
2009-01-17 07:24:25 +00:00
|
|
|
self.list = OptionMenu(self, self.color, command=self.setcolor,
|
|
|
|
*colors)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.checkbox = Checkbutton(self, text="enabled",
|
|
|
|
variable=self.enabled)
|
|
|
|
self.label.grid(row=0, column=0, sticky=E+W)
|
|
|
|
self.sample.grid(row=0, column=1)
|
|
|
|
self.list.grid(row=0, column=2, sticky=E+W)
|
|
|
|
self.checkbox.grid(row=0, column=3)
|
|
|
|
self.columnconfigure(0, weight=1)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.columnconfigure(2, minsize=150)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def setcolor(self, color):
|
|
|
|
self.color.set(color)
|
|
|
|
self.sample.itemconfigure(self.rect, fill=color)
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
cchange = 0
|
|
|
|
echange = 0
|
|
|
|
if (self.color_current != self.color.get()):
|
|
|
|
cchange = 1
|
|
|
|
if (self.enabled_current != self.enabled.get()):
|
|
|
|
echange = 1
|
|
|
|
self.color_current = self.color.get()
|
|
|
|
self.enabled_current = self.enabled.get()
|
|
|
|
if (echange != 0):
|
|
|
|
if (self.enabled_current):
|
|
|
|
graph.setcolor(self.name, self.color_current)
|
|
|
|
else:
|
|
|
|
graph.hide(self.name)
|
|
|
|
return
|
|
|
|
if (cchange != 0):
|
|
|
|
graph.setcolor(self.name, self.color_current)
|
|
|
|
|
|
|
|
def revert(self):
|
|
|
|
self.setcolor(self.color_default)
|
|
|
|
self.enabled.set(self.enabled_default)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class ColorConfigure(Toplevel):
|
|
|
|
def __init__(self, table, name):
|
2004-12-26 00:13:07 +00:00
|
|
|
Toplevel.__init__(self)
|
|
|
|
self.resizable(0, 0)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.title(name)
|
|
|
|
self.items = LabelFrame(self, text="Item Type")
|
2004-12-26 00:13:07 +00:00
|
|
|
self.buttons = Frame(self)
|
|
|
|
self.drawbuttons()
|
|
|
|
self.items.grid(row=0, column=0, sticky=E+W)
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
self.buttons.grid(row=1, column=0, sticky=E+W)
|
|
|
|
self.types = []
|
|
|
|
self.irow = 0
|
2009-01-17 07:24:25 +00:00
|
|
|
for type in table:
|
|
|
|
color = graph.getcolor(type[0])
|
|
|
|
if (color != ""):
|
|
|
|
self.additem(type[0], color)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def additem(self, name, color):
|
|
|
|
item = ColorConf(self.items, name, color)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.types.append(item)
|
|
|
|
item.grid(row=self.irow, column=0, sticky=E+W)
|
|
|
|
self.irow += 1
|
|
|
|
|
|
|
|
def drawbuttons(self):
|
|
|
|
self.apply = Button(self.buttons, text="Apply",
|
|
|
|
command=self.apress)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.default = Button(self.buttons, text="Revert",
|
2004-12-26 00:13:07 +00:00
|
|
|
command=self.rpress)
|
|
|
|
self.apply.grid(row=0, column=0, sticky=E+W)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.default.grid(row=0, column=1, sticky=E+W)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.buttons.columnconfigure(0, weight=1)
|
|
|
|
self.buttons.columnconfigure(1, weight=1)
|
|
|
|
|
|
|
|
def apress(self):
|
|
|
|
for item in self.types:
|
|
|
|
item.apply()
|
|
|
|
|
|
|
|
def rpress(self):
|
|
|
|
for item in self.types:
|
|
|
|
item.revert()
|
|
|
|
|
2009-01-17 11:19:15 +00:00
|
|
|
class SourceConf(Frame):
|
|
|
|
def __init__(self, master, source):
|
|
|
|
Frame.__init__(self, master)
|
|
|
|
if (source.hidden == 1):
|
|
|
|
enabled = 0
|
|
|
|
else:
|
|
|
|
enabled = 1
|
|
|
|
self.source = source
|
|
|
|
self.name = source.name
|
|
|
|
self.enabled = IntVar()
|
|
|
|
self.enabled_default = enabled
|
|
|
|
self.enabled_current = enabled
|
|
|
|
self.enabled.set(enabled)
|
|
|
|
self.draw()
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
self.label = Label(self, text=self.name, anchor=W)
|
|
|
|
self.checkbox = Checkbutton(self, text="enabled",
|
|
|
|
variable=self.enabled)
|
|
|
|
self.label.grid(row=0, column=0, sticky=E+W)
|
|
|
|
self.checkbox.grid(row=0, column=1)
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
|
2009-01-18 04:49:01 +00:00
|
|
|
def changed(self):
|
2009-01-17 11:19:15 +00:00
|
|
|
if (self.enabled_current != self.enabled.get()):
|
2009-01-18 04:49:01 +00:00
|
|
|
return 1
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def apply(self):
|
2009-01-17 11:19:15 +00:00
|
|
|
self.enabled_current = self.enabled.get()
|
|
|
|
|
|
|
|
def revert(self):
|
|
|
|
self.enabled.set(self.enabled_default)
|
|
|
|
|
|
|
|
def check(self):
|
|
|
|
self.enabled.set(1)
|
|
|
|
|
|
|
|
def uncheck(self):
|
|
|
|
self.enabled.set(0)
|
|
|
|
|
|
|
|
class SourceConfigure(Toplevel):
|
|
|
|
def __init__(self):
|
|
|
|
Toplevel.__init__(self)
|
|
|
|
self.resizable(0, 0)
|
|
|
|
self.title("Source Configuration")
|
|
|
|
self.items = []
|
|
|
|
self.iframe = Frame(self)
|
|
|
|
self.iframe.grid(row=0, column=0, sticky=E+W)
|
|
|
|
f = LabelFrame(self.iframe, bd=4, text="Sources")
|
|
|
|
self.items.append(f)
|
|
|
|
self.buttons = Frame(self)
|
|
|
|
self.items[0].grid(row=0, column=0, sticky=E+W)
|
|
|
|
self.columnconfigure(0, weight=1)
|
|
|
|
self.sconfig = []
|
|
|
|
self.irow = 0
|
|
|
|
self.icol = 0
|
|
|
|
for source in sources:
|
|
|
|
self.addsource(source)
|
|
|
|
self.drawbuttons()
|
|
|
|
self.buttons.grid(row=1, column=0, sticky=W)
|
|
|
|
|
|
|
|
def addsource(self, source):
|
|
|
|
if (self.irow > 30):
|
|
|
|
self.icol += 1
|
|
|
|
self.irow = 0
|
|
|
|
c = self.icol
|
|
|
|
f = LabelFrame(self.iframe, bd=4, text="Sources")
|
|
|
|
f.grid(row=0, column=c, sticky=N+E+W)
|
|
|
|
self.items.append(f)
|
|
|
|
item = SourceConf(self.items[self.icol], source)
|
|
|
|
self.sconfig.append(item)
|
|
|
|
item.grid(row=self.irow, column=0, sticky=E+W)
|
|
|
|
self.irow += 1
|
|
|
|
|
|
|
|
def drawbuttons(self):
|
|
|
|
self.apply = Button(self.buttons, text="Apply",
|
|
|
|
command=self.apress)
|
|
|
|
self.default = Button(self.buttons, text="Revert",
|
|
|
|
command=self.rpress)
|
|
|
|
self.checkall = Button(self.buttons, text="Check All",
|
|
|
|
command=self.cpress)
|
|
|
|
self.uncheckall = Button(self.buttons, text="Uncheck All",
|
|
|
|
command=self.upress)
|
|
|
|
self.checkall.grid(row=0, column=0, sticky=W)
|
|
|
|
self.uncheckall.grid(row=0, column=1, sticky=W)
|
|
|
|
self.apply.grid(row=0, column=2, sticky=W)
|
|
|
|
self.default.grid(row=0, column=3, sticky=W)
|
|
|
|
self.buttons.columnconfigure(0, weight=1)
|
|
|
|
self.buttons.columnconfigure(1, weight=1)
|
|
|
|
self.buttons.columnconfigure(2, weight=1)
|
|
|
|
self.buttons.columnconfigure(3, weight=1)
|
|
|
|
|
|
|
|
def apress(self):
|
2009-01-18 04:49:01 +00:00
|
|
|
disable_sources = []
|
|
|
|
enable_sources = []
|
|
|
|
for item in self.sconfig:
|
|
|
|
if (item.changed() == 0):
|
|
|
|
continue
|
|
|
|
if (item.enabled.get() == 1):
|
|
|
|
enable_sources.append(item.source)
|
|
|
|
else:
|
|
|
|
disable_sources.append(item.source)
|
|
|
|
|
|
|
|
if (len(disable_sources)):
|
|
|
|
graph.sourcehidelist(disable_sources)
|
|
|
|
if (len(enable_sources)):
|
|
|
|
graph.sourceshowlist(enable_sources)
|
|
|
|
|
2009-01-17 11:19:15 +00:00
|
|
|
for item in self.sconfig:
|
|
|
|
item.apply()
|
|
|
|
|
|
|
|
def rpress(self):
|
|
|
|
for item in self.sconfig:
|
|
|
|
item.revert()
|
|
|
|
|
|
|
|
def cpress(self):
|
|
|
|
for item in self.sconfig:
|
|
|
|
item.check()
|
|
|
|
|
|
|
|
def upress(self):
|
|
|
|
for item in self.sconfig:
|
|
|
|
item.uncheck()
|
|
|
|
|
2009-01-18 04:49:01 +00:00
|
|
|
# Reverse compare of second member of the tuple
|
|
|
|
def cmp_counts(x, y):
|
|
|
|
return y[1] - x[1]
|
|
|
|
|
|
|
|
class SourceStats(Toplevel):
|
|
|
|
def __init__(self, source):
|
|
|
|
self.source = source
|
|
|
|
Toplevel.__init__(self)
|
|
|
|
self.resizable(0, 0)
|
|
|
|
self.title(source.name + " statistics")
|
|
|
|
self.evframe = LabelFrame(self,
|
2009-01-22 06:21:30 +00:00
|
|
|
text="Event Count, Duration, Avg Duration")
|
2009-01-18 04:49:01 +00:00
|
|
|
self.evframe.grid(row=0, column=0, sticky=E+W)
|
|
|
|
eventtypes={}
|
|
|
|
for event in self.source.events:
|
|
|
|
if (event.type == "pad"):
|
|
|
|
continue
|
|
|
|
duration = event.duration
|
|
|
|
if (eventtypes.has_key(event.name)):
|
|
|
|
(c, d) = eventtypes[event.name]
|
|
|
|
c += 1
|
|
|
|
d += duration
|
|
|
|
eventtypes[event.name] = (c, d)
|
|
|
|
else:
|
|
|
|
eventtypes[event.name] = (1, duration)
|
|
|
|
events = []
|
|
|
|
for k, v in eventtypes.iteritems():
|
|
|
|
(c, d) = v
|
|
|
|
events.append((k, c, d))
|
|
|
|
events.sort(cmp=cmp_counts)
|
|
|
|
|
|
|
|
ypos = 0
|
|
|
|
for event in events:
|
|
|
|
(name, c, d) = event
|
2009-01-22 06:21:30 +00:00
|
|
|
Label(self.evframe, text=name, bd=1,
|
|
|
|
relief=SUNKEN, anchor=W, width=30).grid(
|
|
|
|
row=ypos, column=0, sticky=W+E)
|
|
|
|
Label(self.evframe, text=str(c), bd=1,
|
|
|
|
relief=SUNKEN, anchor=W, width=10).grid(
|
|
|
|
row=ypos, column=1, sticky=W+E)
|
|
|
|
Label(self.evframe, text=ticks2sec(d),
|
|
|
|
bd=1, relief=SUNKEN, width=10).grid(
|
|
|
|
row=ypos, column=2, sticky=W+E)
|
|
|
|
if (d and c):
|
|
|
|
d /= c
|
|
|
|
else:
|
|
|
|
d = 0
|
|
|
|
Label(self.evframe, text=ticks2sec(d),
|
|
|
|
bd=1, relief=SUNKEN, width=10).grid(
|
|
|
|
row=ypos, column=3, sticky=W+E)
|
2009-01-18 04:49:01 +00:00
|
|
|
ypos += 1
|
|
|
|
|
|
|
|
|
|
|
|
class SourceContext(Menu):
|
|
|
|
def __init__(self, event, source):
|
|
|
|
self.source = source
|
|
|
|
Menu.__init__(self, tearoff=0, takefocus=0)
|
|
|
|
self.add_command(label="hide", command=self.hide)
|
|
|
|
self.add_command(label="hide group", command=self.hidegroup)
|
|
|
|
self.add_command(label="stats", command=self.stats)
|
|
|
|
self.tk_popup(event.x_root-3, event.y_root+3)
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
graph.sourcehide(self.source)
|
|
|
|
|
|
|
|
def hidegroup(self):
|
|
|
|
grouplist = []
|
|
|
|
for source in sources:
|
|
|
|
if (source.group == self.source.group):
|
|
|
|
grouplist.append(source)
|
|
|
|
graph.sourcehidelist(grouplist)
|
|
|
|
|
|
|
|
def show(self):
|
|
|
|
graph.sourceshow(self.source)
|
|
|
|
|
|
|
|
def stats(self):
|
|
|
|
SourceStats(self.source)
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
class EventView(Toplevel):
|
|
|
|
def __init__(self, event, canvas):
|
|
|
|
Toplevel.__init__(self)
|
|
|
|
self.resizable(0, 0)
|
|
|
|
self.title("Event")
|
|
|
|
self.event = event
|
|
|
|
self.buttons = Frame(self)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.buttons.grid(row=0, column=0, sticky=E+W)
|
|
|
|
self.frame = Frame(self)
|
|
|
|
self.frame.grid(row=1, column=0, sticky=N+S+E+W)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.canvas = canvas
|
|
|
|
self.drawlabels()
|
|
|
|
self.drawbuttons()
|
|
|
|
event.displayref(canvas)
|
|
|
|
self.bind("<Destroy>", self.destroycb)
|
|
|
|
|
|
|
|
def destroycb(self, event):
|
|
|
|
self.unbind("<Destroy>")
|
|
|
|
if (self.event != None):
|
|
|
|
self.event.displayunref(self.canvas)
|
|
|
|
self.event = None
|
|
|
|
self.destroy()
|
|
|
|
|
|
|
|
def clearlabels(self):
|
|
|
|
for label in self.frame.grid_slaves():
|
|
|
|
label.grid_remove()
|
|
|
|
|
|
|
|
def drawlabels(self):
|
|
|
|
ypos = 0
|
|
|
|
labels = self.event.labels()
|
|
|
|
while (len(labels) < 7):
|
2009-01-17 07:24:25 +00:00
|
|
|
labels.append(("", ""))
|
2004-12-26 00:13:07 +00:00
|
|
|
for label in labels:
|
2009-01-17 07:24:25 +00:00
|
|
|
name, value = label
|
|
|
|
linked = 0
|
|
|
|
if (name == "linkedto"):
|
|
|
|
linked = 1
|
2004-12-26 00:13:07 +00:00
|
|
|
l = Label(self.frame, text=name, bd=1, width=15,
|
|
|
|
relief=SUNKEN, anchor=W)
|
|
|
|
if (linked):
|
|
|
|
fgcolor = "blue"
|
|
|
|
else:
|
|
|
|
fgcolor = "black"
|
|
|
|
r = Label(self.frame, text=value, bd=1,
|
|
|
|
relief=SUNKEN, anchor=W, fg=fgcolor)
|
|
|
|
l.grid(row=ypos, column=0, sticky=E+W)
|
|
|
|
r.grid(row=ypos, column=1, sticky=E+W)
|
|
|
|
if (linked):
|
|
|
|
r.bind("<Button-1>", self.linkpress)
|
|
|
|
ypos += 1
|
|
|
|
self.frame.columnconfigure(1, minsize=80)
|
|
|
|
|
|
|
|
def drawbuttons(self):
|
|
|
|
self.back = Button(self.buttons, text="<", command=self.bpress)
|
|
|
|
self.forw = Button(self.buttons, text=">", command=self.fpress)
|
|
|
|
self.new = Button(self.buttons, text="new", command=self.npress)
|
|
|
|
self.back.grid(row=0, column=0, sticky=E+W)
|
|
|
|
self.forw.grid(row=0, column=1, sticky=E+W)
|
|
|
|
self.new.grid(row=0, column=2, sticky=E+W)
|
|
|
|
self.buttons.columnconfigure(2, weight=1)
|
|
|
|
|
|
|
|
def newevent(self, event):
|
|
|
|
self.event.displayunref(self.canvas)
|
|
|
|
self.clearlabels()
|
|
|
|
self.event = event
|
|
|
|
self.event.displayref(self.canvas)
|
|
|
|
self.drawlabels()
|
|
|
|
|
|
|
|
def npress(self):
|
|
|
|
EventView(self.event, self.canvas)
|
|
|
|
|
|
|
|
def bpress(self):
|
|
|
|
prev = self.event.prev()
|
|
|
|
if (prev == None):
|
|
|
|
return
|
2009-01-17 07:24:25 +00:00
|
|
|
while (prev.type == "pad"):
|
2004-12-26 00:13:07 +00:00
|
|
|
prev = prev.prev()
|
|
|
|
if (prev == None):
|
|
|
|
return
|
|
|
|
self.newevent(prev)
|
|
|
|
|
|
|
|
def fpress(self):
|
|
|
|
next = self.event.next()
|
|
|
|
if (next == None):
|
|
|
|
return
|
2009-01-17 07:24:25 +00:00
|
|
|
while (next.type == "pad"):
|
2004-12-26 00:13:07 +00:00
|
|
|
next = next.next()
|
|
|
|
if (next == None):
|
|
|
|
return
|
|
|
|
self.newevent(next)
|
|
|
|
|
|
|
|
def linkpress(self, wevent):
|
|
|
|
event = self.event.getlinked()
|
|
|
|
if (event != None):
|
|
|
|
self.newevent(event)
|
|
|
|
|
|
|
|
class Event:
|
2009-01-17 07:24:25 +00:00
|
|
|
def __init__(self, source, name, cpu, timestamp, attrs):
|
2004-12-26 00:13:07 +00:00
|
|
|
self.source = source
|
2009-01-17 07:24:25 +00:00
|
|
|
self.name = name
|
2004-12-26 00:13:07 +00:00
|
|
|
self.cpu = cpu
|
|
|
|
self.timestamp = int(timestamp)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.attrs = attrs
|
2004-12-26 00:13:07 +00:00
|
|
|
self.idx = None
|
|
|
|
self.item = None
|
|
|
|
self.dispcnt = 0
|
2009-01-18 04:49:01 +00:00
|
|
|
self.duration = 0
|
2007-11-19 04:46:37 +00:00
|
|
|
self.recno = lineno
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def status(self):
|
|
|
|
statstr = self.name + " " + self.source.name
|
|
|
|
statstr += " on: cpu" + str(self.cpu)
|
|
|
|
statstr += " at: " + str(self.timestamp)
|
2009-01-17 07:24:25 +00:00
|
|
|
statstr += " attributes: "
|
|
|
|
for i in range(0, len(self.attrs)):
|
|
|
|
attr = self.attrs[i]
|
|
|
|
statstr += attr[0] + ": " + str(attr[1])
|
|
|
|
if (i != len(self.attrs) - 1):
|
|
|
|
statstr += ", "
|
2004-12-26 00:13:07 +00:00
|
|
|
status.set(statstr)
|
|
|
|
|
|
|
|
def labels(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
return [("Source", self.source.name),
|
|
|
|
("Event", self.name),
|
|
|
|
("CPU", self.cpu),
|
|
|
|
("Timestamp", self.timestamp),
|
|
|
|
("KTR Line ", self.recno)
|
|
|
|
] + self.attrs
|
|
|
|
|
|
|
|
def mouseenter(self, canvas):
|
2004-12-26 00:13:07 +00:00
|
|
|
self.displayref(canvas)
|
|
|
|
self.status()
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def mouseexit(self, canvas):
|
2004-12-26 00:13:07 +00:00
|
|
|
self.displayunref(canvas)
|
|
|
|
status.clear()
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def mousepress(self, canvas):
|
2004-12-26 00:13:07 +00:00
|
|
|
EventView(self, canvas)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def draw(self, canvas, xpos, ypos, item):
|
|
|
|
self.item = item
|
|
|
|
if (item != None):
|
|
|
|
canvas.items[item] = self
|
|
|
|
|
|
|
|
def move(self, canvas, x, y):
|
|
|
|
if (self.item == None):
|
|
|
|
return;
|
|
|
|
canvas.move(self.item, x, y);
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def next(self):
|
|
|
|
return self.source.eventat(self.idx + 1)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def nexttype(self, type):
|
|
|
|
next = self.next()
|
|
|
|
while (next != None and next.type != type):
|
|
|
|
next = next.next()
|
|
|
|
return (next)
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def prev(self):
|
|
|
|
return self.source.eventat(self.idx - 1)
|
|
|
|
|
|
|
|
def displayref(self, canvas):
|
|
|
|
if (self.dispcnt == 0):
|
|
|
|
canvas.itemconfigure(self.item, width=2)
|
|
|
|
self.dispcnt += 1
|
|
|
|
|
|
|
|
def displayunref(self, canvas):
|
|
|
|
self.dispcnt -= 1
|
|
|
|
if (self.dispcnt == 0):
|
|
|
|
canvas.itemconfigure(self.item, width=0)
|
|
|
|
canvas.tag_raise("point", "state")
|
|
|
|
|
|
|
|
def getlinked(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
for attr in self.attrs:
|
|
|
|
if (attr[0] != "linkedto"):
|
|
|
|
continue
|
|
|
|
source = ktrfile.findid(attr[1])
|
|
|
|
return source.findevent(self.timestamp)
|
|
|
|
return None
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
class PointEvent(Event):
|
2009-01-17 07:24:25 +00:00
|
|
|
type = "point"
|
|
|
|
def __init__(self, source, name, cpu, timestamp, attrs):
|
|
|
|
Event.__init__(self, source, name, cpu, timestamp, attrs)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def draw(self, canvas, xpos, ypos):
|
2009-01-17 07:24:25 +00:00
|
|
|
color = colormap.lookup(self.name)
|
2009-01-18 05:44:31 +00:00
|
|
|
l = canvas.create_oval(xpos - XY_POINT, ypos,
|
|
|
|
xpos + XY_POINT, ypos - (XY_POINT * 2),
|
2009-01-18 04:49:01 +00:00
|
|
|
fill=color, width=0,
|
2009-01-18 05:44:31 +00:00
|
|
|
tags=("event", self.type, self.name, self.source.tag))
|
2009-01-17 07:24:25 +00:00
|
|
|
Event.draw(self, canvas, xpos, ypos, l)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
return xpos
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
class StateEvent(Event):
|
2009-01-17 07:24:25 +00:00
|
|
|
type = "state"
|
|
|
|
def __init__(self, source, name, cpu, timestamp, attrs):
|
|
|
|
Event.__init__(self, source, name, cpu, timestamp, attrs)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def draw(self, canvas, xpos, ypos):
|
2009-01-17 07:24:25 +00:00
|
|
|
next = self.nexttype("state")
|
|
|
|
if (next == None):
|
2004-12-26 00:13:07 +00:00
|
|
|
return (xpos)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.duration = duration = next.timestamp - self.timestamp
|
2009-01-17 07:24:25 +00:00
|
|
|
self.attrs.insert(0, ("duration", ticks2sec(duration)))
|
|
|
|
color = colormap.lookup(self.name)
|
|
|
|
if (duration < 0):
|
|
|
|
duration = 0
|
2007-01-24 21:19:56 +00:00
|
|
|
print "Unsynchronized timestamp"
|
|
|
|
print self.cpu, self.timestamp
|
|
|
|
print next.cpu, next.timestamp
|
2009-01-17 07:24:25 +00:00
|
|
|
delta = duration / canvas.ratio
|
2004-12-26 00:13:07 +00:00
|
|
|
l = canvas.create_rectangle(xpos, ypos,
|
2009-01-17 07:24:25 +00:00
|
|
|
xpos + delta, ypos - 10, fill=color, width=0,
|
2009-01-18 05:44:31 +00:00
|
|
|
tags=("event", self.type, self.name, self.source.tag))
|
2009-01-17 07:24:25 +00:00
|
|
|
Event.draw(self, canvas, xpos, ypos, l)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
return (xpos + delta)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class CountEvent(Event):
|
|
|
|
type = "count"
|
|
|
|
def __init__(self, source, count, cpu, timestamp, attrs):
|
|
|
|
count = int(count)
|
|
|
|
self.count = count
|
|
|
|
Event.__init__(self, source, "count", cpu, timestamp, attrs)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def draw(self, canvas, xpos, ypos):
|
2009-01-17 07:24:25 +00:00
|
|
|
next = self.nexttype("count")
|
|
|
|
if (next == None):
|
|
|
|
return (xpos)
|
|
|
|
color = colormap.lookup("count")
|
2009-01-18 04:49:01 +00:00
|
|
|
self.duration = duration = next.timestamp - self.timestamp
|
2009-01-20 12:33:04 +00:00
|
|
|
if (duration < 0):
|
|
|
|
duration = 0
|
|
|
|
print "Unsynchronized timestamp"
|
|
|
|
print self.cpu, self.timestamp
|
|
|
|
print next.cpu, next.timestamp
|
2009-01-17 07:24:25 +00:00
|
|
|
self.attrs.insert(0, ("count", self.count))
|
|
|
|
self.attrs.insert(1, ("duration", ticks2sec(duration)))
|
|
|
|
delta = duration / canvas.ratio
|
2004-12-26 00:13:07 +00:00
|
|
|
yhight = self.source.yscale() * self.count
|
|
|
|
l = canvas.create_rectangle(xpos, ypos - yhight,
|
2009-01-17 07:24:25 +00:00
|
|
|
xpos + delta, ypos, fill=color, width=0,
|
2009-01-18 05:44:31 +00:00
|
|
|
tags=("event", self.type, self.name, self.source.tag))
|
2009-01-17 07:24:25 +00:00
|
|
|
Event.draw(self, canvas, xpos, ypos, l)
|
2004-12-26 00:13:07 +00:00
|
|
|
return (xpos + delta)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class PadEvent(StateEvent):
|
|
|
|
type = "pad"
|
|
|
|
def __init__(self, source, cpu, timestamp, last=0):
|
|
|
|
if (last):
|
|
|
|
cpu = source.events[len(source.events) -1].cpu
|
|
|
|
else:
|
|
|
|
cpu = source.events[0].cpu
|
|
|
|
StateEvent.__init__(self, source, "pad", cpu, timestamp, [])
|
2004-12-26 00:13:07 +00:00
|
|
|
def draw(self, canvas, xpos, ypos):
|
|
|
|
next = self.next()
|
|
|
|
if (next == None):
|
|
|
|
return (xpos)
|
2009-01-17 07:24:25 +00:00
|
|
|
duration = next.timestamp - self.timestamp
|
|
|
|
delta = duration / canvas.ratio
|
|
|
|
Event.draw(self, canvas, xpos, ypos, None)
|
2004-12-26 00:13:07 +00:00
|
|
|
return (xpos + delta)
|
|
|
|
|
2009-01-18 04:49:01 +00:00
|
|
|
# Sort function for start y address
|
|
|
|
def source_cmp_start(x, y):
|
|
|
|
return x.y - y.y
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
class EventSource:
|
2009-01-17 07:24:25 +00:00
|
|
|
def __init__(self, group, id):
|
|
|
|
self.name = id
|
2004-12-26 00:13:07 +00:00
|
|
|
self.events = []
|
2009-01-17 07:24:25 +00:00
|
|
|
self.cpuitems = []
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.group = group
|
2009-01-17 07:24:25 +00:00
|
|
|
self.y = 0
|
|
|
|
self.item = None
|
2009-01-17 11:19:15 +00:00
|
|
|
self.hidden = 0
|
2009-01-18 04:49:01 +00:00
|
|
|
self.tag = group + id
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
|
|
|
|
def __cmp__(self, other):
|
2009-01-17 07:24:25 +00:00
|
|
|
if (other == None):
|
|
|
|
return -1
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
if (self.group == other.group):
|
2009-01-17 07:24:25 +00:00
|
|
|
return cmp(self.name, other.name)
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
return cmp(self.group, other.group)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
# It is much faster to append items to a list then to insert them
|
|
|
|
# at the beginning. As a result, we add events in reverse order
|
|
|
|
# and then swap the list during fixup.
|
2004-12-26 00:13:07 +00:00
|
|
|
def fixup(self):
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.events.reverse()
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def addevent(self, event):
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.events.append(event)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def addlastevent(self, event):
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.events.insert(0, event)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def draw(self, canvas, ypos):
|
|
|
|
xpos = 10
|
2009-01-17 07:24:25 +00:00
|
|
|
cpux = 10
|
|
|
|
cpu = self.events[1].cpu
|
2004-12-26 00:13:07 +00:00
|
|
|
for i in range(0, len(self.events)):
|
|
|
|
self.events[i].idx = i
|
|
|
|
for event in self.events:
|
2009-01-17 07:24:25 +00:00
|
|
|
if (event.cpu != cpu and event.cpu != -1):
|
|
|
|
self.drawcpu(canvas, cpu, cpux, xpos, ypos)
|
|
|
|
cpux = xpos
|
|
|
|
cpu = event.cpu
|
2004-12-26 00:13:07 +00:00
|
|
|
xpos = event.draw(canvas, xpos, ypos)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.drawcpu(canvas, cpu, cpux, xpos, ypos)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def drawname(self, canvas, ypos):
|
2009-01-17 07:24:25 +00:00
|
|
|
self.y = ypos
|
2004-12-26 00:13:07 +00:00
|
|
|
ypos = ypos - (self.ysize() / 2)
|
2009-01-18 05:44:31 +00:00
|
|
|
self.item = canvas.create_text(X_BORDER, ypos, anchor="w",
|
|
|
|
text=self.name)
|
2009-01-17 07:24:25 +00:00
|
|
|
return (self.item)
|
|
|
|
|
|
|
|
def drawcpu(self, canvas, cpu, fromx, tox, ypos):
|
|
|
|
cpu = "CPU " + str(cpu)
|
|
|
|
color = cpucolormap.lookup(cpu)
|
|
|
|
# Create the cpu background colors default to hidden
|
|
|
|
l = canvas.create_rectangle(fromx,
|
2004-12-26 00:13:07 +00:00
|
|
|
ypos - self.ysize() - canvas.bdheight,
|
2009-01-17 07:24:25 +00:00
|
|
|
tox, ypos + canvas.bdheight, fill=color, width=0,
|
2009-01-18 05:44:31 +00:00
|
|
|
tags=("cpubg", cpu, self.tag), state="hidden")
|
2009-01-17 07:24:25 +00:00
|
|
|
self.cpuitems.append(l)
|
|
|
|
|
|
|
|
def move(self, canvas, xpos, ypos):
|
2009-01-18 04:49:01 +00:00
|
|
|
canvas.move(self.tag, xpos, ypos)
|
2009-01-17 07:24:25 +00:00
|
|
|
|
|
|
|
def movename(self, canvas, xpos, ypos):
|
|
|
|
self.y += ypos
|
|
|
|
canvas.move(self.item, xpos, ypos)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def ysize(self):
|
2009-01-18 05:44:31 +00:00
|
|
|
return (Y_EVENTSOURCE)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def eventat(self, i):
|
|
|
|
if (i >= len(self.events)):
|
|
|
|
return (None)
|
|
|
|
event = self.events[i]
|
|
|
|
return (event)
|
|
|
|
|
|
|
|
def findevent(self, timestamp):
|
|
|
|
for event in self.events:
|
2009-01-17 07:24:25 +00:00
|
|
|
if (event.timestamp >= timestamp and event.type != "pad"):
|
2004-12-26 00:13:07 +00:00
|
|
|
return (event)
|
|
|
|
return (None)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class Counter(EventSource):
|
|
|
|
#
|
|
|
|
# Store a hash of counter groups that keeps the max value
|
|
|
|
# for a counter in this group for scaling purposes.
|
|
|
|
#
|
|
|
|
groups = {}
|
|
|
|
def __init__(self, group, id):
|
2004-12-26 00:13:07 +00:00
|
|
|
try:
|
2009-01-17 07:24:25 +00:00
|
|
|
Counter.cnt = Counter.groups[group]
|
2004-12-26 00:13:07 +00:00
|
|
|
except:
|
2009-01-17 07:24:25 +00:00
|
|
|
Counter.groups[group] = 0
|
|
|
|
EventSource.__init__(self, group, id)
|
2009-01-13 16:44:18 +00:00
|
|
|
|
|
|
|
def fixup(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
for event in self.events:
|
|
|
|
if (event.type != "count"):
|
|
|
|
continue;
|
|
|
|
count = int(event.count)
|
|
|
|
if (count > Counter.groups[self.group]):
|
|
|
|
Counter.groups[self.group] = count
|
2009-01-13 16:44:18 +00:00
|
|
|
EventSource.fixup(self)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2007-11-19 04:46:37 +00:00
|
|
|
def ymax(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
return (Counter.groups[self.group])
|
2007-11-19 04:46:37 +00:00
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def ysize(self):
|
2009-01-18 05:44:31 +00:00
|
|
|
return (Y_COUNTER)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def yscale(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
return (self.ysize() / self.ymax())
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
class KTRFile:
|
|
|
|
def __init__(self, file):
|
2007-01-24 21:19:56 +00:00
|
|
|
self.timestamp_f = None
|
|
|
|
self.timestamp_l = None
|
2009-01-13 16:44:18 +00:00
|
|
|
self.locks = {}
|
|
|
|
self.callwheels = {}
|
2004-12-26 00:13:07 +00:00
|
|
|
self.ticks = {}
|
|
|
|
self.load = {}
|
2005-11-21 21:27:40 +00:00
|
|
|
self.crit = {}
|
2007-01-24 21:19:56 +00:00
|
|
|
self.stathz = 0
|
2009-01-18 05:44:31 +00:00
|
|
|
self.eventcnt = 0
|
2009-01-20 12:33:04 +00:00
|
|
|
self.taghash = {}
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
self.parse(file)
|
|
|
|
self.fixup()
|
|
|
|
global ticksps
|
2007-01-24 21:19:56 +00:00
|
|
|
ticksps = self.ticksps()
|
2009-01-18 05:44:31 +00:00
|
|
|
span = self.timespan()
|
|
|
|
ghz = float(ticksps) / 1000000000.0
|
|
|
|
#
|
|
|
|
# Update the title with some stats from the file
|
|
|
|
#
|
|
|
|
titlestr = "SchedGraph: "
|
|
|
|
titlestr += ticks2sec(span) + " at %.3f ghz, " % ghz
|
|
|
|
titlestr += str(len(sources)) + " event sources, "
|
|
|
|
titlestr += str(self.eventcnt) + " events"
|
|
|
|
root.title(titlestr)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def parse(self, file):
|
|
|
|
try:
|
|
|
|
ifp = open(file)
|
|
|
|
except:
|
|
|
|
print "Can't open", file
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
# quoteexp matches a quoted string, no escaping
|
|
|
|
quoteexp = "\"([^\"]*)\""
|
|
|
|
|
|
|
|
#
|
|
|
|
# commaexp matches a quoted string OR the string up
|
|
|
|
# to the first ','
|
|
|
|
#
|
|
|
|
commaexp = "(?:" + quoteexp + "|([^,]+))"
|
|
|
|
|
|
|
|
#
|
|
|
|
# colonstr matches a quoted string OR the string up
|
|
|
|
# to the first ':'
|
|
|
|
#
|
|
|
|
colonexp = "(?:" + quoteexp + "|([^:]+))"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Match various manditory parts of the KTR string this is
|
|
|
|
# fairly inflexible until you get to attributes to make
|
|
|
|
# parsing faster.
|
|
|
|
#
|
|
|
|
hdrexp = "\s*(\d+)\s+(\d+)\s+(\d+)\s+"
|
|
|
|
groupexp = "KTRGRAPH group:" + quoteexp + ", "
|
|
|
|
idexp = "id:" + quoteexp + ", "
|
|
|
|
typeexp = "([^:]+):" + commaexp + ", "
|
|
|
|
attribexp = "attributes: (.*)"
|
|
|
|
|
|
|
|
#
|
|
|
|
# Matches optional attributes in the KTR string. This
|
|
|
|
# tolerates more variance as the users supply these values.
|
|
|
|
#
|
|
|
|
attrexp = colonexp + "\s*:\s*(?:" + commaexp + ", (.*)|"
|
|
|
|
attrexp += quoteexp +"|(.*))"
|
|
|
|
|
|
|
|
# Precompile regexp
|
|
|
|
ktrre = re.compile(hdrexp + groupexp + idexp + typeexp + attribexp)
|
|
|
|
attrre = re.compile(attrexp)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2007-11-19 04:46:37 +00:00
|
|
|
global lineno
|
|
|
|
lineno = 0
|
2008-04-26 05:02:48 +00:00
|
|
|
for line in ifp.readlines():
|
2007-11-19 04:46:37 +00:00
|
|
|
lineno += 1
|
2009-01-17 07:24:25 +00:00
|
|
|
if ((lineno % 2048) == 0):
|
2007-11-19 04:46:37 +00:00
|
|
|
status.startup("Parsing line " + str(lineno))
|
2009-01-17 07:24:25 +00:00
|
|
|
m = ktrre.match(line);
|
2007-11-12 17:33:07 +00:00
|
|
|
if (m == None):
|
2009-01-17 07:24:25 +00:00
|
|
|
print "Can't parse", lineno, line,
|
|
|
|
continue;
|
|
|
|
(index, cpu, timestamp, group, id, type, dat, dat1, attrstring) = m.groups();
|
|
|
|
if (dat == None):
|
|
|
|
dat = dat1
|
|
|
|
if (self.checkstamp(timestamp) == 0):
|
2009-01-20 12:33:04 +00:00
|
|
|
print "Bad timestamp at", lineno, ":",
|
|
|
|
print cpu, timestamp
|
2009-01-17 07:24:25 +00:00
|
|
|
continue
|
|
|
|
#
|
|
|
|
# Build the table of optional attributes
|
|
|
|
#
|
|
|
|
attrs = []
|
|
|
|
while (attrstring != None):
|
|
|
|
m = attrre.match(attrstring.strip())
|
|
|
|
if (m == None):
|
|
|
|
break;
|
|
|
|
#
|
|
|
|
# Name may or may not be quoted.
|
|
|
|
#
|
|
|
|
# For val we have four cases:
|
|
|
|
# 1) quotes followed by comma and more
|
|
|
|
# attributes.
|
|
|
|
# 2) no quotes followed by comma and more
|
|
|
|
# attributes.
|
|
|
|
# 3) no more attributes or comma with quotes.
|
|
|
|
# 4) no more attributes or comma without quotes.
|
|
|
|
#
|
|
|
|
(name, name1, val, val1, attrstring, end, end1) = m.groups();
|
|
|
|
if (name == None):
|
|
|
|
name = name1
|
|
|
|
if (end == None):
|
|
|
|
end = end1
|
|
|
|
if (val == None):
|
|
|
|
val = val1
|
|
|
|
if (val == None):
|
|
|
|
val = end
|
|
|
|
if (name == "stathz"):
|
|
|
|
self.setstathz(val, cpu)
|
|
|
|
attrs.append((name, val))
|
|
|
|
args = (dat, cpu, timestamp, attrs)
|
|
|
|
e = self.makeevent(group, id, type, args)
|
|
|
|
if (e == None):
|
|
|
|
print "Unknown type", type, lineno, line,
|
|
|
|
|
|
|
|
def makeevent(self, group, id, type, args):
|
|
|
|
e = None
|
|
|
|
source = self.makeid(group, id, type)
|
|
|
|
if (type == "state"):
|
|
|
|
e = StateEvent(source, *args)
|
|
|
|
elif (type == "counter"):
|
|
|
|
e = CountEvent(source, *args)
|
|
|
|
elif (type == "point"):
|
|
|
|
e = PointEvent(source, *args)
|
|
|
|
if (e != None):
|
2009-01-18 05:44:31 +00:00
|
|
|
self.eventcnt += 1
|
2009-01-17 07:24:25 +00:00
|
|
|
source.addevent(e);
|
|
|
|
return e
|
|
|
|
|
|
|
|
def setstathz(self, val, cpu):
|
|
|
|
self.stathz = int(val)
|
|
|
|
cpu = int(cpu)
|
|
|
|
try:
|
|
|
|
ticks = self.ticks[cpu]
|
|
|
|
except:
|
|
|
|
self.ticks[cpu] = 0
|
|
|
|
self.ticks[cpu] += 1
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def checkstamp(self, timestamp):
|
2004-12-26 00:13:07 +00:00
|
|
|
timestamp = int(timestamp)
|
2008-04-26 05:02:48 +00:00
|
|
|
if (self.timestamp_f == None):
|
|
|
|
self.timestamp_f = timestamp;
|
2009-01-20 12:33:04 +00:00
|
|
|
if (self.timestamp_l != None and
|
|
|
|
timestamp -2048> self.timestamp_l):
|
2004-12-26 00:13:07 +00:00
|
|
|
return (0)
|
2008-04-26 05:02:48 +00:00
|
|
|
self.timestamp_l = timestamp;
|
2009-01-17 07:24:25 +00:00
|
|
|
return (1)
|
|
|
|
|
|
|
|
def makeid(self, group, id, type):
|
2009-01-20 12:33:04 +00:00
|
|
|
tag = group + id
|
|
|
|
if (self.taghash.has_key(tag)):
|
|
|
|
return self.taghash[tag]
|
2009-01-17 07:24:25 +00:00
|
|
|
if (type == "counter"):
|
|
|
|
source = Counter(group, id)
|
|
|
|
else:
|
|
|
|
source = EventSource(group, id)
|
|
|
|
sources.append(source)
|
2009-01-20 12:33:04 +00:00
|
|
|
self.taghash[tag] = source
|
2009-01-17 07:24:25 +00:00
|
|
|
return (source)
|
|
|
|
|
|
|
|
def findid(self, id):
|
|
|
|
for source in sources:
|
|
|
|
if (source.name == id):
|
|
|
|
return source
|
|
|
|
return (None)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def timespan(self):
|
2007-01-24 21:19:56 +00:00
|
|
|
return (self.timestamp_f - self.timestamp_l);
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def ticksps(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
oneghz = 1000000000
|
|
|
|
# Use user supplied clock first
|
|
|
|
if (clockfreq != None):
|
|
|
|
return int(clockfreq * oneghz)
|
|
|
|
|
|
|
|
# Check for a discovered clock
|
2009-01-20 12:33:04 +00:00
|
|
|
if (self.stathz != 0):
|
2009-01-17 07:24:25 +00:00
|
|
|
return (self.timespan() / self.ticks[0]) * int(self.stathz)
|
|
|
|
# Pretend we have a 1ns clock
|
|
|
|
print "WARNING: No clock discovered and no frequency ",
|
|
|
|
print "specified via the command line."
|
|
|
|
print "Using fake 1ghz clock"
|
|
|
|
return (oneghz);
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def fixup(self):
|
|
|
|
for source in sources:
|
|
|
|
e = PadEvent(source, -1, self.timestamp_l)
|
|
|
|
source.addevent(e)
|
|
|
|
e = PadEvent(source, -1, self.timestamp_f, last=1)
|
|
|
|
source.addlastevent(e)
|
|
|
|
source.fixup()
|
|
|
|
sources.sort()
|
2009-01-13 16:44:18 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
class SchedNames(Canvas):
|
|
|
|
def __init__(self, master, display):
|
|
|
|
self.display = display
|
|
|
|
self.parent = master
|
|
|
|
self.bdheight = master.bdheight
|
|
|
|
self.items = {}
|
|
|
|
self.ysize = 0
|
|
|
|
self.lines = []
|
|
|
|
Canvas.__init__(self, master, width=120,
|
|
|
|
height=display["height"], bg='grey',
|
|
|
|
scrollregion=(0, 0, 50, 100))
|
|
|
|
|
|
|
|
def moveline(self, cur_y, y):
|
|
|
|
for line in self.lines:
|
|
|
|
(x0, y0, x1, y1) = self.coords(line)
|
|
|
|
if (cur_y != y0):
|
|
|
|
continue
|
|
|
|
self.move(line, 0, y)
|
2009-01-13 16:44:18 +00:00
|
|
|
return
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def draw(self):
|
|
|
|
status.startup("Drawing names")
|
|
|
|
ypos = 0
|
|
|
|
self.configure(scrollregion=(0, 0,
|
|
|
|
self["width"], self.display.ysize()))
|
|
|
|
for source in sources:
|
|
|
|
l = self.create_line(0, ypos, self["width"], ypos,
|
|
|
|
width=1, fill="black", tags=("all","sources"))
|
|
|
|
self.lines.append(l)
|
|
|
|
ypos += self.bdheight
|
|
|
|
ypos += source.ysize()
|
|
|
|
t = source.drawname(self, ypos)
|
|
|
|
self.items[t] = source
|
|
|
|
ypos += self.bdheight
|
|
|
|
self.ysize = ypos
|
|
|
|
self.create_line(0, ypos, self["width"], ypos,
|
|
|
|
width=1, fill="black", tags=("all",))
|
|
|
|
self.bind("<Button-1>", self.master.mousepress);
|
2009-01-18 04:49:01 +00:00
|
|
|
self.bind("<Button-3>", self.master.mousepressright);
|
2009-01-17 07:24:25 +00:00
|
|
|
self.bind("<ButtonRelease-1>", self.master.mouserelease);
|
|
|
|
self.bind("<B1-Motion>", self.master.mousemotion);
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 11:19:15 +00:00
|
|
|
def updatescroll(self):
|
|
|
|
self.configure(scrollregion=(0, 0,
|
|
|
|
self["width"], self.display.ysize()))
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
class SchedDisplay(Canvas):
|
|
|
|
def __init__(self, master):
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.ratio = 1
|
|
|
|
self.parent = master
|
2009-01-17 07:24:25 +00:00
|
|
|
self.bdheight = master.bdheight
|
|
|
|
self.items = {}
|
|
|
|
self.lines = []
|
2004-12-26 00:13:07 +00:00
|
|
|
Canvas.__init__(self, master, width=800, height=500, bg='grey',
|
|
|
|
scrollregion=(0, 0, 800, 500))
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def prepare(self):
|
|
|
|
#
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
# Compute a ratio to ensure that the file's timespan fits into
|
|
|
|
# 2^31. Although python may handle larger values for X
|
|
|
|
# values, the Tk internals do not.
|
2009-01-17 07:24:25 +00:00
|
|
|
#
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.ratio = (ktrfile.timespan() - 1) / 2**31 + 1
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def draw(self):
|
|
|
|
ypos = 0
|
|
|
|
xsize = self.xsize()
|
2009-01-17 07:24:25 +00:00
|
|
|
for source in sources:
|
2004-12-26 00:13:07 +00:00
|
|
|
status.startup("Drawing " + source.name)
|
2009-01-17 07:24:25 +00:00
|
|
|
l = self.create_line(0, ypos, xsize, ypos,
|
2004-12-26 00:13:07 +00:00
|
|
|
width=1, fill="black", tags=("all",))
|
2009-01-17 07:24:25 +00:00
|
|
|
self.lines.append(l)
|
2004-12-26 00:13:07 +00:00
|
|
|
ypos += self.bdheight
|
|
|
|
ypos += source.ysize()
|
|
|
|
source.draw(self, ypos)
|
|
|
|
ypos += self.bdheight
|
2009-01-18 05:44:31 +00:00
|
|
|
self.tag_raise("point", "state")
|
|
|
|
self.tag_lower("cpubg", ALL)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.create_line(0, ypos, xsize, ypos,
|
2009-01-18 05:44:31 +00:00
|
|
|
width=1, fill="black", tags=("lines",))
|
2004-12-26 00:13:07 +00:00
|
|
|
self.tag_bind("event", "<Enter>", self.mouseenter)
|
|
|
|
self.tag_bind("event", "<Leave>", self.mouseexit)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.bind("<Button-1>", self.mousepress)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.bind("<Button-3>", self.master.mousepressright);
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
self.bind("<Button-4>", self.wheelup)
|
|
|
|
self.bind("<Button-5>", self.wheeldown)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.bind("<ButtonRelease-1>", self.master.mouserelease);
|
|
|
|
self.bind("<B1-Motion>", self.master.mousemotion);
|
|
|
|
|
|
|
|
def moveline(self, cur_y, y):
|
|
|
|
for line in self.lines:
|
|
|
|
(x0, y0, x1, y1) = self.coords(line)
|
|
|
|
if (cur_y != y0):
|
|
|
|
continue
|
|
|
|
self.move(line, 0, y)
|
|
|
|
return
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def mouseenter(self, event):
|
|
|
|
item, = self.find_withtag(CURRENT)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.items[item].mouseenter(self)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def mouseexit(self, event):
|
|
|
|
item, = self.find_withtag(CURRENT)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.items[item].mouseexit(self)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def mousepress(self, event):
|
2009-01-17 07:24:25 +00:00
|
|
|
# Find out what's beneath us
|
|
|
|
items = self.find_withtag(CURRENT)
|
|
|
|
if (len(items) == 0):
|
|
|
|
self.master.mousepress(event)
|
|
|
|
return
|
|
|
|
# Only grab mouse presses for things with event tags.
|
|
|
|
item = items[0]
|
|
|
|
tags = self.gettags(item)
|
|
|
|
for tag in tags:
|
|
|
|
if (tag == "event"):
|
|
|
|
self.items[item].mousepress(self)
|
|
|
|
return
|
|
|
|
# Leave the rest to the master window
|
|
|
|
self.master.mousepress(event)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
- Add some rudimentary support for sorting the list of event sources
(threads, CPU load counters, etc.). Each source is tagged with a group
and an order similar to the SYSINIT SI_SUB_* and SI_ORDER_*. After
the file is parsed, all the sources are then sorted. Currently, the only
affects of this are that the CPU loads are now sorted by CPU ID (so
CPU 0 is always first). However, this makes it easier to add new types
of event sources in the future and have them all clustered together
instead of intertwined with threads.
- Python lists perform insertions at the tail much faster than insertions
at the head. For a trace that had a lot of events for a single event
source, the constant insertions of new events to the head of the
per-source event list caused a noticable slow down. To compensate,
append new events to the end of the list during parsing and then
reverse the list prior to drawing.
- Somewhere in the tkinter internals the coordinates of a canvas are
stored in a signed 32-bit integer. As a result, if an the box for
an event spans 2^31, it would actually end up having a negative
X offset at one end. The result was a single box that covered the
entire event source. Kris worked around this for some traces by
bumping up the initial ticks/pixel ratio from 1 to 10. However, a
divisor of 10 can still be too small for large tracefiles (e.g.
with 4 million entries). Instead of hardcoding the initial scaling
ratio, calculate it from the time span of the trace file.
- Add support for using the mouse wheel to scroll the graph window
up and down.
2009-01-13 16:33:10 +00:00
|
|
|
def wheeldown(self, event):
|
|
|
|
self.parent.display_yview("scroll", 1, "units")
|
|
|
|
|
|
|
|
def wheelup(self, event):
|
|
|
|
self.parent.display_yview("scroll", -1, "units")
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def xsize(self):
|
2009-01-18 05:44:31 +00:00
|
|
|
return ((ktrfile.timespan() / self.ratio) + (X_BORDER * 2))
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def ysize(self):
|
|
|
|
ysize = 0
|
2009-01-17 07:24:25 +00:00
|
|
|
for source in sources:
|
2009-01-17 11:19:15 +00:00
|
|
|
if (source.hidden == 1):
|
|
|
|
continue
|
|
|
|
ysize += self.parent.sourcesize(source)
|
2009-01-17 07:24:25 +00:00
|
|
|
return ysize
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def scaleset(self, ratio):
|
2009-01-17 07:24:25 +00:00
|
|
|
if (ktrfile == None):
|
2004-12-26 00:13:07 +00:00
|
|
|
return
|
|
|
|
oldratio = self.ratio
|
2009-01-17 07:24:25 +00:00
|
|
|
xstart, xend = self.xview()
|
|
|
|
midpoint = xstart + ((xend - xstart) / 2)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
self.ratio = ratio
|
2009-01-17 11:19:15 +00:00
|
|
|
self.updatescroll()
|
2009-01-18 05:44:31 +00:00
|
|
|
self.scale(ALL, 0, 0, float(oldratio) / ratio, 1)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
xstart, xend = self.xview()
|
|
|
|
xsize = (xend - xstart) / 2
|
|
|
|
self.xview_moveto(midpoint - xsize)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 11:19:15 +00:00
|
|
|
def updatescroll(self):
|
|
|
|
self.configure(scrollregion=(0, 0, self.xsize(), self.ysize()))
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def scaleget(self):
|
|
|
|
return self.ratio
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def getcolor(self, tag):
|
|
|
|
return self.itemcget(tag, "fill")
|
|
|
|
|
|
|
|
def getstate(self, tag):
|
|
|
|
return self.itemcget(tag, "state")
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def setcolor(self, tag, color):
|
|
|
|
self.itemconfigure(tag, state="normal", fill=color)
|
|
|
|
|
|
|
|
def hide(self, tag):
|
|
|
|
self.itemconfigure(tag, state="hidden")
|
|
|
|
|
|
|
|
class GraphMenu(Frame):
|
|
|
|
def __init__(self, master):
|
|
|
|
Frame.__init__(self, master, bd=2, relief=RAISED)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.conf = Menubutton(self, text="Configure")
|
|
|
|
self.confmenu = Menu(self.conf, tearoff=0)
|
|
|
|
self.confmenu.add_command(label="Event Colors",
|
2004-12-26 00:13:07 +00:00
|
|
|
command=self.econf)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.confmenu.add_command(label="CPU Colors",
|
2009-01-17 07:24:25 +00:00
|
|
|
command=self.cconf)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.confmenu.add_command(label="Source Configure",
|
2009-01-17 11:19:15 +00:00
|
|
|
command=self.sconf)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.conf["menu"] = self.confmenu
|
|
|
|
self.conf.pack(side=LEFT)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
|
|
|
def econf(self):
|
2009-01-17 07:24:25 +00:00
|
|
|
ColorConfigure(eventcolors, "Event Display Configuration")
|
|
|
|
|
|
|
|
def cconf(self):
|
|
|
|
ColorConfigure(cpucolors, "CPU Background Colors")
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 11:19:15 +00:00
|
|
|
def sconf(self):
|
|
|
|
SourceConfigure()
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
class SchedGraph(Frame):
|
|
|
|
def __init__(self, master):
|
|
|
|
Frame.__init__(self, master)
|
|
|
|
self.menu = None
|
|
|
|
self.names = None
|
|
|
|
self.display = None
|
|
|
|
self.scale = None
|
|
|
|
self.status = None
|
2009-01-18 05:44:31 +00:00
|
|
|
self.bdheight = Y_BORDER
|
2009-01-17 07:24:25 +00:00
|
|
|
self.clicksource = None
|
|
|
|
self.lastsource = None
|
2004-12-26 00:13:07 +00:00
|
|
|
self.pack(expand=1, fill="both")
|
|
|
|
self.buildwidgets()
|
|
|
|
self.layout()
|
|
|
|
|
|
|
|
def buildwidgets(self):
|
|
|
|
global status
|
|
|
|
self.menu = GraphMenu(self)
|
|
|
|
self.display = SchedDisplay(self)
|
2009-01-17 07:24:25 +00:00
|
|
|
self.names = SchedNames(self, self.display)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.scale = Scaler(self, self.display)
|
|
|
|
status = self.status = Status(self)
|
|
|
|
self.scrollY = Scrollbar(self, orient="vertical",
|
|
|
|
command=self.display_yview)
|
|
|
|
self.display.scrollX = Scrollbar(self, orient="horizontal",
|
|
|
|
command=self.display.xview)
|
|
|
|
self.display["xscrollcommand"] = self.display.scrollX.set
|
|
|
|
self.display["yscrollcommand"] = self.scrollY.set
|
|
|
|
self.names["yscrollcommand"] = self.scrollY.set
|
|
|
|
|
|
|
|
def layout(self):
|
|
|
|
self.columnconfigure(1, weight=1)
|
|
|
|
self.rowconfigure(1, weight=1)
|
|
|
|
self.menu.grid(row=0, column=0, columnspan=3, sticky=E+W)
|
|
|
|
self.names.grid(row=1, column=0, sticky=N+S)
|
|
|
|
self.display.grid(row=1, column=1, sticky=W+E+N+S)
|
|
|
|
self.scrollY.grid(row=1, column=2, sticky=N+S)
|
|
|
|
self.display.scrollX.grid(row=2, column=0, columnspan=2,
|
|
|
|
sticky=E+W)
|
|
|
|
self.scale.grid(row=3, column=0, columnspan=3, sticky=E+W)
|
|
|
|
self.status.grid(row=4, column=0, columnspan=3, sticky=E+W)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def draw(self):
|
2004-12-26 00:13:07 +00:00
|
|
|
self.master.update()
|
2009-01-17 07:24:25 +00:00
|
|
|
self.display.prepare()
|
|
|
|
self.names.draw()
|
2004-12-26 00:13:07 +00:00
|
|
|
self.display.draw()
|
2009-01-17 07:24:25 +00:00
|
|
|
self.status.startup("")
|
2009-01-20 12:33:04 +00:00
|
|
|
#
|
|
|
|
# Configure scale related values
|
|
|
|
#
|
|
|
|
scalemax = ktrfile.timespan() / int(self.display["width"])
|
|
|
|
width = int(root.geometry().split('x')[0])
|
|
|
|
self.constwidth = width - int(self.display["width"])
|
|
|
|
self.scale.setmax(scalemax)
|
|
|
|
self.scale.set(scalemax)
|
2004-12-26 00:13:07 +00:00
|
|
|
self.display.xview_moveto(0)
|
2009-01-20 12:33:04 +00:00
|
|
|
self.bind("<Configure>", self.resize)
|
2004-12-26 00:13:07 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def mousepress(self, event):
|
|
|
|
self.clicksource = self.sourceat(event.y)
|
|
|
|
|
2009-01-18 04:49:01 +00:00
|
|
|
def mousepressright(self, event):
|
|
|
|
source = self.sourceat(event.y)
|
|
|
|
if (source == None):
|
|
|
|
return
|
|
|
|
SourceContext(event, source)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def mouserelease(self, event):
|
|
|
|
if (self.clicksource == None):
|
|
|
|
return
|
|
|
|
newsource = self.sourceat(event.y)
|
|
|
|
if (self.clicksource != newsource):
|
|
|
|
self.sourceswap(self.clicksource, newsource)
|
|
|
|
self.clicksource = None
|
|
|
|
self.lastsource = None
|
|
|
|
|
|
|
|
def mousemotion(self, event):
|
|
|
|
if (self.clicksource == None):
|
|
|
|
return
|
|
|
|
newsource = self.sourceat(event.y)
|
|
|
|
#
|
|
|
|
# If we get a None source they moved off the page.
|
|
|
|
# swapsource() can't handle moving multiple items so just
|
|
|
|
# pretend we never clicked on anything to begin with so the
|
|
|
|
# user can't mouseover a non-contiguous area.
|
|
|
|
#
|
|
|
|
if (newsource == None):
|
|
|
|
self.clicksource = None
|
|
|
|
self.lastsource = None
|
|
|
|
return
|
|
|
|
if (newsource == self.lastsource):
|
|
|
|
return;
|
|
|
|
self.lastsource = newsource
|
|
|
|
if (newsource != self.clicksource):
|
|
|
|
self.sourceswap(self.clicksource, newsource)
|
|
|
|
|
|
|
|
# These are here because this object controls layout
|
|
|
|
def sourcestart(self, source):
|
|
|
|
return source.y - self.bdheight - source.ysize()
|
|
|
|
|
|
|
|
def sourceend(self, source):
|
|
|
|
return source.y + self.bdheight
|
|
|
|
|
|
|
|
def sourcesize(self, source):
|
|
|
|
return (self.bdheight * 2) + source.ysize()
|
|
|
|
|
|
|
|
def sourceswap(self, source1, source2):
|
|
|
|
# Sort so we always know which one is on top.
|
|
|
|
if (source2.y < source1.y):
|
|
|
|
swap = source1
|
|
|
|
source1 = source2
|
|
|
|
source2 = swap
|
|
|
|
# Only swap adjacent sources
|
|
|
|
if (self.sourceend(source1) != self.sourcestart(source2)):
|
|
|
|
return
|
|
|
|
# Compute start coordinates and target coordinates
|
|
|
|
y1 = self.sourcestart(source1)
|
|
|
|
y2 = self.sourcestart(source2)
|
|
|
|
y1targ = y1 + self.sourcesize(source2)
|
|
|
|
y2targ = y1
|
|
|
|
#
|
|
|
|
# If the sizes are not equal, adjust the start of the lower
|
|
|
|
# source to account for the lost/gained space.
|
|
|
|
#
|
|
|
|
if (source1.ysize() != source2.ysize()):
|
|
|
|
diff = source2.ysize() - source1.ysize()
|
|
|
|
self.names.moveline(y2, diff);
|
|
|
|
self.display.moveline(y2, diff)
|
|
|
|
source1.move(self.display, 0, y1targ - y1)
|
|
|
|
source2.move(self.display, 0, y2targ - y2)
|
|
|
|
source1.movename(self.names, 0, y1targ - y1)
|
|
|
|
source2.movename(self.names, 0, y2targ - y2)
|
|
|
|
|
2009-01-18 04:49:01 +00:00
|
|
|
def sourcepicky(self, source):
|
2009-01-17 11:19:15 +00:00
|
|
|
if (source.hidden == 0):
|
2009-01-18 04:49:01 +00:00
|
|
|
return self.sourcestart(source)
|
|
|
|
# Revert to group based sort
|
|
|
|
sources.sort()
|
2009-01-17 11:19:15 +00:00
|
|
|
prev = None
|
|
|
|
for s in sources:
|
|
|
|
if (s == source):
|
|
|
|
break
|
|
|
|
if (s.hidden == 0):
|
|
|
|
prev = s
|
|
|
|
if (prev == None):
|
|
|
|
newy = 0
|
|
|
|
else:
|
|
|
|
newy = self.sourcestart(prev) + self.sourcesize(prev)
|
2009-01-18 04:49:01 +00:00
|
|
|
return newy
|
|
|
|
|
|
|
|
def sourceshow(self, source):
|
|
|
|
if (source.hidden == 0):
|
|
|
|
return;
|
|
|
|
newy = self.sourcepicky(source)
|
2009-01-17 11:19:15 +00:00
|
|
|
off = newy - self.sourcestart(source)
|
2009-01-18 04:49:01 +00:00
|
|
|
self.sourceshiftall(newy-1, self.sourcesize(source))
|
2009-01-17 11:19:15 +00:00
|
|
|
self.sourceshift(source, off)
|
|
|
|
source.hidden = 0
|
|
|
|
|
2009-01-18 04:49:01 +00:00
|
|
|
#
|
|
|
|
# Optimized source show of multiple entries that only moves each
|
|
|
|
# existing entry once. Doing sourceshow() iteratively is too
|
|
|
|
# expensive due to python's canvas.move().
|
|
|
|
#
|
|
|
|
def sourceshowlist(self, srclist):
|
|
|
|
srclist.sort(cmp=source_cmp_start)
|
|
|
|
startsize = []
|
|
|
|
for source in srclist:
|
|
|
|
if (source.hidden == 0):
|
|
|
|
srclist.remove(source)
|
|
|
|
startsize.append((self.sourcepicky(source),
|
|
|
|
self.sourcesize(source)))
|
|
|
|
|
|
|
|
sources.sort(cmp=source_cmp_start, reverse=True)
|
|
|
|
self.status.startup("Updating display...");
|
|
|
|
for source in sources:
|
|
|
|
if (source.hidden == 1):
|
|
|
|
continue
|
|
|
|
nstart = self.sourcestart(source)
|
|
|
|
size = 0
|
|
|
|
for hidden in startsize:
|
|
|
|
(start, sz) = hidden
|
|
|
|
if (start <= nstart or start+sz <= nstart):
|
|
|
|
size += sz
|
|
|
|
self.sourceshift(source, size)
|
|
|
|
idx = 0
|
|
|
|
size = 0
|
|
|
|
for source in srclist:
|
|
|
|
(newy, sz) = startsize[idx]
|
|
|
|
off = (newy + size) - self.sourcestart(source)
|
|
|
|
self.sourceshift(source, off)
|
|
|
|
source.hidden = 0
|
|
|
|
size += sz
|
|
|
|
idx += 1
|
2009-01-20 12:33:04 +00:00
|
|
|
self.updatescroll()
|
2009-01-18 04:49:01 +00:00
|
|
|
self.status.set("")
|
|
|
|
|
|
|
|
#
|
|
|
|
# Optimized source hide of multiple entries that only moves each
|
|
|
|
# remaining entry once. Doing sourcehide() iteratively is too
|
|
|
|
# expensive due to python's canvas.move().
|
|
|
|
#
|
|
|
|
def sourcehidelist(self, srclist):
|
|
|
|
srclist.sort(cmp=source_cmp_start)
|
|
|
|
sources.sort(cmp=source_cmp_start)
|
|
|
|
startsize = []
|
|
|
|
off = len(sources) * 100
|
|
|
|
self.status.startup("Updating display...");
|
|
|
|
for source in srclist:
|
|
|
|
if (source.hidden == 1):
|
|
|
|
srclist.remove(source)
|
|
|
|
#
|
|
|
|
# Remember our old position so we can sort things
|
|
|
|
# below us when we're done.
|
|
|
|
#
|
|
|
|
startsize.append((self.sourcestart(source),
|
|
|
|
self.sourcesize(source)))
|
|
|
|
self.sourceshift(source, off)
|
|
|
|
source.hidden = 1
|
|
|
|
|
|
|
|
idx = 0
|
|
|
|
size = 0
|
|
|
|
for hidden in startsize:
|
|
|
|
(start, sz) = hidden
|
|
|
|
size += sz
|
|
|
|
if (idx + 1 < len(startsize)):
|
|
|
|
(stop, sz) = startsize[idx+1]
|
|
|
|
else:
|
|
|
|
stop = self.display.ysize()
|
|
|
|
idx += 1
|
|
|
|
for source in sources:
|
|
|
|
nstart = self.sourcestart(source)
|
|
|
|
if (nstart < start or source.hidden == 1):
|
|
|
|
continue
|
|
|
|
if (nstart >= stop):
|
|
|
|
break;
|
|
|
|
self.sourceshift(source, -size)
|
2009-01-20 12:33:04 +00:00
|
|
|
self.updatescroll()
|
2009-01-18 04:49:01 +00:00
|
|
|
self.status.set("")
|
|
|
|
|
2009-01-17 11:19:15 +00:00
|
|
|
def sourcehide(self, source):
|
2009-01-18 04:49:01 +00:00
|
|
|
if (source.hidden == 1):
|
|
|
|
return;
|
2009-01-17 11:19:15 +00:00
|
|
|
# Move it out of the visible area
|
|
|
|
off = len(sources) * 100
|
|
|
|
start = self.sourcestart(source)
|
|
|
|
self.sourceshift(source, off)
|
|
|
|
self.sourceshiftall(start, -self.sourcesize(source))
|
|
|
|
source.hidden = 1
|
|
|
|
|
|
|
|
def sourceshift(self, source, off):
|
|
|
|
start = self.sourcestart(source)
|
|
|
|
source.move(self.display, 0, off)
|
|
|
|
source.movename(self.names, 0, off)
|
|
|
|
self.names.moveline(start, off);
|
|
|
|
self.display.moveline(start, off)
|
2009-01-18 04:49:01 +00:00
|
|
|
#
|
|
|
|
# We update the idle tasks to shrink the dirtied area so
|
|
|
|
# it does not always include the entire screen.
|
|
|
|
#
|
|
|
|
self.names.update_idletasks()
|
|
|
|
self.display.update_idletasks()
|
2009-01-17 11:19:15 +00:00
|
|
|
|
|
|
|
def sourceshiftall(self, start, off):
|
2009-01-18 04:49:01 +00:00
|
|
|
self.status.startup("Updating display...");
|
2009-01-17 11:19:15 +00:00
|
|
|
for source in sources:
|
|
|
|
nstart = self.sourcestart(source)
|
|
|
|
if (nstart < start):
|
|
|
|
continue;
|
|
|
|
self.sourceshift(source, off)
|
2009-01-20 12:33:04 +00:00
|
|
|
self.updatescroll()
|
2009-01-18 04:49:01 +00:00
|
|
|
self.status.set("")
|
2009-01-17 11:19:15 +00:00
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def sourceat(self, ypos):
|
|
|
|
(start, end) = self.names.yview()
|
|
|
|
starty = start * float(self.names.ysize)
|
|
|
|
ypos += starty
|
|
|
|
for source in sources:
|
2009-01-17 11:19:15 +00:00
|
|
|
if (source.hidden == 1):
|
|
|
|
continue;
|
2009-01-17 07:24:25 +00:00
|
|
|
yend = self.sourceend(source)
|
|
|
|
ystart = self.sourcestart(source)
|
|
|
|
if (ypos >= ystart and ypos <= yend):
|
|
|
|
return source
|
|
|
|
return None
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def display_yview(self, *args):
|
|
|
|
self.names.yview(*args)
|
|
|
|
self.display.yview(*args)
|
|
|
|
|
2009-01-20 12:33:04 +00:00
|
|
|
def resize(self, *args):
|
|
|
|
width = int(root.geometry().split('x')[0])
|
|
|
|
scalemax = ktrfile.timespan() / (width - self.constwidth)
|
|
|
|
self.scale.setmax(scalemax)
|
|
|
|
|
|
|
|
def updatescroll(self):
|
|
|
|
self.names.updatescroll()
|
|
|
|
self.display.updatescroll()
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
def setcolor(self, tag, color):
|
|
|
|
self.display.setcolor(tag, color)
|
|
|
|
|
|
|
|
def hide(self, tag):
|
|
|
|
self.display.hide(tag)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
def getcolor(self, tag):
|
|
|
|
return self.display.getcolor(tag)
|
|
|
|
|
|
|
|
def getstate(self, tag):
|
|
|
|
return self.display.getstate(tag)
|
|
|
|
|
|
|
|
if (len(sys.argv) != 2 and len(sys.argv) != 3):
|
|
|
|
print "usage:", sys.argv[0], "<ktr file> [clock freq in ghz]"
|
2004-12-26 00:13:07 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2009-01-17 07:24:25 +00:00
|
|
|
if (len(sys.argv) > 2):
|
|
|
|
clockfreq = float(sys.argv[2])
|
|
|
|
|
2004-12-26 00:13:07 +00:00
|
|
|
root = Tk()
|
2009-01-18 05:44:31 +00:00
|
|
|
root.title("SchedGraph")
|
2009-01-17 07:24:25 +00:00
|
|
|
colormap = Colormap(eventcolors)
|
|
|
|
cpucolormap = Colormap(cpucolors)
|
2004-12-26 00:13:07 +00:00
|
|
|
graph = SchedGraph(root)
|
2009-01-17 07:24:25 +00:00
|
|
|
ktrfile = KTRFile(sys.argv[1])
|
|
|
|
graph.draw()
|
2004-12-26 00:13:07 +00:00
|
|
|
root.mainloop()
|