Patchwork D6781: py3: for statprof's Chrome output, write json to string, then encode to bytes

login
register
mail settings
Submitter phabricator
Date Aug. 31, 2019, 10:59 p.m.
Message ID <cd52cbbd98043e83e06683a2d7d08e21@localhost.localdomain>
Download mbox | patch
Permalink /patch/41454/
State Not Applicable
Headers show

Comments

phabricator - Aug. 31, 2019, 10:59 p.m.
Closed by commit rHG06e2467ff27a: py3: for statprof&#039;s Chrome output, write json to string, then encode to bytes (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6781?vs=16346&id=16351

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6781/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6781

AFFECTED FILES
  mercurial/statprof.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/statprof.py b/mercurial/statprof.py
--- a/mercurial/statprof.py
+++ b/mercurial/statprof.py
@@ -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():