From: Andreas Gerstmayr <agerstmayr@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-perf-users@vger.kernel.org,
Michael Petlan <mpetlan@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] perf flamegraph: explicitly set utf-8 encoding
Date: Mon, 22 Jun 2020 19:45:39 +0200 [thread overview]
Message-ID: <4a02db6c-3a47-09aa-1534-48926d425633@redhat.com> (raw)
In-Reply-To: <20200622163127.GB30611@kernel.org>
On 22.06.20 18:31, Arnaldo Carvalho de Melo wrote:
> Em Fri, Jun 19, 2020 at 05:32:31PM +0200, Andreas Gerstmayr escreveu:
>> on some platforms the default encoding is not utf-8,
>> which causes an UnicodeDecodeError when reading the flamegraph template
>> and writing the flamegraph
>
> Thanks, applied.
Thank you!
Cheers,
Andreas
>
> - Arnaldo
>
>> Signed-off-by: Andreas Gerstmayr <agerstmayr@redhat.com>
>> ---
>>
>> 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
>>
>
prev parent reply other threads:[~2020-06-22 17:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 13:07 [PATCH] perf flamegraph: explicitly set utf-8 encoding Andreas Gerstmayr
2020-06-19 15:32 ` [PATCH v2] " Andreas Gerstmayr
2020-06-22 16:31 ` Arnaldo Carvalho de Melo
2020-06-22 17:45 ` Andreas Gerstmayr [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4a02db6c-3a47-09aa-1534-48926d425633@redhat.com \
--to=agerstmayr@redhat.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=mpetlan@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).