py3: for statprof's Chrome output, write json to string, then encode to bytes
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 30 Aug 2019 15:30:47 -0700
changeset 42836 cd3b5be5515d
parent 42835 db6d7cbda80b
child 42837 cde1c101ab8a
py3: for statprof's Chrome output, write json to string, then encode to bytes `json.dump(obj, fp)` requires `fp.write()` to accept str output, and since the file pointer we have there only accepts bytes, we need to change to json.dumps() and then encode as utf-8. We have already done the same thing for the json (non-Chrome) format in 4b7eb862692e (py3: encode json output to bytes and use write(), 2018-10-12). Differential Revision: https://phab.mercurial-scm.org/D6781
mercurial/statprof.py
--- a/mercurial/statprof.py	Fri Aug 30 16:44:31 2019 -0700
+++ b/mercurial/statprof.py	Fri Aug 30 15:30:47 2019 -0700
@@ -875,7 +875,10 @@
               if idx not in blacklist]
     frames = collections.OrderedDict((str(k), v)
                                      for (k,v) in enumerate(id2stack))
-    json.dump(dict(traceEvents=events, stackFrames=frames), fp, indent=1)
+    data = json.dumps(dict(traceEvents=events, stackFrames=frames), indent=1)
+    if not isinstance(data, bytes):
+        data = data.encode('utf-8')
+    fp.write(data)
     fp.write('\n')
 
 def printusage():