Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1868532ybb; Thu, 9 Apr 2020 10:29:25 -0700 (PDT) X-Google-Smtp-Source: APiQypJv4FP9iHkX2t0B78J9CbZXKlASwZsZ9R3SkP0jEml00e+/WtlRpcayRzSnKK/VPpOv+bqD X-Received: by 2002:a05:620a:15d4:: with SMTP id o20mr974748qkm.218.1586453365813; Thu, 09 Apr 2020 10:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586453365; cv=none; d=google.com; s=arc-20160816; b=n1mmBRaELyiz7P+1du8DvXAJBChGZDX/Kh5KvijrocpqrCtY2gXOYWxxGDeV//beZr MiZLCSpq43Scog9TuhLGpSoqukf6Aj72JMILNUfsr1vTjSj5uegqIVHBLza9gsbMCvNz 8m/OAC2kHg4W4wgPRmU60cVbNokKShVGo2wVNUU+heb9wa7blaHoZDDQilpAZVTVtvWw N1hqRK+yMPAZwsKbMTItGet35bT5cF6QNLHglH5Vs3K8spYALyVoH90ttcwfZJ2OXUed 5TvYhmOcsKPxqcit7R9GD4pL5FdcJLbQzJFvufSMSSV597MYf1bK8/aJDpKdsM6F4Quy gAJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oIlNiJb3ausYuUxni1zU+nLq9ARdN6KgHNOnahfy3D8=; b=Ja8hGt724sjs0ehFloKAMAlqqMUcr+PQrDygqau6C8uZrUTFfE9vV1NZDmLwXRDDuy oivLtHFjHf5uP2JYimauNyoZIB0yyleQSoTqBPn4MbGOHiW0O/sAp/6r5TkNsl7ZoszO oxd87F5eeFEnEC+ca1TLJ4A10qZeXZWBU7DOEhMgkLXW9zbRvMmlfsX8afAwKDrrvkiO jlbS0aGGSyxslSgKSPeiQRD5k6Xx1BYepXwyh+yWyzD9DBLryepasHAFILH4jeu+oVeQ JliFxlxRM9bmq0tR5iz01/zNlkvXmAXnPL9MeARUn8TQEdHOmI2PHErNFACsu/BwI7Z1 lPew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=duYC2sW3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w128si6428100qkc.373.2020.04.09.10.29.11; Thu, 09 Apr 2020 10:29:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=duYC2sW3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727884AbgDIQ7D (ORCPT + 99 others); Thu, 9 Apr 2020 12:59:03 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:50402 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726728AbgDIQ7D (ORCPT ); Thu, 9 Apr 2020 12:59:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586451543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oIlNiJb3ausYuUxni1zU+nLq9ARdN6KgHNOnahfy3D8=; b=duYC2sW3uk0LSqlj2ZNh0LdYBbf83vIqOqYsjTtTDm8Ot62JbddhkHSJS5afx2GsuQOkAf QipAsl8pBdu+rCvxTLsQDBcIiZzjNziR/aQikIKb6Urx7Rz5jrem8O6vrd9BZu8cBMDWyl Y/AasEJBMlotbvG+PGBHTf24y0NO430= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-447-cNAfnu6LPDSY90YRtKWIXg-1; Thu, 09 Apr 2020 12:58:54 -0400 X-MC-Unique: cNAfnu6LPDSY90YRtKWIXg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C213100727C; Thu, 9 Apr 2020 16:58:53 +0000 (UTC) Received: from agerstmayr-thinkpad.redhat.com (unknown [10.40.193.205]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46EB960BFB; Thu, 9 Apr 2020 16:58:48 +0000 (UTC) From: Andreas Gerstmayr To: linux-perf-users@vger.kernel.org Cc: Andreas Gerstmayr , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org Subject: [PATCH] perf script flamegraph: python2 support, update cli args Date: Thu, 9 Apr 2020 18:57:31 +0200 Message-Id: <20200409165734.165260-1-agerstmayr@redhat.com> In-Reply-To: <20200406151118.GC32649@kernel.org> References: <20200406151118.GC32649@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * removed --indent argument * renamed -F to -f argument to be consistent with other arguments Signed-off-by: Andreas Gerstmayr --- tools/perf/scripts/python/flamegraph.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts= /python/flamegraph.py index 5835d190ca42..61f3be9add6b 100755 --- a/tools/perf/scripts/python/flamegraph.py +++ b/tools/perf/scripts/python/flamegraph.py @@ -14,6 +14,7 @@ # Flame Graphs invented by Brendan Gregg # Works in tandem with d3-flame-graph by Martin Spier =20 +from __future__ import print_function import sys import os import argparse @@ -43,11 +44,11 @@ class FlameGraphCLI: =20 if self.args.format =3D=3D "html" and \ not os.path.isfile(self.args.template): - print(f"Flame Graph template {self.args.template} does not "= + - f"exist. Please install the js-d3-flame-graph (RPM) or= " + - f"libjs-d3-flame-graph (deb) package, specify an " + - f"existing flame graph template (--template PATH) or "= + - f"another output format (--format FORMAT).", + print("Flame Graph template {} does not exist. Please instal= l " + "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=3Dsys.stderr) sys.exit(1) =20 @@ -76,8 +77,7 @@ class FlameGraphCLI: node.value +=3D 1 =20 def trace_end(self): - json_str =3D json.dumps(self.stack, default=3Dlambda x: x.toJSON= (), - indent=3Dself.args.indent) + json_str =3D json.dumps(self.stack, default=3Dlambda x: x.toJSON= ()) =20 if self.args.format =3D=3D "html": try: @@ -85,7 +85,7 @@ class FlameGraphCLI: output_str =3D f.read().replace("/** @flamegraph_jso= n **/", json_str) except IOError as e: - print(f"Error reading template file: {e}", file=3Dsys.st= derr) + print("Error reading template file: {}".format(e), file=3D= sys.stderr) sys.exit(1) output_fn =3D self.args.output or "flamegraph.html" else: @@ -95,24 +95,22 @@ class FlameGraphCLI: if output_fn =3D=3D "-": sys.stdout.write(output_str) else: - print(f"dumping data to {output_fn}") + print("dumping data to {}".format(output_fn)) try: with open(output_fn, "w") as out: out.write(output_str) except IOError as e: - print(f"Error writing output file: {e}", file=3Dsys.stde= rr) + print("Error writing output file: {}".format(e), file=3D= sys.stderr) sys.exit(1) =20 =20 if __name__ =3D=3D "__main__": parser =3D argparse.ArgumentParser(description=3D"Create flame graph= s.") - parser.add_argument("-F", "--format", + parser.add_argument("-f", "--format", default=3D"html", choices=3D["json", "html"], help=3D"output file format") parser.add_argument("-o", "--output", help=3D"output file name") - parser.add_argument("--indent", - type=3Dint, help=3D"JSON indentation") parser.add_argument("--template", default=3D"/usr/share/d3-flame-graph/d3-flamegra= ph-base.html", help=3D"path to flamegraph HTML template") --=20 2.25.2