Skip to content

Commit c42ad5d

Browse files
andreasgerstmayracmel
authored andcommitted
perf flamegraph: Explicitly set utf-8 encoding
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 <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 625d344 commit c42ad5d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tools/perf/scripts/python/flamegraph.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import print_function
1818
import sys
1919
import os
20+
import io
2021
import argparse
2122
import json
2223

@@ -81,7 +82,7 @@ def trace_end(self):
8182

8283
if self.args.format == "html":
8384
try:
84-
with open(self.args.template) as f:
85+
with io.open(self.args.template, encoding="utf-8") as f:
8586
output_str = f.read().replace("/** @flamegraph_json **/",
8687
json_str)
8788
except IOError as e:
@@ -93,11 +94,12 @@ def trace_end(self):
9394
output_fn = self.args.output or "stacks.json"
9495

9596
if output_fn == "-":
96-
sys.stdout.write(output_str)
97+
with io.open(sys.stdout.fileno(), "w", encoding="utf-8", closefd=False) as out:
98+
out.write(output_str)
9799
else:
98100
print("dumping data to {}".format(output_fn))
99101
try:
100-
with open(output_fn, "w") as out:
102+
with io.open(output_fn, "w", encoding="utf-8") as out:
101103
out.write(output_str)
102104
except IOError as e:
103105
print("Error writing output file: {}".format(e), file=sys.stderr)

0 commit comments

Comments
 (0)