Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <agerstmayr@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20200619153232.203537-1-agerstmayr@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Andreas Gerstmayr and committed by
Arnaldo Carvalho de Melo
c42ad5d4 625d3449

+5 -3
+5 -3
tools/perf/scripts/python/flamegraph.py
··· 17 17 from __future__ import print_function 18 18 import sys 19 19 import os 20 + import io 20 21 import argparse 21 22 import json 22 23 ··· 82 81 83 82 if self.args.format == "html": 84 83 try: 85 - with open(self.args.template) as f: 84 + with io.open(self.args.template, encoding="utf-8") as f: 86 85 output_str = f.read().replace("/** @flamegraph_json **/", 87 86 json_str) 88 87 except IOError as e: ··· 94 93 output_fn = self.args.output or "stacks.json" 95 94 96 95 if output_fn == "-": 97 - sys.stdout.write(output_str) 96 + with io.open(sys.stdout.fileno(), "w", encoding="utf-8", closefd=False) as out: 97 + out.write(output_str) 98 98 else: 99 99 print("dumping data to {}".format(output_fn)) 100 100 try: 101 - with open(output_fn, "w") as out: 101 + with io.open(output_fn, "w", encoding="utf-8") as out: 102 102 out.write(output_str) 103 103 except IOError as e: 104 104 print("Error writing output file: {}".format(e), file=sys.stderr)