Mercurial > hg
annotate mercurial/lsprofcalltree.py @ 38486:4c0683655599
namespaces: let namespaces override singlenode() definition
Some namespaces have multiple nodes per name (meaning that their
namemap() returns multiple nodes). One such namespace is the "topics"
namespace (from the evolve repo). We also have our own internal
namespace at Google (for review units) that has multiple nodes per
name. These namespaces may not want to use the default "pick highest
revnum" resolution that we currently use when resolving a name to a
single node. As an example, they may decide that `hg co <name>` should
check out a commit that's last in some sense even if an earlier commit
had just been amended and thus had a higher revnum [1]. This patch
gives the namespace the option to continue to return multiple nodes
and to override how the best node is picked. Allowing namespaces to
override that may also be useful as an optimization (it may be cheaper
for the namespace to find just that node).
I have been arguing (in D3715) for using all the nodes returned from
namemap() when resolving the symbol to a revset, so e.g. `hg log -r
stable` would resolve to *all* nodes on stable, not just the one with
the highest revnum (except that I don't actually think we should
change it for the branch namespace because of BC). Most people seem
opposed to that. If we decide not to do it, I think we can deprecate
the namemap() function in favor of the new singlenode() (I find it
weird to have namespaces, like the branch namespace, where namemap()
isn't nodemap()'s inverse). I therefore think this patch makes sense
regardless of what we decide on that issue.
[1] Actually, even the branch namespace would have wanted to override
singlenode() if it had supported multiple nodes. That's because
closes branch heads are mostly ignored, so "hg co default" will
not check out the highest-revnum node if that's a closed head.
Differential Revision: https://phab.mercurial-scm.org/D3852
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 26 Jun 2018 10:02:01 -0700 |
parents | 5a988b3c9645 |
children | 1ae0faa14797 |
rev | line source |
---|---|
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
1 """ |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
2 lsprofcalltree.py - lsprof output which is readable by kcachegrind |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
3 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
4 Authors: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
5 * David Allouche <david <at> allouche.net> |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
6 * Jp Calderone & Itamar Shtull-Trauring |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
7 * Johan Dahlin |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
8 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
9 This software may be used and distributed according to the terms |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
10 of the GNU General Public License, incorporated herein by reference. |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
11 """ |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
12 |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
13 from __future__ import absolute_import, print_function |
27505
071af8d385a9
lsprofcalltree: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
8390
diff
changeset
|
14 |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
15 def label(code): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
16 if isinstance(code, str): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
17 return '~' + code # built-in functions ('~' sorts at the end) |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
18 else: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
19 return '%s %s:%d' % (code.co_name, |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
20 code.co_filename, |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
21 code.co_firstlineno) |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
22 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
23 class KCacheGrind(object): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
24 def __init__(self, profiler): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
25 self.data = profiler.getstats() |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
26 self.out_file = None |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
27 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
28 def output(self, out_file): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
29 self.out_file = out_file |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
30 print('events: Ticks', file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
31 self._print_summary() |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
32 for entry in self.data: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
33 self._entry(entry) |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
34 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
35 def _print_summary(self): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
36 max_cost = 0 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
37 for entry in self.data: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
38 totaltime = int(entry.totaltime * 1000) |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
39 max_cost = max(max_cost, totaltime) |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
40 print('summary: %d' % max_cost, file=self.out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
41 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
42 def _entry(self, entry): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
43 out_file = self.out_file |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
44 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
45 code = entry.code |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
46 if isinstance(code, str): |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
47 print('fi=~', file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
48 else: |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
49 print('fi=%s' % code.co_filename, file=out_file) |
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
50 print('fn=%s' % label(code), file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
51 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
52 inlinetime = int(entry.inlinetime * 1000) |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
53 if isinstance(code, str): |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
54 print('0 ', inlinetime, file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
55 else: |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
56 print('%d %d' % (code.co_firstlineno, inlinetime), file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
57 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
58 # recursive calls are counted in entry.calls |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
59 if entry.calls: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
60 calls = entry.calls |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
61 else: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
62 calls = [] |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
63 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
64 if isinstance(code, str): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
65 lineno = 0 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
66 else: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
67 lineno = code.co_firstlineno |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
68 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
69 for subentry in calls: |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
70 self._subentry(lineno, subentry) |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
71 print(file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
72 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
73 def _subentry(self, lineno, subentry): |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
74 out_file = self.out_file |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
75 code = subentry.code |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
76 print('cfn=%s' % label(code), file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
77 if isinstance(code, str): |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
78 print('cfi=~', file=out_file) |
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
79 print('calls=%d 0' % subentry.callcount, file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
80 else: |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
81 print('cfi=%s' % code.co_filename, file=out_file) |
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
82 print('calls=%d %d' % ( |
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
83 subentry.callcount, code.co_firstlineno), file=out_file) |
8024
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
84 |
9a1b86cfd29e
profiling: Adding support for kcachegrind output format, using lsprofcalltree
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
diff
changeset
|
85 totaltime = int(subentry.totaltime * 1000) |
27618
5a988b3c9645
lsprofcalltree: use print function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27505
diff
changeset
|
86 print('%d %d' % (lineno, totaltime), file=out_file) |