##// END OF EJS Templates
dispatch: add support for python-flamegraph[0] profiling...
Augie Fackler -
r25187:670c1df6 default
parent child Browse files
Show More
@@ -921,6 +921,30 b' def lsprofile(ui, func, fp):'
921 921 stats.sort(field)
922 922 stats.pprint(limit=limit, file=fp, climit=climit)
923 923
924 def flameprofile(ui, func, fp):
925 try:
926 from flamegraph import flamegraph
927 except ImportError:
928 raise util.Abort(_(
929 'flamegraph not available - install from '
930 'https://github.com/evanhempel/python-flamegraph'))
931 freq = ui.configint('profiling', 'freq', default=1000)
932 filter_ = None
933 collapse_recursion = True
934 thread = flamegraph.ProfileThread(fp, 1.0 / freq,
935 filter_, collapse_recursion)
936 start_time = time.clock()
937 try:
938 thread.start()
939 func()
940 finally:
941 thread.stop()
942 thread.join()
943 print 'Collected %d stack frames (%d unique) in %2.2f seconds.' % (
944 time.clock() - start_time, thread.num_frames(),
945 thread.num_frames(unique=True))
946
947
924 948 def statprofile(ui, func, fp):
925 949 try:
926 950 import statprof
@@ -952,7 +976,7 b' def _runcommand(ui, options, cmd, cmdfun'
952 976 profiler = os.getenv('HGPROF')
953 977 if profiler is None:
954 978 profiler = ui.config('profiling', 'type', default='ls')
955 if profiler not in ('ls', 'stat'):
979 if profiler not in ('ls', 'stat', 'flame'):
956 980 ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler)
957 981 profiler = 'ls'
958 982
@@ -967,6 +991,8 b' def _runcommand(ui, options, cmd, cmdfun'
967 991 try:
968 992 if profiler == 'ls':
969 993 return lsprofile(ui, checkargs, fp)
994 elif profiler == 'flame':
995 return flameprofile(ui, checkargs, fp)
970 996 else:
971 997 return statprofile(ui, checkargs, fp)
972 998 finally:
General Comments 0
You need to be logged in to leave comments. Login now