Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/statprof.py @ 42847:cde1c101ab8a
py3: make statprof's chrome output work
With this patch, this command works:
python3 hg --profile --config profiling.statformat=chrome st
(and it works with s/python3/python2/ as well)
Differential Revision: https://phab.mercurial-scm.org/D6777
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sat, 31 Aug 2019 10:26:39 -0700 |
parents | cd3b5be5515d |
children | 9a3be115fb78 |
comparison
equal
deleted
inserted
replaced
42846:cd3b5be5515d | 42847:cde1c101ab8a |
---|---|
757 removing whatever part of the Python search path it was found | 757 removing whatever part of the Python search path it was found |
758 on.''' | 758 on.''' |
759 | 759 |
760 if path in _pathcache: | 760 if path in _pathcache: |
761 return _pathcache[path] | 761 return _pathcache[path] |
762 hgpath = pycompat.fsencode(encoding.__file__).rsplit(os.sep, 2)[0] | 762 hgpath = encoding.__file__.rsplit(os.sep, 2)[0] |
763 for p in [hgpath] + sys.path: | 763 for p in [hgpath] + sys.path: |
764 prefix = p + os.sep | 764 prefix = p + os.sep |
765 if path.startswith(prefix): | 765 if path.startswith(prefix): |
766 path = path[len(prefix):] | 766 path = path[len(prefix):] |
767 break | 767 break |
805 if stack in stack2id: | 805 if stack in stack2id: |
806 return stack2id[stack] | 806 return stack2id[stack] |
807 parent = stackid(stack[1:]) | 807 parent = stackid(stack[1:]) |
808 myid = len(stack2id) | 808 myid = len(stack2id) |
809 stack2id[stack] = myid | 809 stack2id[stack] = myid |
810 id2stack.append(dict(category=stack[0][0], name='%s %s' % stack[0])) | 810 id2stack.append(dict(category=stack[0][0], name=r'%s %s' % stack[0])) |
811 if parent is not None: | 811 if parent is not None: |
812 id2stack[-1].update(parent=parent) | 812 id2stack[-1].update(parent=parent) |
813 return myid | 813 return myid |
814 | 814 |
815 # The sampling profiler can sample multiple times without | 815 # The sampling profiler can sample multiple times without |
840 oldtime, oldidx = lastseen.popleft() | 840 oldtime, oldidx = lastseen.popleft() |
841 duration = sample.time - oldtime | 841 duration = sample.time - oldtime |
842 if minthreshold <= duration <= maxthreshold: | 842 if minthreshold <= duration <= maxthreshold: |
843 # ensure no zero-duration events | 843 # ensure no zero-duration events |
844 sampletime = max(oldtime + clamp, sample.time) | 844 sampletime = max(oldtime + clamp, sample.time) |
845 samples.append(dict(ph='E', name=oldfunc, cat=oldcat, sf=oldsid, | 845 samples.append(dict(ph=r'E', name=oldfunc, cat=oldcat, sf=oldsid, |
846 ts=sampletime*1e6, pid=0)) | 846 ts=sampletime*1e6, pid=0)) |
847 else: | 847 else: |
848 blacklist.add(oldidx) | 848 blacklist.add(oldidx) |
849 | 849 |
850 # Much fiddling to synthesize correctly(ish) nested begin/end | 850 # Much fiddling to synthesize correctly(ish) nested begin/end |
851 # events given only stack snapshots. | 851 # events given only stack snapshots. |
852 | 852 |
853 for sample in data.samples: | 853 for sample in data.samples: |
854 stack = tuple((('%s:%d' % (simplifypath(frame.path), frame.lineno), | 854 stack = tuple(((r'%s:%d' % (simplifypath(pycompat.sysstr(frame.path)), |
855 frame.function) for frame in sample.stack)) | 855 frame.lineno), |
856 pycompat.sysstr(frame.function)) | |
857 for frame in sample.stack)) | |
856 qstack = collections.deque(stack) | 858 qstack = collections.deque(stack) |
857 if laststack == qstack: | 859 if laststack == qstack: |
858 continue | 860 continue |
859 while laststack and qstack and laststack[-1] == qstack[-1]: | 861 while laststack and qstack and laststack[-1] == qstack[-1]: |
860 laststack.pop() | 862 laststack.pop() |
864 for f in reversed(qstack): | 866 for f in reversed(qstack): |
865 lastseen.appendleft((sample.time, len(samples))) | 867 lastseen.appendleft((sample.time, len(samples))) |
866 laststack.appendleft(f) | 868 laststack.appendleft(f) |
867 path, name = f | 869 path, name = f |
868 sid = stackid(tuple(laststack)) | 870 sid = stackid(tuple(laststack)) |
869 samples.append(dict(ph='B', name=name, cat=path, ts=sample.time*1e6, | 871 samples.append(dict(ph=r'B', name=name, cat=path, |
870 sf=sid, pid=0)) | 872 ts=sample.time*1e6, sf=sid, pid=0)) |
871 laststack = collections.deque(stack) | 873 laststack = collections.deque(stack) |
872 while laststack: | 874 while laststack: |
873 poplast() | 875 poplast() |
874 events = [sample for idx, sample in enumerate(samples) | 876 events = [sample for idx, sample in enumerate(samples) |
875 if idx not in blacklist] | 877 if idx not in blacklist] |