Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2532330rwl; Fri, 6 Jan 2023 07:41:16 -0800 (PST) X-Google-Smtp-Source: AMrXdXtNMHcB2NU5W1NIAWxYimu7rseC3cbgGoqeMCYdbKnlwdZByrxGN7JaB4WyiwXTHj16pKzA X-Received: by 2002:a17:906:fb18:b0:82d:1d5f:2617 with SMTP id lz24-20020a170906fb1800b0082d1d5f2617mr49400254ejb.69.1673019676214; Fri, 06 Jan 2023 07:41:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673019676; cv=none; d=google.com; s=arc-20160816; b=YR0n2gNw9WS73CoTJgpRUa5IP+8JwrsnOo/3dgzTPY4UsbqZdwNu9ws0ABbZnRUk4k pSYinWnGQ5UokTZ/cg9TlKNJtuQSYgIx0b281tXgwZtJZLKEgm10aNazbqvplOkLLZz2 KN9Gu7gqeWD5fRPu2nzYQXe8uaUQH0UZfJwENR2g30E6gUjCt9y33sECf/1bWhLpmpyQ s0T8UYChIKswzMPtidek6/8SmvLbCzD305Zf7q8KBSFeP23fHlOQvTgwmkxdDNCUCFnl OJrXlCvZ7J6K2hRHJSDcaKksh23LTeMcHo0dfkY6zj5RLVI7YRI5BM1oi4hw7ibThCcA wZTA== 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=dQP/5D3LqTosG+7vRYjRg9axW9DC5iFtmMm9kbIA6S4=; b=EEzB7Pte7gSJ9CrMMh3sYgs8YCSQ6f8aD3xaz/1znTjPXNUsdQKEDx8BfHzpeok6hd KghnePJz/TaLL6qiiwGHzaim9k2cfCAKSIHgSZ0mLha2qC6rl79vuvDYK0M9SUjCKn9l UaOUn3OkBJmMc+BNHGMpeO2iTSZoT/33VSjstxU6yw9CEHNADzcLXfSovgJsACHaWxjx uHh1g2xA/9b1zhGKVUUYpwLZFTdQ9p4gz7zKy1e1UTPqP5+8EApjm71NodNL8jbMLQ2H v4+2PJttPkWPobZ3mi0Oe6NnRmFOP8sXGbXXcuAg7bKJ/IIbvFUmmWi26DJIvHaHwv/2 GiNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fpRj6AGH; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd41-20020a17090796a900b007c0fb283f11si2199491ejc.130.2023.01.06.07.41.03; Fri, 06 Jan 2023 07:41:16 -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=@gmail.com header.s=20210112 header.b=fpRj6AGH; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235708AbjAFPcu (ORCPT + 54 others); Fri, 6 Jan 2023 10:32:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235898AbjAFPcQ (ORCPT ); Fri, 6 Jan 2023 10:32:16 -0500 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B7E75D25; Fri, 6 Jan 2023 07:31:59 -0800 (PST) Received: by mail-yb1-xb30.google.com with SMTP id o75so2248718yba.2; Fri, 06 Jan 2023 07:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.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=dQP/5D3LqTosG+7vRYjRg9axW9DC5iFtmMm9kbIA6S4=; b=fpRj6AGHA4XtKSDcDKpCmSdJ7iZtz93UjJW4eyt0E8Y0HA6m2pjJF0Edmb3yyGUSD0 nmFIP3HAV/4/fEsaHR1WkagVrIyNZVY53D9G8Nv0z12z73PjEF7eqOP2LabG8bdhmvpj OFLbQPj/iYb4nZwJFGaL348GJbLCEjRbmnlo1XznWv2oKDpVhP9rAR6LaRR6CQKP3Q2U rJGcAU4X/czptrga1MTc8GwkI6t/o1uVK/tEKXWR35Ib66nxWb74wIoi25xS1vr31uPh vswd4Uxry24K6QB63vN/xRY27mEV110vK9o3DHQBzwvM0hF72hsGoYyzc92h8HF56j4/ 4zvQ== 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=dQP/5D3LqTosG+7vRYjRg9axW9DC5iFtmMm9kbIA6S4=; b=CdN4LlxeG+Ip6xSvxrwgND2FnBOKb2GZtqcm2qwokbJUI0zcgkRPO2ak3OT+j6DHc3 7m372RX3nUSJU6RSdxzLQPJptjObDODvdTiWKtpxam+igEtU9vYCUP02kPaPbpiBpejA b+SG8SqelEl5OMOds/zFtV4O1ELkr19ES6RGBqb5XFrwMCuDeuI50QUT1IVn4dcR/B53 g8XyiyS1WBRrQyb5doJxepZaiEHHbdtl9ZHRZLlLMykjrFDOh3KGaRra8TYBA6v5Qk66 FMCVdbGpSGa9N7qTl/bHfBWXoQbgQwkiQl97t4qeT5UR3UQg7kdJXA9qQKCrmPuQ3s3R tKYw== X-Gm-Message-State: AFqh2kpjbSnTzbRB2YkaZPfVVaDBOULc9BL4A9/Ap75CrAOHGEPTDYcO DvBHc5+b7FiJLK+wE3XmfqUJ8S+R+oU6xiUNL75zbKYm X-Received: by 2002:a25:9bc5:0:b0:706:bb2c:837 with SMTP id w5-20020a259bc5000000b00706bb2c0837mr5891970ybo.240.1673019118613; Fri, 06 Jan 2023 07:31:58 -0800 (PST) MIME-Version: 1.0 References: <20230105030434.255603-1-irogers@google.com> In-Reply-To: From: Martin Spier Date: Fri, 6 Jan 2023 07:31:46 -0800 Message-ID: Subject: Re: [PATCH v1] perf script flamegraph: Avoid d3-flame-graph package dependency To: Ian Rogers 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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, 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 > > > + > > + > > +
> > + > > + > > + > > + > > +""" > > > > # 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 > >