Mercurial > public > mercurial-scm > hg
comparison mercurial/profiling.py @ 51585:1574718fa62f
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.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sun, 14 Apr 2024 02:36:55 +0200 |
parents | 18c8c18993f0 |
children | 812a094a7477 1bb71046f5e0 |
comparison
equal
deleted
inserted
replaced
51584:8cd317c033b8 | 51585:1574718fa62f |
---|---|
68 else: | 68 else: |
69 # format == 'text' | 69 # format == 'text' |
70 stats = lsprof.Stats(p.getstats()) | 70 stats = lsprof.Stats(p.getstats()) |
71 stats.sort(pycompat.sysstr(field)) | 71 stats.sort(pycompat.sysstr(field)) |
72 stats.pprint(limit=limit, file=fp, climit=climit) | 72 stats.pprint(limit=limit, file=fp, climit=climit) |
73 fp.flush() | |
73 | 74 |
74 | 75 |
75 @contextlib.contextmanager | 76 @contextlib.contextmanager |
76 def flameprofile(ui, fp): | 77 def flameprofile(ui, fp): |
77 try: | 78 try: |
95 thread.start() | 96 thread.start() |
96 yield | 97 yield |
97 finally: | 98 finally: |
98 thread.stop() | 99 thread.stop() |
99 thread.join() | 100 thread.join() |
100 print( | 101 m = b'Collected %d stack frames (%d unique) in %2.2f seconds.' |
101 b'Collected %d stack frames (%d unique) in %2.2f seconds.' | 102 m %= ( |
102 % ( | 103 ( |
103 util.timer() - start_time, | 104 util.timer() - start_time, |
104 thread.num_frames(), | 105 thread.num_frames(), |
105 thread.num_frames(unique=True), | 106 thread.num_frames(unique=True), |
106 ) | 107 ), |
107 ) | 108 ) |
109 print(m, flush=True) | |
108 | 110 |
109 | 111 |
110 @contextlib.contextmanager | 112 @contextlib.contextmanager |
111 def statprofile(ui, fp): | 113 def statprofile(ui, fp): |
112 from . import statprof | 114 from . import statprof |
168 kwargs['limit'] = limit | 170 kwargs['limit'] = limit |
169 showtime = ui.configbool(b'profiling', b'showtime') | 171 showtime = ui.configbool(b'profiling', b'showtime') |
170 kwargs['showtime'] = showtime | 172 kwargs['showtime'] = showtime |
171 | 173 |
172 statprof.display(fp, data=data, format=displayformat, **kwargs) | 174 statprof.display(fp, data=data, format=displayformat, **kwargs) |
175 fp.flush() | |
173 | 176 |
174 | 177 |
175 class profile: | 178 class profile: |
176 """Start profiling. | 179 """Start profiling. |
177 | 180 |