# HG changeset patch # User Pierre-Yves David # Date 2024-04-14 00:36:55 # Node ID 1574718fa62fca918a17a2f32ad6b0f0251ff459 # Parent 8cd317c033b86e0a3c2e45d5f75b5c199448e1d6 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. diff --git a/mercurial/profiling.py b/mercurial/profiling.py --- a/mercurial/profiling.py +++ b/mercurial/profiling.py @@ -70,6 +70,7 @@ def lsprofile(ui, fp): 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 @@ def flameprofile(ui, fp): 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 @@ def statprofile(ui, fp): kwargs['showtime'] = showtime statprof.display(fp, data=data, format=displayformat, **kwargs) + fp.flush() class profile: