Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp895055ybt; Fri, 19 Jun 2020 17:17:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyrMpbabwL9ouexpHZp3H7WK17CSWMmWqztAD/HchjXLWKYZG7HVOWMI3go33/wVEZXzs8 X-Received: by 2002:a17:906:838a:: with SMTP id p10mr5770348ejx.243.1592612222994; Fri, 19 Jun 2020 17:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592612222; cv=none; d=google.com; s=arc-20160816; b=PUeBkAJVcF8ZgquhDRbAg1xogXHFaubKnBdHmdR+4DwJaFDOAyDDgL1vznunL96O52 tcNemm3JqANxQhT/RENS5KdW2jzyHR8K/VMhOcyuQJViN8jmfX7vGDnzMVGGRe8lAYDq pVctsrsl2ZwYQPv2Bfr/e7nNTKDSDsEZ228SjCmd7cTMXajxQ7ghawI1C0/AP9N5XCOr PmDbHscsnYIo3JXWbbySL9yLMTrfNFc/I2frr/XlvtZ0RUwur+DC4g2vH1Ml3Jfm1RDg KWyv0wf5e5jNzawYYaInuNYns+j1x+XSJy2/940rcZF6CaQbyN5D5rAGSVmDqBu9fKDO 3ytA== 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=1gjUns75l8t6S6FnUcYsN6ZlE6IET04KazBXsahJkg8=; b=KCh/myyc1Lw77RO/IPjcM33OHCUHITKCKbvOaQ9UbdMFUXVTe4wkrWOoJ7diAEkf9j fEABxG7A3+ylROcOOMx18hOMZeQI11jJOZNaweNqVg8GR1QJpTKGsUwat+TJYcmc7qIv NKeveWYuGyeYk/V6RJnigLu3r/nDSyoWmEc7quAPFc7LVb2M4kFRx0Q3qpb9YtdxlMAf K1nHDjcK695S/5i4Qbe2HG+NcLhbQ36gXmzOqGwi68HiXxPsnfWE7/1S3LkEqbs/ETXx h1Hq+jbuWz5BrDS1CV+6fR989sBKyYN/kdNDEGwcvEtbS0Ug1tOqmgMPcDBtZMPz/NzV OsOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R89A4Vk1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id i20si4667909eja.745.2020.06.19.17.16.40; Fri, 19 Jun 2020 17:17:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R89A4Vk1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2404946AbgFSPeQ (ORCPT + 99 others); Fri, 19 Jun 2020 11:34:16 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:50714 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404901AbgFSPeH (ORCPT ); Fri, 19 Jun 2020 11:34:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592580845; 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=1gjUns75l8t6S6FnUcYsN6ZlE6IET04KazBXsahJkg8=; b=R89A4Vk1fiBeltHWigJoNwYNpFI/7x3JzBZIGYRejPjtRqZwhEvH/aye5EvgwfEDcWHCzr w78g5PPSjhAkkUkWcP+2OavZGo7GhLyvVdloDeXAc2iMAorfPJSs5J6I8K/bBWj2WndLpn apzsgtdEcqEnCJ+RHNJnxOnPu8I7vZA= 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-187-NbuglgpSPkKbOHTyzRHHIQ-1; Fri, 19 Jun 2020 11:34:00 -0400 X-MC-Unique: NbuglgpSPkKbOHTyzRHHIQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44B44801503; Fri, 19 Jun 2020 15:33:59 +0000 (UTC) Received: from agerstmayr-thinkpad.redhat.com (unknown [10.40.196.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 915942CE8A; Fri, 19 Jun 2020 15:33:51 +0000 (UTC) From: Andreas Gerstmayr To: linux-perf-users@vger.kernel.org Cc: Michael Petlan , 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 v2] perf flamegraph: explicitly set utf-8 encoding Date: Fri, 19 Jun 2020 17:32:31 +0200 Message-Id: <20200619153232.203537-1-agerstmayr@redhat.com> In-Reply-To: <20200619130745.153113-1-agerstmayr@redhat.com> References: <20200619130745.153113-1-agerstmayr@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org on some platforms the default encoding is not utf-8, which causes an UnicodeDecodeError when reading the flamegraph template and writing the flamegraph Signed-off-by: Andreas Gerstmayr --- changelog v2: also write to stdout with utf-8 encoding tools/perf/scripts/python/flamegraph.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/perf/scripts/python/flamegraph.py b/tools/perf/scripts/python/flamegraph.py index 61f3be9add6b..65780013f745 100755 --- a/tools/perf/scripts/python/flamegraph.py +++ b/tools/perf/scripts/python/flamegraph.py @@ -17,6 +17,7 @@ from __future__ import print_function import sys import os +import io import argparse import json @@ -81,7 +82,7 @@ class FlameGraphCLI: if self.args.format == "html": try: - with open(self.args.template) as f: + with io.open(self.args.template, encoding="utf-8") as f: output_str = f.read().replace("/** @flamegraph_json **/", json_str) except IOError as e: @@ -93,11 +94,12 @@ class FlameGraphCLI: output_fn = self.args.output or "stacks.json" if output_fn == "-": - sys.stdout.write(output_str) + with io.open(sys.stdout.fileno(), "w", encoding="utf-8", closefd=False) as out: + out.write(output_str) else: print("dumping data to {}".format(output_fn)) try: - with open(output_fn, "w") as out: + with io.open(output_fn, "w", encoding="utf-8") as out: out.write(output_str) except IOError as e: print("Error writing output file: {}".format(e), file=sys.stderr) -- 2.25.4