From nobody Tue Feb 08 16:16:47 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 6536319A58CA; Tue, 8 Feb 2022 16:16:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JtSnX0PfBz3pbZ; Tue, 8 Feb 2022 16:16:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644337008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nkYAHybZGsyj/LP5xoEKoYmJB46Ca754M5Ybli/7zrI=; b=FYoWUAPRLR51KYWSSF3gsPIiOLQo7qV++2zXxT0suOmLD7C2xTD6l0PgU+b5Us3X5JQSy/ /WJ1mUoZ3utls7SUjQmBt+nL0ncL2TicblQRJqBcYArdX66LW4Kk1J159Z8gi0S7lSyNn/ lskyBS71QTH4jlaF4y6T5196nAgzNJ2etAI4xRPwQjvkd1REewqD5ieoN/Qo44aakFi8p0 0RV7dE6e+u+j78fAkeCaQKSVifYTF6DtU5fT9zEkdCahp092rmyuZwQUDz5fYlUkhj1Fbi DFnPArwNDJtAxQ7YEokUiVdSnktHvQPj9qfGC1vgrRKPWAxOPJ0GJZ8M9prbJQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C99211C8E4; Tue, 8 Feb 2022 16:16:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 218GGlad002055; Tue, 8 Feb 2022 16:16:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 218GGluP002054; Tue, 8 Feb 2022 16:16:47 GMT (envelope-from git) Date: Tue, 8 Feb 2022 16:16:47 GMT Message-Id: <202202081616.218GGluP002054@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: b76c31036687 - stable/12 - schedgraph.py: port to Python 3 List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: b76c310366878ff100c86a303bea98cb7664b08d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644337008; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nkYAHybZGsyj/LP5xoEKoYmJB46Ca754M5Ybli/7zrI=; b=MnrVx+yq2aHsZDetsXk/dmZUaYumX5c8umsJe78LJhl+qaKtzZmwYi8HeG8aXHgQv2zNpm STLmh7tFcpWZ1T7f7Bl/wxNJ7Tq9SWHleRsxUy9CxwZfnbKo2II6blsrxFoRSRLJPLciKn 4lJKKL4zNxu8DkRdu9Qz7AZyPRdoshrzB9mD9BewCna4fAoa+Son2W3wQ6MINDtbhMWQ4V HA0+RZwChVA/rbwYqx9AmxFRZMepOsx9wxN1WzMcWL3m7vtb7eIzKScSXg8ujP95vKyFCw hlTTMo5aSPHAS6BOlN8OazbsCP5ZQIfHYxE6KgOVooLDiWK23LdcNfmiuEzslQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644337008; a=rsa-sha256; cv=none; b=wdBvq1/xrkMEv/MT7GANbyVGNWG71z1Keqh3BQCugIj5LD6qXY4iLAalBd9kD7QsTS3/iD hqezok2KXA4bpKykBh7CS9tQEl3Bqsq/Fe73xWI1lyKQAbxxxmwz9TZKLvfjhvLjYgnNgl StMTdSeYQ2JnjwY81Boh4NIXNoetMBgJ+osI+a/WQyumUl1cfNUUPOTxZfAq1jJHt6tFAF JXcfC4tadu/Dd1nPE25RxsRczffDrbnROxGlm9vrjyfC1nCEQjJ2bpUau4G+ePBu/Ui1QZ yyTiCPDaafPmfjmDguIthos393HVtX6ErJv2RxQLHFhtWHhtJYZ5z3lOpZfvDQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=b76c310366878ff100c86a303bea98cb7664b08d commit b76c310366878ff100c86a303bea98cb7664b08d Author: Andriy Gapon AuthorDate: 2022-01-11 13:31:45 +0000 Commit: Andriy Gapon CommitDate: 2022-02-08 16:16:27 +0000 schedgraph.py: port to Python 3 The change does not preserve compatibility with Python 2.7. (cherry picked from commit 7e8ed296e120a57211d377102fa27dd9411d0fbd) --- tools/sched/schedgraph.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tools/sched/schedgraph.py b/tools/sched/schedgraph.py index 6d8a4b9ada14..bfd4339f6633 100644 --- a/tools/sched/schedgraph.py +++ b/tools/sched/schedgraph.py @@ -30,11 +30,13 @@ from __future__ import print_function import sys import re import random -from Tkinter import * +from operator import attrgetter, itemgetter +from functools import total_ordering +from tkinter import * # To use: # - 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. # options KTR # options KTR_ENTRIES=32768 @@ -55,6 +57,8 @@ from Tkinter import * # while the workload is still running is to avoid wasting log entries on # "idle" time at the end. # - 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 # your cpu frequency in ghz: 'python schedgraph.py ktr.out 2.4' # @@ -444,10 +448,6 @@ class SourceConfigure(Toplevel): for item in self.sconfig: item.uncheck() -# 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 @@ -473,7 +473,7 @@ class SourceStats(Toplevel): for k, v in eventtypes.iteritems(): (c, d) = v events.append((k, c, d)) - events.sort(cmp=cmp_counts) + events.sort(key=itemgetter(1), reverse=True) ypos = 0 for event in events: @@ -793,10 +793,8 @@ class PadEvent(StateEvent): Event.draw(self, canvas, xpos, ypos, None) return (xpos + delta) -# Sort function for start y address -def source_cmp_start(x, y): - return x.y - y.y +@total_ordering class EventSource: def __init__(self, group, id): self.name = id @@ -808,12 +806,16 @@ class EventSource: self.hidden = 0 self.tag = group + id - def __cmp__(self, other): - if (other == None): - return -1 - if (self.group == other.group): - return cmp(self.name, other.name) - return cmp(self.group, other.group) + def __lt__(self, other): + if other is None: + return False + return (self.group < other.group or + self.group == other.group and self.name < other.name) + + 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 # at the beginning. As a result, we add events in reverse order @@ -1478,7 +1480,7 @@ class SchedGraph(Frame): # expensive due to python's canvas.move(). # def sourceshowlist(self, srclist): - srclist.sort(cmp=source_cmp_start) + srclist.sort(key=attrgetter('y')) startsize = [] for source in srclist: if (source.hidden == 0): @@ -1486,7 +1488,7 @@ class SchedGraph(Frame): startsize.append((self.sourcepicky(source), self.sourcesize(source))) - sources.sort(cmp=source_cmp_start, reverse=True) + sources.sort(key=attrgetter('y'), reverse=True) self.status.startup("Updating display..."); for source in sources: if (source.hidden == 1): @@ -1516,8 +1518,8 @@ class SchedGraph(Frame): # expensive due to python's canvas.move(). # def sourcehidelist(self, srclist): - srclist.sort(cmp=source_cmp_start) - sources.sort(cmp=source_cmp_start) + srclist.sort(key=attrgetter('y')) + sources.sort(key=attrgetter('y')) startsize = [] off = len(sources) * 100 self.status.startup("Updating display...");