Show More
@@ -921,6 +921,30 b' def lsprofile(ui, func, fp):' | |||||
921 | stats.sort(field) |
|
921 | stats.sort(field) | |
922 | stats.pprint(limit=limit, file=fp, climit=climit) |
|
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 | def statprofile(ui, func, fp): |
|
948 | def statprofile(ui, func, fp): | |
925 | try: |
|
949 | try: | |
926 | import statprof |
|
950 | import statprof | |
@@ -952,7 +976,7 b' def _runcommand(ui, options, cmd, cmdfun' | |||||
952 | profiler = os.getenv('HGPROF') |
|
976 | profiler = os.getenv('HGPROF') | |
953 | if profiler is None: |
|
977 | if profiler is None: | |
954 | profiler = ui.config('profiling', 'type', default='ls') |
|
978 | profiler = ui.config('profiling', 'type', default='ls') | |
955 | if profiler not in ('ls', 'stat'): |
|
979 | if profiler not in ('ls', 'stat', 'flame'): | |
956 | ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler) |
|
980 | ui.warn(_("unrecognized profiler '%s' - ignored\n") % profiler) | |
957 | profiler = 'ls' |
|
981 | profiler = 'ls' | |
958 |
|
982 | |||
@@ -967,6 +991,8 b' def _runcommand(ui, options, cmd, cmdfun' | |||||
967 | try: |
|
991 | try: | |
968 | if profiler == 'ls': |
|
992 | if profiler == 'ls': | |
969 | return lsprofile(ui, checkargs, fp) |
|
993 | return lsprofile(ui, checkargs, fp) | |
|
994 | elif profiler == 'flame': | |||
|
995 | return flameprofile(ui, checkargs, fp) | |||
970 | else: |
|
996 | else: | |
971 | return statprofile(ui, checkargs, fp) |
|
997 | return statprofile(ui, checkargs, fp) | |
972 | finally: |
|
998 | finally: |
General Comments 0
You need to be logged in to leave comments.
Login now