Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1345775rwb; Thu, 1 Dec 2022 16:17:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WR/OTa2DFncRantlcXDqDEZ9zSq+IJe19dPDeEIHznEGQnhHxnUDc7orPXYs5aP1rH0PL X-Received: by 2002:a17:90b:609:b0:219:3ad9:64f5 with SMTP id gb9-20020a17090b060900b002193ad964f5mr23365206pjb.138.1669940246343; Thu, 01 Dec 2022 16:17:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669940246; cv=none; d=google.com; s=arc-20160816; b=X5jGpYzuPf9hMCBFk0xpI+4r9XmRq1UPFSZQCvtd8XCJLHGQPn8cDAw60U+Ottn0pl 50Bg2VZrgZ49m3DBWWd8xKdLSJaDmtuaP4g0VcXtZMEV+LpjQdghAcOMSOrZcP15lPL5 QS8OilO74dUpZc3DY5whhsgi5VVjE5bhLIv9VnQQ/usriM18lHLbiIjcFP/4wUe3pwv4 1HV1YoeecwmkwKBjPGp3uS548rHGFEd3diZKCFsXAd1xDHzhoCqVJt5KE2VhmH5ngMhe DgFyX6i6MB0p6DBbueVfRu47XubjalakLh1fGQgGnc+TXn1maLp3c2H7tSeHBzLblEgw eijA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wI/EJc3uSkptXQMEeWu/DfSWa/8ogFJrF+6WTf8nAZA=; b=0QO1IX/NGDFyH4YIlF4yWJ+NkhrY3tAYCVTidWCxkQWKKgHWPEW6UxwVNIEkcY/2ah N0p8yuLVO/yCfSXYdZzqyy1TLfFyURv99sNztHtk5oSPjslWgDhwwwvJP+R61kfP5hlO E9ayroRVmhNX83KTe5gZXmByZ9+l48ObZPMAfJS9nQZ32xTZgsLP3nIx4av/pRbavYET IYjURP9m9tm/obo9yRn3nZpsKwzuiqsu+aldqBuiBzm2zi5dLnnfqIlRJLRSuTwfBK1y wCdpjcqLKznzzV1OfiAB2UgGZD+LKOClLBL3soquBwDMaMvZRKmJDohreP82XyqGGqm1 qNKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XgIEZIoB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 199-20020a6302d0000000b0047776c01d71si6177636pgc.375.2022.12.01.16.17.15; Thu, 01 Dec 2022 16:17:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XgIEZIoB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbiLBAFe (ORCPT + 82 others); Thu, 1 Dec 2022 19:05:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbiLBAFc (ORCPT ); Thu, 1 Dec 2022 19:05:32 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70E99C5127 for ; Thu, 1 Dec 2022 16:05:29 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id bs21so5437424wrb.4 for ; Thu, 01 Dec 2022 16:05:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wI/EJc3uSkptXQMEeWu/DfSWa/8ogFJrF+6WTf8nAZA=; b=XgIEZIoBM4Id4mPBUa9pPE/skgI/V82r8fMSES3z2mreZKmAA/RFZGs/PN8uK2WqVh OqnwjfwSjrkDfuEqpyeLA7SFxq69vdYnnGiuYKZVq6uxqPRn3DJB0uZQzlrMHw0QHlvO ze3Xa4Fs0ggmuEBnAGqqxAT1FJMkfF0XwDYm8Y1q9hHiL34rifbndFxxSy0MCYB0diWj zuWBpe/L5iCIFSwe5deY3UZXvj/T1QQwBX8gEjiwFvMTh1XmvIJoXjOLoq6+1yUBFchb kYruGqMM4lLhZ1/YApNpFc7YeUffA6JPcx+rQo+z/V5mudF/Y29foXOW7i7y4n/km7yy oofA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wI/EJc3uSkptXQMEeWu/DfSWa/8ogFJrF+6WTf8nAZA=; b=yTuyg474lcK6uR3j9CGgF4g+4d2UdbMmN2oGRJta0SYYgFFScVVyhcsDrY4gNTkoDr USLP/R27o2ol4ZAxvOuBGCeA7Ngp8X60s4dLUgg93TTykuuKJ+NcTVrMifm5+cbrWqC7 13MpRpr2KafhxmhdGMf7HrlGqASQ1xR3qLFd8+3CJQFZgm2qV3724Csa1acF+8+8ssRH crVPgRkN5PLfem9hpC4JcqKYeRfq0NG9JMNJYw9Vmi87tNTt0Wry704EmFUUJhPfJ5z1 fyuw+Y4qLls79IhDyjLCYED4ldhVzvVGB10nA3vEoPGyo66IwgrVIthK9ofUv3KlzwdH 4N/g== X-Gm-Message-State: ANoB5pk3iYkyr0LTR5Khux72fyDZv/uA7ZpBBibaiLFuL0gi5UNB2cf1 7Tjg06ss2rfn4zKABSF7oCUtIUN2jV2hoTGzNC53NA== X-Received: by 2002:adf:f944:0:b0:236:8f54:f1f4 with SMTP id q4-20020adff944000000b002368f54f1f4mr42766519wrr.654.1669939527415; Thu, 01 Dec 2022 16:05:27 -0800 (PST) MIME-Version: 1.0 References: <20221201193557.65548-1-petar.gligor@gmail.com> <20221201193557.65548-2-petar.gligor@gmail.com> In-Reply-To: <20221201193557.65548-2-petar.gligor@gmail.com> From: Ian Rogers Date: Thu, 1 Dec 2022 16:05:15 -0800 Message-ID: Subject: Re: [PATCH 1/2] perf script: introduce task analyzer To: Petar Gligoric Cc: linux-kernel@vger.kernel.org, Hagen Paul Pfeifer , Petar Gligoric , Arnaldo Carvalho de Melo , Andi Kleen , Jiri Olsa , Namhyung Kim Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 1, 2022 at 11:36 AM Petar Gligoric wrote: > > From: Hagen Paul Pfeifer > > Introduce a new perf script to analyze task scheduling behavior. > > During the task analysis, some data is always needed - which goes beyond the > simple time of switching on and off a task (process/thread). This concerns for > example the runtime of a process or the frequency with which the process was > called. This script serves to simplify this recurring analyze process. It > immediately provides the user with helpful task characteristic information > about the tasks runtimes. > > Usage: > > Recorded can be in two ways: > $ perf script record tasks-analyzer -- sleep 10 > $ perf record -e sched:sched_switch -a -- sleep 10 > > The script can parse all perf.data files, most important: sched:sched_switch > events are mandatory, other events will be ignored. > > Most simple report use case is to just call the script without arguments: > > $ perf script report tasks-analyzer > Switched-In Switched-Out CPU PID TID Comm Runtime Time Out-In > 15576.658891407 15576.659156086 4 2412 2428 gdbus 265 1949 > 15576.659111320 15576.659455410 0 2412 2412 gnome-shell 344 2267 > 15576.659491326 15576.659506173 2 74 74 kworker/2:1 15 13145 > 15576.659506173 15576.659825748 2 2858 2858 gnome-terminal- 320 63263 > 15576.659871270 15576.659902872 6 20932 20932 kworker/u16:0 32 2314582 > 15576.659909951 15576.659945501 3 27264 27264 sh 36 -1 > 15576.659853285 15576.659971052 7 27265 27265 perf 118 5050741 > [...] > > What is not shown here are the ASCII color sequences. For example, if the task > consists of only one thread, the TID is grayed out. > > Runtime is the time the task was running on the CPU, Time Out-In is the time > between the process being scheduled *out* and scheduled back *in*. So the last > time span between two executions. If -1 is printed, then the task simply ran the > first time in the measurements - a Out-In delta could not be calculated. > > In addition to the chronological representation, there is a summary on task > level. This output can be additionally switched on via the --summary option > and provides information such as max, min & average runtime per process. The > maximum runtime is often important for debugging. The call looks like this: > > $ perf script report tasks-analyzer --summary > Summary > Task Information Runtime Information > PID TID Comm Runs Accumulated Mean Median Min Max Max At > 14 14 ksoftirqd/0 13 334 26 15 9 127 15571.621211956 > 15 15 rcu_preempt 133 1778 13 13 2 33 15572.581176024 > 16 16 migration/0 3 49 16 13 12 24 15571.608915425 > 20 20 migration/1 3 34 11 13 8 13 15571.639101555 > 25 25 migration/2 3 32 11 12 9 12 15575.639239896 > [...] > > Besides these two options, there are a number of other options that change the > output and behavior. This can be queried via --help. Options worth mentioning include: > > - filter-tasks - filter out unneeded tasks, --filter-task 1337,/sbin/init > - highlight-tasks - more pleasant focusing, --highlight-tasks 1:red,mutt:yellow > - extended-times - show combinations of elapsed times between schedule in/schedule out > - summary-extended - summary with additional information, like maximum delta time statistics > - rename-comms-by-tids - handy for inexpressive processnames like python, --rename 1337:my-python-app > - ms - show timestamps in milliseconds, nanoseconds is also possible (--ns) > - time-limit - limit the analyzer to a time range, --time-limit 15576.0:15576.1 > > Script is tested and prime time ready for python2 & python3: > - make PYTHON=python3 prefix=/usr/local install > - make PYTHON=python2 prefix=/usr/local install Thanks Peter, Python2 isn't a thing any more. It is worth knowing that for python3 you can test old versions easily with docker: docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3.6 python