Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6755757rwl; Mon, 9 Jan 2023 12:35:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXvCwwhNcKsH7uNrvPnjrzLfbriDIoEN6Xu3FXGkd0Dc/hcCptwnInyuDnY5TJ8gJsHpFOAL X-Received: by 2002:a17:907:8c0c:b0:7c0:ad62:a25f with SMTP id ta12-20020a1709078c0c00b007c0ad62a25fmr57735012ejc.51.1673296552586; Mon, 09 Jan 2023 12:35:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673296552; cv=none; d=google.com; s=arc-20160816; b=nDFhCKZR0kzPGTDHovbWk6jkSYqUlLWA4HLZ03nLEUeBsK656+cFcpUEO+USW2fEg5 LL6FAX0Nm7QiDQHlUszjV/BaLjHrGUd795t7BjoptTl3pa2svEL9f/G9jIosGlQkMvwH ggHD5yfF7KWPz8xHaEiXDZr7jbIVs9w0BVpoXPXZ4pwCZyIx5XDWUFvufI28yX4KNcAa AWYpnwIUuMgI8LzzTUZk6+hqQ807xoael/bjVspIdpCo7DkqQI6T2A7m+oYTpydkOM50 AlCpT4X2J9R7sF0rbvsc4URL4hMpTU3cP5/qVzYflTns45YrobnKjvadZXVuKH8TIo4s 49Pg== 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=sm+C6Y4VHJEDtGwIvvGgY7BGxijkOAR29lDr/Tbsy3A=; b=jJvU2CYTcdCWnT7Dcxu09e3qgW9nhUr6avzGTDuxyKt5kFIec2bP/tt4WEhalu5/Oj InWi3WHgE7QW7ARcWnE7P6/7cYIgngxWWGDtbIfu6Rc11EYo0nJWWWiZZ4XWI4EXdCN1 okASqdKw9Wia/OJ+0fPlThac+OM+No9CUYkqkfwsXjLsjQ/163uG0eOb51zVyICsFoa0 f6rzek80mpP2B1umrns9Xvx3uhxsbzZuouTIrLunvRwku+ixuzjQ4jTAP3alIh23eIC2 GQykThApKVvxbh6jKnW2KyaCdrrvnRt5sJ/uRQDhSQS/ANZWIXsuA4bg4gFPx3huTn4Y 11ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=tDlDq1Fk; 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 jg13-20020a170907970d00b0078dfe6dc4d2si10453443ejc.33.2023.01.09.12.35.40; Mon, 09 Jan 2023 12:35:52 -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=tDlDq1Fk; 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 S237627AbjAITnL (ORCPT + 53 others); Mon, 9 Jan 2023 14:43:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237678AbjAITm5 (ORCPT ); Mon, 9 Jan 2023 14:42:57 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E4503590C for ; Mon, 9 Jan 2023 11:42:56 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id bs20so9336420wrb.3 for ; Mon, 09 Jan 2023 11:42:56 -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=sm+C6Y4VHJEDtGwIvvGgY7BGxijkOAR29lDr/Tbsy3A=; b=tDlDq1FkSgoi9HsSAmHq/G1pvTD21qW7XYfQnck5oYb2AhOo9kFjJMrLzYSkivk1T4 4BPoJn1oyAJsLYH87L+dNhESNeJXB4dkJ5TQ0Gq5UwBIuCdQEfYvPfJmGp6kowUbBj0g ZOjVOa+89Z3KIgebtQN+Ug9K2zNt6viJ17kxjohRc91l1gyfcHSBGya+kQEw97VYLr77 DteJKaG7Pb6gW0/OgmH6lq03RZTQIqOZpYpmB7ZbU9VW1Bnp9mVIofo7kGSSBwBWglSi rdV/IAq18wsDLyUVEoVIsE0ga0iIruBN10dy2evrp1LsBCBP8CleQefNS5rvS7xnkUo+ Ft1Q== 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=sm+C6Y4VHJEDtGwIvvGgY7BGxijkOAR29lDr/Tbsy3A=; b=sv4NE+Nr608Dwwnt1cqdb86h6kdLypHagpMAx8uoXSD0csrl6hAyHwkD8QLUcVqjUd GuHzMz8RpsStMI5HaZUxUfGZQJSZAoUS9SCOllCb5vRxq5VQfA8ZBgP+8HalV5gXyVOQ nb36AYAZZPc4MFi6tbkGdSC8fwl0K0UKgn+TQ7DuxIBrI9BaMn9SZ3bobdKUSZCGbPbH 2SUhOOt4STaDFuluFlSC6aIMmd93XzWf4hU0tOpgs8q9CzvsfLeCbLHmxKvomPQlJGUk 3jVHAyE4J815MTtbR2eIy1D9A+xWXXfwVIkheFasTO1MUli1mcrkSaWttzTVYYK3+o7y h0ig== X-Gm-Message-State: AFqh2kreNKwQo++4p5tU76fjSIvtoE7YqQQWtRYeldwYzkEBhCGfZET+ VPQcYJmdzgNFd233DrdUSOvhWCYY+5caHTvD7uEHlA== X-Received: by 2002:a05:6000:12cb:b0:28c:459a:d5d with SMTP id l11-20020a05600012cb00b0028c459a0d5dmr1401361wrx.654.1673293374842; Mon, 09 Jan 2023 11:42:54 -0800 (PST) MIME-Version: 1.0 References: <20230105030434.255603-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Mon, 9 Jan 2023 11:42:42 -0800 Message-ID: Subject: Re: [PATCH v1] perf script flamegraph: Avoid d3-flame-graph package dependency To: Martin Spier Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, 996839@bugs.debian.org, Andreas Gerstmayr , Brendan Gregg 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 Fri, Jan 6, 2023 at 7:32 AM Martin Spier wrote: > > On Thu, Jan 5, 2023 at 1:25 AM Ian Rogers wrote: > > > > On Wed, Jan 4, 2023 at 7:04 PM Ian Rogers wrote: > > > > > > Currently flame graph generation requires a d3-flame-graph template to > > > be installed. Unfortunately this is hard to come by for things like > > > Debian [1]. If the template isn't installed warn and download it from > > > jsdelivr CDN. If downloading fails generate a minimal flame graph > > > again with the javascript coming from jsdelivr CDN. > > > > > > [1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=996839 > > > > > > Signed-off-by: Ian Rogers > > > --- > > > tools/perf/scripts/python/flamegraph.py | 63 ++++++++++++++++++------- > > > 1 file changed, 45 insertions(+), 18 deletions(-) > > > > > > diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts/python/flamegraph.py > > > index b6af1dd5f816..808b0e1c9be5 100755 > > > --- a/tools/perf/scripts/python/flamegraph.py > > > +++ b/tools/perf/scripts/python/flamegraph.py > > > @@ -25,6 +25,27 @@ import io > > > import argparse > > > import json > > > import subprocess > > > +import urllib.request > > > + > > > +minimal_html = """ > > > + > > > > (hopefully fixed Martin Spier's e-mail address) > > > > The @4.1.3 comes from the README.md: > > https://github.com/spiermar/d3-flame-graph/blob/master/README.md > > Does it make sense just to drop it or use @latest ? It'd be nice not > > to patch this file for every d3-flame-graph update. > > > > Thanks, > > Ian > > Yes, that's the right email. > > Using @latest is an option, but it might be better to just use @4 to > avoid breaking changes. Not expecting any major releases in the near > future. > > Thanks, > Martin Thanks Martin! I'll leave it using @4 then. Could I trouble you for an Acked-by or Reviewed-by for the change? It would be nice to resolve the Debian bug. Thanks, Ian > > > > > + > > > + > > > +
> > > + > > > + > > > + > > > + > > > +""" > > > > > > # pylint: disable=too-few-public-methods > > > class Node: > > > @@ -50,15 +71,18 @@ class FlameGraphCLI: > > > self.args = args > > > self.stack = Node("all", "root") > > > > > > - if self.args.format == "html" and \ > > > - not os.path.isfile(self.args.template): > > > - print("Flame Graph template {} does not exist. Please install " > > > - "the js-d3-flame-graph (RPM) or libjs-d3-flame-graph (deb) " > > > - "package, specify an existing flame graph template " > > > - "(--template PATH) or another output format " > > > - "(--format FORMAT).".format(self.args.template), > > > - file=sys.stderr) > > > - sys.exit(1) > > > + if self.args.format == "html": > > > + if os.path.isfile(self.args.template): > > > + self.template = f"file://{self.args.template}" > > > + else: > > > + print(f""" > > > +Warning: Flame Graph template '{self.args.template}' > > > +does not exist, a template will be downloaded via http. To avoid this > > > +please install a package such as the js-d3-flame-graph or > > > +libjs-d3-flame-graph, specify an existing flame graph template > > > +(--template PATH) or another output format (--format FORMAT). > > > +""", file=sys.stderr) > > > + self.template = "https://cdn.jsdelivr.net/npm/d3-flame-graph@4.1.3/dist/templates/d3-flamegraph-base.html" > > > > > > @staticmethod > > > def get_libtype_from_dso(dso): > > > @@ -129,15 +153,18 @@ class FlameGraphCLI: > > > options_json = json.dumps(options) > > > > > > try: > > > - with io.open(self.args.template, encoding="utf-8") as template: > > > - output_str = ( > > > - template.read() > > > - .replace("/** @options_json **/", options_json) > > > - .replace("/** @flamegraph_json **/", stacks_json) > > > - ) > > > - except IOError as err: > > > - print("Error reading template file: {}".format(err), file=sys.stderr) > > > - sys.exit(1) > > > + with urllib.request.urlopen(self.template) as template: > > > + output_str = '\n'.join([ > > > + l.decode('utf-8') for l in template.readlines() > > > + ]) > > > + except Exception as err: > > > + print(f"Error reading template {self.template}: {err}\n" > > > + "a minimal flame graph will be generated", file=sys.stderr) > > > + output_str = minimal_html > > > + > > > + output_str = output_str.replace("/** @options_json **/", options_json) > > > + output_str = output_str.replace("/** @flamegraph_json **/", stacks_json) > > > + > > > output_fn = self.args.output or "flamegraph.html" > > > else: > > > output_str = stacks_json > > > -- > > > 2.39.0.314.g84b9a713c41-goog > > >