profiler: flush after writing the profiler output
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 14 Apr 2024 02:36:55 +0200
changeset 51588 1574718fa62f
parent 51587 8cd317c033b8
child 51589 90ef3e042e10
profiler: flush after writing the profiler output Otherwise, the profiler output might only partially appears until the next flush of the buffer. Since profiling often happens for long operation, the next flush can be a long time away.
mercurial/profiling.py
--- a/mercurial/profiling.py	Sun Apr 14 02:33:36 2024 +0200
+++ b/mercurial/profiling.py	Sun Apr 14 02:36:55 2024 +0200
@@ -70,6 +70,7 @@
             stats = lsprof.Stats(p.getstats())
             stats.sort(pycompat.sysstr(field))
             stats.pprint(limit=limit, file=fp, climit=climit)
+        fp.flush()
 
 
 @contextlib.contextmanager
@@ -97,14 +98,15 @@
     finally:
         thread.stop()
         thread.join()
-        print(
-            b'Collected %d stack frames (%d unique) in %2.2f seconds.'
-            % (
+        m = b'Collected %d stack frames (%d unique) in %2.2f seconds.'
+        m %= (
+            (
                 util.timer() - start_time,
                 thread.num_frames(),
                 thread.num_frames(unique=True),
-            )
+            ),
         )
+        print(m, flush=True)
 
 
 @contextlib.contextmanager
@@ -170,6 +172,7 @@
             kwargs['showtime'] = showtime
 
         statprof.display(fp, data=data, format=displayformat, **kwargs)
+        fp.flush()
 
 
 class profile: