Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp586289rwl; Thu, 5 Jan 2023 01:28:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXsycIwqlX9DcEN0NJh0GiWsrOZltx4j+EvlshC6JvfFNvsWcX6pojrQo9b2B0HPGFh3uQ9L X-Received: by 2002:a05:6a21:c008:b0:af:8448:5137 with SMTP id bm8-20020a056a21c00800b000af84485137mr64821144pzc.39.1672910882006; Thu, 05 Jan 2023 01:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672910881; cv=none; d=google.com; s=arc-20160816; b=ytSvDWHCk0gfzJp2hgYc+1dkEVYt3EiizBPXj+HeY5xB+out4Jut/0jek/JZxT9IuA 8gjxx5Zh7a//Uh5w3NAfehTl7slfeh1jYiYajaCG2WbeBEKpqq3V/pCJQifaBuWUhZDq Mo0BpHFxBaGE/Gk5OMYi6ON0Byfuj6ViVOaG0Dxqapq1LoAMqMIce2TLRnDRXVd571cb ho5riYqaqJoyeJ45Zk6ZWtDNSj3WzdBMlx2xVAWiWgX2oBnCwmpRgU4+9vs12PGz5S3p Bcd+hI8nes7JjDmP3S1n59m7AbJyj3LYEFKkkw7HIHMq6SNkNqj+TBJYvXR4tok2VYcI lhdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=yJxb6YsgY1IN1CKBHgvi2wvMh1i9b0ozsEOL55ctxKY=; b=oNOIAZGMm+KMg2i2nUVb1OcAxEEwKG6nhrkKDa2Dn2tgXRjTv9F0ewtsGfbcnoD3gh Y13e0h4mYWNC/zxmFEEpyRv//8wkz6+5z46O/BSLVwuptgz4DB86lGzB6PkftKx0H5Xk Prd8aT5UwPMVHcVJaFwept7mP7+MiAKVGQKVjuE70Hk+NoMBlK6Gepl097q4t1/gUxi2 edgFhqpiD1rTI68X1H+cDzxx0VsUf9TEQI/vOKIZLpnjSErX0BdiYEW9yyvZn8mXPOPt PAu54O4UV09JUhJAicwNtGYj7FwWNhaPlN+zROK4P0V2qRx1UkQtrLJGx8lJYoNcc439 /ptw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KLHUdbae; 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 84-20020a630257000000b00477ff64b022si39701403pgc.19.2023.01.05.01.27.54; Thu, 05 Jan 2023 01:28:01 -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=KLHUdbae; 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 S231600AbjAEJZS (ORCPT + 55 others); Thu, 5 Jan 2023 04:25:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231989AbjAEJZM (ORCPT ); Thu, 5 Jan 2023 04:25:12 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3046551C8 for ; Thu, 5 Jan 2023 01:25:08 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id bn26so16027735wrb.0 for ; Thu, 05 Jan 2023 01:25:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=yJxb6YsgY1IN1CKBHgvi2wvMh1i9b0ozsEOL55ctxKY=; b=KLHUdbae1C0mOJLmF5TVe4FUxY2qoWxHG8Sccep6Tm9jZx6DMjOx2hYGQGf9LIDXtu jGwfrngwYsYzUWnRevcI0HDbXWCvCVWQLRJLEvUVqTi4/7MYnLZqNZUid9DMnQUKzHE/ Q+/u4ayAe8Jbw1Lnpw2iQ4V3oHouUssuyV8ItGtHrcbYCSTHbfs40TQjlYn8rVha0oYV Efn6urBp1R3QgRAsntARKfKCQzW4PC3m43oOeZFf5pAWbWoNod/KX431WDSHLpjx0g/x eGRQZrXPFbCdHC4mzQGMAcT8fATNzgP53nZud6CKlU2ennELNZ9qB/ieIqy0obZb13QK 6kBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=yJxb6YsgY1IN1CKBHgvi2wvMh1i9b0ozsEOL55ctxKY=; b=Myxqb7QTozGcod9wpjAd9Kqcq9WWQl4AgysTNB1dxmas2SgLg4DeIg1A6B+IxXDOxp tgDF697FLmXsIGs+6ckhj/ofoVp75H9WuZCJ8MQ7zLqL6Za1DZ+XJM/LgCMJfZP5TLc0 dwPcFbPUG/WIJvwEYOePxKVXbB8+Zp6FZMmZfBRhG3LswofKG0BF639cpc7pg4ExtQC9 pnpVIqSorYQH7voQJlZ0dzJLQtuNo8yCl8rUegBICEpu0W7nv8+IsgpFptKMVztc3J/T +5KZGpDHlJz434fVRqNGpjcCz7N3GcZV1vX8LICWHslBNIxWHkceekzQthzywHUzJB5R G8CQ== X-Gm-Message-State: AFqh2kqj6H7Gu1h4p05gRyM+9KdKzscZgSR4W0VK/Kv22brYw6IoqAp0 8jYhUxNZ/SqC9Ps6jHU/00xopuOky+bDkDKEpXwL+w== X-Received: by 2002:a5d:4590:0:b0:27e:cf2e:ca4e with SMTP id p16-20020a5d4590000000b0027ecf2eca4emr759089wrq.343.1672910706943; Thu, 05 Jan 2023 01:25:06 -0800 (PST) MIME-Version: 1.0 References: <20230105030434.255603-1-irogers@google.com> In-Reply-To: <20230105030434.255603-1-irogers@google.com> From: Ian Rogers Date: Thu, 5 Jan 2023 01:24:54 -0800 Message-ID: Subject: Re: [PATCH v1] perf script flamegraph: Avoid d3-flame-graph package dependency To: 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 , spiermar@gmail.com 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 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 > + > + > +
> + > + > + > + > +""" > > # 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 >