annotate mercurial/lsprofcalltree.py @ 35616:706aa203b396

fileset: add a lightweight file filtering language This patch was inspired by one that Jun Wu authored for the fb-experimental repo, to avoid using matcher for efficiency[1]. We want a way to specify what files will be converted to LFS at commit time. And per discussion, we also want to specify what files to skip, text diff, or merge in another config option. The current `lfs.threshold` config option could not satisfy complex needs. I'm putting it in a core package because Augie floated the idea of also using it for narrow and sparse. Yuya suggested farming out to fileset.parse(), which added support for more symbols. The only fileset element not supported here is 'negate'. (List isn't supported by filesets either.) I also changed the 'always' token to the 'all()' predicate for consistency, and introduced 'none()' to improve readability in a future tracked file based config. The extension operator was changed from '.' to '**', to match how recursive path globs are specified. Finally, I changed the path matcher from '/' to 'path:' at Yuya's suggestion, for consistency with matcher. Unfortunately, ':' is currently reserved in filesets, so this has to be quoted to be processed as a string instead of a symbol[2]. We should probably revisit that, because it's seriously ugly. But it's only used by an experimental extension, and I think using a file based config for LFS may drive some more tweaks, so I'm settling for this for now. I reserved all of the glob characters in fileset except '.' and '_' for the extension test because those are likely valid extension characters. Sample filter settings: all() # everything size(">20MB") # larger than 20MB !**.txt # except for .txt files **.zip | **.tar.gz | **.7z # some types of compressed files "path:bin" # files under "bin" in the project root [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-December/109387.html [2] https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-January/109729.html
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 10 Jan 2018 22:23:34 -0500
parents 5a988b3c9645
children 1ae0faa14797
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)