schedgraph.py: port to Python 3
The change does not preserve compatibility with Python 2.7. MFC after: 4 weeks Differential Revision: https://reviews.freebsd.org/D33626
This commit is contained in:
parent
776c34f646
commit
7e8ed296e1
@ -30,11 +30,13 @@
|
|||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import random
|
import random
|
||||||
from Tkinter import *
|
from operator import attrgetter, itemgetter
|
||||||
|
from functools import total_ordering
|
||||||
|
from tkinter import *
|
||||||
|
|
||||||
# To use:
|
# To use:
|
||||||
# - Install the ports/x11-toolkits/py-tkinter package; e.g.
|
# - Install the ports/x11-toolkits/py-tkinter package; e.g.
|
||||||
# portinstall x11-toolkits/py-tkinter package
|
# pkg install x11-toolkits/py-tkinter
|
||||||
# - Add KTR_SCHED to KTR_COMPILE and KTR_MASK in your KERNCONF; e.g.
|
# - Add KTR_SCHED to KTR_COMPILE and KTR_MASK in your KERNCONF; e.g.
|
||||||
# options KTR
|
# options KTR
|
||||||
# options KTR_ENTRIES=32768
|
# options KTR_ENTRIES=32768
|
||||||
@ -55,6 +57,8 @@
|
|||||||
# while the workload is still running is to avoid wasting log entries on
|
# while the workload is still running is to avoid wasting log entries on
|
||||||
# "idle" time at the end.
|
# "idle" time at the end.
|
||||||
# - Dump the trace to a file: 'ktrdump -ct > ktr.out'
|
# - Dump the trace to a file: 'ktrdump -ct > ktr.out'
|
||||||
|
# - Alternatively, use schedgraph.d script in this directory for getting
|
||||||
|
# the trace data by means of DTrace. See the script for details.
|
||||||
# - Run the python script: 'python schedgraph.py ktr.out' optionally provide
|
# - Run the python script: 'python schedgraph.py ktr.out' optionally provide
|
||||||
# your cpu frequency in ghz: 'python schedgraph.py ktr.out 2.4'
|
# your cpu frequency in ghz: 'python schedgraph.py ktr.out 2.4'
|
||||||
#
|
#
|
||||||
@ -444,10 +448,6 @@ def upress(self):
|
|||||||
for item in self.sconfig:
|
for item in self.sconfig:
|
||||||
item.uncheck()
|
item.uncheck()
|
||||||
|
|
||||||
# Reverse compare of second member of the tuple
|
|
||||||
def cmp_counts(x, y):
|
|
||||||
return y[1] - x[1]
|
|
||||||
|
|
||||||
class SourceStats(Toplevel):
|
class SourceStats(Toplevel):
|
||||||
def __init__(self, source):
|
def __init__(self, source):
|
||||||
self.source = source
|
self.source = source
|
||||||
@ -473,7 +473,7 @@ def __init__(self, source):
|
|||||||
for k, v in eventtypes.iteritems():
|
for k, v in eventtypes.iteritems():
|
||||||
(c, d) = v
|
(c, d) = v
|
||||||
events.append((k, c, d))
|
events.append((k, c, d))
|
||||||
events.sort(cmp=cmp_counts)
|
events.sort(key=itemgetter(1), reverse=True)
|
||||||
|
|
||||||
ypos = 0
|
ypos = 0
|
||||||
for event in events:
|
for event in events:
|
||||||
@ -793,10 +793,8 @@ def draw(self, canvas, xpos, ypos):
|
|||||||
Event.draw(self, canvas, xpos, ypos, None)
|
Event.draw(self, canvas, xpos, ypos, None)
|
||||||
return (xpos + delta)
|
return (xpos + delta)
|
||||||
|
|
||||||
# Sort function for start y address
|
|
||||||
def source_cmp_start(x, y):
|
|
||||||
return x.y - y.y
|
|
||||||
|
|
||||||
|
@total_ordering
|
||||||
class EventSource:
|
class EventSource:
|
||||||
def __init__(self, group, id):
|
def __init__(self, group, id):
|
||||||
self.name = id
|
self.name = id
|
||||||
@ -808,12 +806,16 @@ def __init__(self, group, id):
|
|||||||
self.hidden = 0
|
self.hidden = 0
|
||||||
self.tag = group + id
|
self.tag = group + id
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __lt__(self, other):
|
||||||
if (other == None):
|
if other is None:
|
||||||
return -1
|
return False
|
||||||
if (self.group == other.group):
|
return (self.group < other.group or
|
||||||
return cmp(self.name, other.name)
|
self.group == other.group and self.name < other.name)
|
||||||
return cmp(self.group, other.group)
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
if other is None:
|
||||||
|
return False
|
||||||
|
return self.group == other.group and self.name == other.name
|
||||||
|
|
||||||
# It is much faster to append items to a list then to insert them
|
# 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
|
# at the beginning. As a result, we add events in reverse order
|
||||||
@ -1478,7 +1480,7 @@ def sourceshow(self, source):
|
|||||||
# expensive due to python's canvas.move().
|
# expensive due to python's canvas.move().
|
||||||
#
|
#
|
||||||
def sourceshowlist(self, srclist):
|
def sourceshowlist(self, srclist):
|
||||||
srclist.sort(cmp=source_cmp_start)
|
srclist.sort(key=attrgetter('y'))
|
||||||
startsize = []
|
startsize = []
|
||||||
for source in srclist:
|
for source in srclist:
|
||||||
if (source.hidden == 0):
|
if (source.hidden == 0):
|
||||||
@ -1486,7 +1488,7 @@ def sourceshowlist(self, srclist):
|
|||||||
startsize.append((self.sourcepicky(source),
|
startsize.append((self.sourcepicky(source),
|
||||||
self.sourcesize(source)))
|
self.sourcesize(source)))
|
||||||
|
|
||||||
sources.sort(cmp=source_cmp_start, reverse=True)
|
sources.sort(key=attrgetter('y'), reverse=True)
|
||||||
self.status.startup("Updating display...");
|
self.status.startup("Updating display...");
|
||||||
for source in sources:
|
for source in sources:
|
||||||
if (source.hidden == 1):
|
if (source.hidden == 1):
|
||||||
@ -1516,8 +1518,8 @@ def sourceshowlist(self, srclist):
|
|||||||
# expensive due to python's canvas.move().
|
# expensive due to python's canvas.move().
|
||||||
#
|
#
|
||||||
def sourcehidelist(self, srclist):
|
def sourcehidelist(self, srclist):
|
||||||
srclist.sort(cmp=source_cmp_start)
|
srclist.sort(key=attrgetter('y'))
|
||||||
sources.sort(cmp=source_cmp_start)
|
sources.sort(key=attrgetter('y'))
|
||||||
startsize = []
|
startsize = []
|
||||||
off = len(sources) * 100
|
off = len(sources) * 100
|
||||||
self.status.startup("Updating display...");
|
self.status.startup("Updating display...");
|
||||||
|
Loading…
Reference in New Issue
Block a user