##// END OF EJS Templates
lsprofcalltree: use print function...
Gregory Szorc -
r27618:5a988b3c default
parent child Browse files
Show More
@@ -1,88 +1,86 b''
1 """
1 """
2 lsprofcalltree.py - lsprof output which is readable by kcachegrind
2 lsprofcalltree.py - lsprof output which is readable by kcachegrind
3
3
4 Authors:
4 Authors:
5 * David Allouche <david <at> allouche.net>
5 * David Allouche <david <at> allouche.net>
6 * Jp Calderone & Itamar Shtull-Trauring
6 * Jp Calderone & Itamar Shtull-Trauring
7 * Johan Dahlin
7 * Johan Dahlin
8
8
9 This software may be used and distributed according to the terms
9 This software may be used and distributed according to the terms
10 of the GNU General Public License, incorporated herein by reference.
10 of the GNU General Public License, incorporated herein by reference.
11 """
11 """
12
12
13 from __future__ import absolute_import
13 from __future__ import absolute_import, print_function
14
14
15 def label(code):
15 def label(code):
16 if isinstance(code, str):
16 if isinstance(code, str):
17 return '~' + code # built-in functions ('~' sorts at the end)
17 return '~' + code # built-in functions ('~' sorts at the end)
18 else:
18 else:
19 return '%s %s:%d' % (code.co_name,
19 return '%s %s:%d' % (code.co_name,
20 code.co_filename,
20 code.co_filename,
21 code.co_firstlineno)
21 code.co_firstlineno)
22
22
23 class KCacheGrind(object):
23 class KCacheGrind(object):
24 def __init__(self, profiler):
24 def __init__(self, profiler):
25 self.data = profiler.getstats()
25 self.data = profiler.getstats()
26 self.out_file = None
26 self.out_file = None
27
27
28 def output(self, out_file):
28 def output(self, out_file):
29 self.out_file = out_file
29 self.out_file = out_file
30 print >> out_file, 'events: Ticks'
30 print('events: Ticks', file=out_file)
31 self._print_summary()
31 self._print_summary()
32 for entry in self.data:
32 for entry in self.data:
33 self._entry(entry)
33 self._entry(entry)
34
34
35 def _print_summary(self):
35 def _print_summary(self):
36 max_cost = 0
36 max_cost = 0
37 for entry in self.data:
37 for entry in self.data:
38 totaltime = int(entry.totaltime * 1000)
38 totaltime = int(entry.totaltime * 1000)
39 max_cost = max(max_cost, totaltime)
39 max_cost = max(max_cost, totaltime)
40 print >> self.out_file, 'summary: %d' % (max_cost,)
40 print('summary: %d' % max_cost, file=self.out_file)
41
41
42 def _entry(self, entry):
42 def _entry(self, entry):
43 out_file = self.out_file
43 out_file = self.out_file
44
44
45 code = entry.code
45 code = entry.code
46 #print >> out_file, 'ob=%s' % (code.co_filename,)
47 if isinstance(code, str):
46 if isinstance(code, str):
48 print >> out_file, 'fi=~'
47 print('fi=~', file=out_file)
49 else:
48 else:
50 print >> out_file, 'fi=%s' % (code.co_filename,)
49 print('fi=%s' % code.co_filename, file=out_file)
51 print >> out_file, 'fn=%s' % (label(code),)
50 print('fn=%s' % label(code), file=out_file)
52
51
53 inlinetime = int(entry.inlinetime * 1000)
52 inlinetime = int(entry.inlinetime * 1000)
54 if isinstance(code, str):
53 if isinstance(code, str):
55 print >> out_file, '0 ', inlinetime
54 print('0 ', inlinetime, file=out_file)
56 else:
55 else:
57 print >> out_file, '%d %d' % (code.co_firstlineno, inlinetime)
56 print('%d %d' % (code.co_firstlineno, inlinetime), file=out_file)
58
57
59 # recursive calls are counted in entry.calls
58 # recursive calls are counted in entry.calls
60 if entry.calls:
59 if entry.calls:
61 calls = entry.calls
60 calls = entry.calls
62 else:
61 else:
63 calls = []
62 calls = []
64
63
65 if isinstance(code, str):
64 if isinstance(code, str):
66 lineno = 0
65 lineno = 0
67 else:
66 else:
68 lineno = code.co_firstlineno
67 lineno = code.co_firstlineno
69
68
70 for subentry in calls:
69 for subentry in calls:
71 self._subentry(lineno, subentry)
70 self._subentry(lineno, subentry)
72 print >> out_file
71 print(file=out_file)
73
72
74 def _subentry(self, lineno, subentry):
73 def _subentry(self, lineno, subentry):
75 out_file = self.out_file
74 out_file = self.out_file
76 code = subentry.code
75 code = subentry.code
77 #print >> out_file, 'cob=%s' % (code.co_filename,)
76 print('cfn=%s' % label(code), file=out_file)
78 print >> out_file, 'cfn=%s' % (label(code),)
79 if isinstance(code, str):
77 if isinstance(code, str):
80 print >> out_file, 'cfi=~'
78 print('cfi=~', file=out_file)
81 print >> out_file, 'calls=%d 0' % (subentry.callcount,)
79 print('calls=%d 0' % subentry.callcount, file=out_file)
82 else:
80 else:
83 print >> out_file, 'cfi=%s' % (code.co_filename,)
81 print('cfi=%s' % code.co_filename, file=out_file)
84 print >> out_file, 'calls=%d %d' % (
82 print('calls=%d %d' % (
85 subentry.callcount, code.co_firstlineno)
83 subentry.callcount, code.co_firstlineno), file=out_file)
86
84
87 totaltime = int(subentry.totaltime * 1000)
85 totaltime = int(subentry.totaltime * 1000)
88 print >> out_file, '%d %d' % (lineno, totaltime)
86 print('%d %d' % (lineno, totaltime), file=out_file)
@@ -1,183 +1,182 b''
1 #require test-repo
1 #require test-repo
2
2
3 $ cd "$TESTDIR"/..
3 $ cd "$TESTDIR"/..
4
4
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
5 $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs python contrib/check-py3-compat.py
6 contrib/casesmash.py not using absolute_import
6 contrib/casesmash.py not using absolute_import
7 contrib/check-code.py not using absolute_import
7 contrib/check-code.py not using absolute_import
8 contrib/check-code.py requires print_function
8 contrib/check-code.py requires print_function
9 contrib/check-config.py not using absolute_import
9 contrib/check-config.py not using absolute_import
10 contrib/check-config.py requires print_function
10 contrib/check-config.py requires print_function
11 contrib/debugcmdserver.py not using absolute_import
11 contrib/debugcmdserver.py not using absolute_import
12 contrib/debugcmdserver.py requires print_function
12 contrib/debugcmdserver.py requires print_function
13 contrib/debugshell.py not using absolute_import
13 contrib/debugshell.py not using absolute_import
14 contrib/fixpax.py not using absolute_import
14 contrib/fixpax.py not using absolute_import
15 contrib/fixpax.py requires print_function
15 contrib/fixpax.py requires print_function
16 contrib/hgclient.py not using absolute_import
16 contrib/hgclient.py not using absolute_import
17 contrib/hgclient.py requires print_function
17 contrib/hgclient.py requires print_function
18 contrib/hgfixes/fix_bytes.py not using absolute_import
18 contrib/hgfixes/fix_bytes.py not using absolute_import
19 contrib/hgfixes/fix_bytesmod.py not using absolute_import
19 contrib/hgfixes/fix_bytesmod.py not using absolute_import
20 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
20 contrib/hgfixes/fix_leftover_imports.py not using absolute_import
21 contrib/import-checker.py not using absolute_import
21 contrib/import-checker.py not using absolute_import
22 contrib/import-checker.py requires print_function
22 contrib/import-checker.py requires print_function
23 contrib/memory.py not using absolute_import
23 contrib/memory.py not using absolute_import
24 contrib/perf.py not using absolute_import
24 contrib/perf.py not using absolute_import
25 contrib/python-hook-examples.py not using absolute_import
25 contrib/python-hook-examples.py not using absolute_import
26 contrib/revsetbenchmarks.py not using absolute_import
26 contrib/revsetbenchmarks.py not using absolute_import
27 contrib/revsetbenchmarks.py requires print_function
27 contrib/revsetbenchmarks.py requires print_function
28 contrib/showstack.py not using absolute_import
28 contrib/showstack.py not using absolute_import
29 contrib/synthrepo.py not using absolute_import
29 contrib/synthrepo.py not using absolute_import
30 contrib/win32/hgwebdir_wsgi.py not using absolute_import
30 contrib/win32/hgwebdir_wsgi.py not using absolute_import
31 doc/check-seclevel.py not using absolute_import
31 doc/check-seclevel.py not using absolute_import
32 doc/gendoc.py not using absolute_import
32 doc/gendoc.py not using absolute_import
33 doc/hgmanpage.py not using absolute_import
33 doc/hgmanpage.py not using absolute_import
34 hgext/__init__.py not using absolute_import
34 hgext/__init__.py not using absolute_import
35 hgext/acl.py not using absolute_import
35 hgext/acl.py not using absolute_import
36 hgext/blackbox.py not using absolute_import
36 hgext/blackbox.py not using absolute_import
37 hgext/bugzilla.py not using absolute_import
37 hgext/bugzilla.py not using absolute_import
38 hgext/censor.py not using absolute_import
38 hgext/censor.py not using absolute_import
39 hgext/children.py not using absolute_import
39 hgext/children.py not using absolute_import
40 hgext/churn.py not using absolute_import
40 hgext/churn.py not using absolute_import
41 hgext/clonebundles.py not using absolute_import
41 hgext/clonebundles.py not using absolute_import
42 hgext/color.py not using absolute_import
42 hgext/color.py not using absolute_import
43 hgext/convert/__init__.py not using absolute_import
43 hgext/convert/__init__.py not using absolute_import
44 hgext/convert/bzr.py not using absolute_import
44 hgext/convert/bzr.py not using absolute_import
45 hgext/convert/common.py not using absolute_import
45 hgext/convert/common.py not using absolute_import
46 hgext/convert/convcmd.py not using absolute_import
46 hgext/convert/convcmd.py not using absolute_import
47 hgext/convert/cvs.py not using absolute_import
47 hgext/convert/cvs.py not using absolute_import
48 hgext/convert/cvsps.py not using absolute_import
48 hgext/convert/cvsps.py not using absolute_import
49 hgext/convert/darcs.py not using absolute_import
49 hgext/convert/darcs.py not using absolute_import
50 hgext/convert/filemap.py not using absolute_import
50 hgext/convert/filemap.py not using absolute_import
51 hgext/convert/git.py not using absolute_import
51 hgext/convert/git.py not using absolute_import
52 hgext/convert/gnuarch.py not using absolute_import
52 hgext/convert/gnuarch.py not using absolute_import
53 hgext/convert/hg.py not using absolute_import
53 hgext/convert/hg.py not using absolute_import
54 hgext/convert/monotone.py not using absolute_import
54 hgext/convert/monotone.py not using absolute_import
55 hgext/convert/p4.py not using absolute_import
55 hgext/convert/p4.py not using absolute_import
56 hgext/convert/subversion.py not using absolute_import
56 hgext/convert/subversion.py not using absolute_import
57 hgext/convert/transport.py not using absolute_import
57 hgext/convert/transport.py not using absolute_import
58 hgext/eol.py not using absolute_import
58 hgext/eol.py not using absolute_import
59 hgext/extdiff.py not using absolute_import
59 hgext/extdiff.py not using absolute_import
60 hgext/factotum.py not using absolute_import
60 hgext/factotum.py not using absolute_import
61 hgext/fetch.py not using absolute_import
61 hgext/fetch.py not using absolute_import
62 hgext/gpg.py not using absolute_import
62 hgext/gpg.py not using absolute_import
63 hgext/graphlog.py not using absolute_import
63 hgext/graphlog.py not using absolute_import
64 hgext/hgcia.py not using absolute_import
64 hgext/hgcia.py not using absolute_import
65 hgext/hgk.py not using absolute_import
65 hgext/hgk.py not using absolute_import
66 hgext/highlight/__init__.py not using absolute_import
66 hgext/highlight/__init__.py not using absolute_import
67 hgext/highlight/highlight.py not using absolute_import
67 hgext/highlight/highlight.py not using absolute_import
68 hgext/histedit.py not using absolute_import
68 hgext/histedit.py not using absolute_import
69 hgext/keyword.py not using absolute_import
69 hgext/keyword.py not using absolute_import
70 hgext/largefiles/__init__.py not using absolute_import
70 hgext/largefiles/__init__.py not using absolute_import
71 hgext/largefiles/basestore.py not using absolute_import
71 hgext/largefiles/basestore.py not using absolute_import
72 hgext/largefiles/lfcommands.py not using absolute_import
72 hgext/largefiles/lfcommands.py not using absolute_import
73 hgext/largefiles/lfutil.py not using absolute_import
73 hgext/largefiles/lfutil.py not using absolute_import
74 hgext/largefiles/localstore.py not using absolute_import
74 hgext/largefiles/localstore.py not using absolute_import
75 hgext/largefiles/overrides.py not using absolute_import
75 hgext/largefiles/overrides.py not using absolute_import
76 hgext/largefiles/proto.py not using absolute_import
76 hgext/largefiles/proto.py not using absolute_import
77 hgext/largefiles/remotestore.py not using absolute_import
77 hgext/largefiles/remotestore.py not using absolute_import
78 hgext/largefiles/reposetup.py not using absolute_import
78 hgext/largefiles/reposetup.py not using absolute_import
79 hgext/largefiles/uisetup.py not using absolute_import
79 hgext/largefiles/uisetup.py not using absolute_import
80 hgext/largefiles/wirestore.py not using absolute_import
80 hgext/largefiles/wirestore.py not using absolute_import
81 hgext/mq.py not using absolute_import
81 hgext/mq.py not using absolute_import
82 hgext/notify.py not using absolute_import
82 hgext/notify.py not using absolute_import
83 hgext/pager.py not using absolute_import
83 hgext/pager.py not using absolute_import
84 hgext/patchbomb.py not using absolute_import
84 hgext/patchbomb.py not using absolute_import
85 hgext/purge.py not using absolute_import
85 hgext/purge.py not using absolute_import
86 hgext/rebase.py not using absolute_import
86 hgext/rebase.py not using absolute_import
87 hgext/record.py not using absolute_import
87 hgext/record.py not using absolute_import
88 hgext/relink.py not using absolute_import
88 hgext/relink.py not using absolute_import
89 hgext/schemes.py not using absolute_import
89 hgext/schemes.py not using absolute_import
90 hgext/share.py not using absolute_import
90 hgext/share.py not using absolute_import
91 hgext/shelve.py not using absolute_import
91 hgext/shelve.py not using absolute_import
92 hgext/strip.py not using absolute_import
92 hgext/strip.py not using absolute_import
93 hgext/transplant.py not using absolute_import
93 hgext/transplant.py not using absolute_import
94 hgext/win32mbcs.py not using absolute_import
94 hgext/win32mbcs.py not using absolute_import
95 hgext/win32text.py not using absolute_import
95 hgext/win32text.py not using absolute_import
96 hgext/zeroconf/Zeroconf.py not using absolute_import
96 hgext/zeroconf/Zeroconf.py not using absolute_import
97 hgext/zeroconf/Zeroconf.py requires print_function
97 hgext/zeroconf/Zeroconf.py requires print_function
98 hgext/zeroconf/__init__.py not using absolute_import
98 hgext/zeroconf/__init__.py not using absolute_import
99 i18n/check-translation.py not using absolute_import
99 i18n/check-translation.py not using absolute_import
100 i18n/polib.py not using absolute_import
100 i18n/polib.py not using absolute_import
101 mercurial/cmdutil.py not using absolute_import
101 mercurial/cmdutil.py not using absolute_import
102 mercurial/commands.py not using absolute_import
102 mercurial/commands.py not using absolute_import
103 mercurial/lsprofcalltree.py requires print_function
104 mercurial/mail.py requires print_function
103 mercurial/mail.py requires print_function
105 setup.py not using absolute_import
104 setup.py not using absolute_import
106 tests/filterpyflakes.py requires print_function
105 tests/filterpyflakes.py requires print_function
107 tests/generate-working-copy-states.py requires print_function
106 tests/generate-working-copy-states.py requires print_function
108 tests/get-with-headers.py requires print_function
107 tests/get-with-headers.py requires print_function
109 tests/heredoctest.py requires print_function
108 tests/heredoctest.py requires print_function
110 tests/hypothesishelpers.py not using absolute_import
109 tests/hypothesishelpers.py not using absolute_import
111 tests/hypothesishelpers.py requires print_function
110 tests/hypothesishelpers.py requires print_function
112 tests/killdaemons.py not using absolute_import
111 tests/killdaemons.py not using absolute_import
113 tests/md5sum.py not using absolute_import
112 tests/md5sum.py not using absolute_import
114 tests/mockblackbox.py not using absolute_import
113 tests/mockblackbox.py not using absolute_import
115 tests/printenv.py not using absolute_import
114 tests/printenv.py not using absolute_import
116 tests/readlink.py not using absolute_import
115 tests/readlink.py not using absolute_import
117 tests/readlink.py requires print_function
116 tests/readlink.py requires print_function
118 tests/revlog-formatv0.py not using absolute_import
117 tests/revlog-formatv0.py not using absolute_import
119 tests/run-tests.py not using absolute_import
118 tests/run-tests.py not using absolute_import
120 tests/seq.py not using absolute_import
119 tests/seq.py not using absolute_import
121 tests/seq.py requires print_function
120 tests/seq.py requires print_function
122 tests/silenttestrunner.py not using absolute_import
121 tests/silenttestrunner.py not using absolute_import
123 tests/silenttestrunner.py requires print_function
122 tests/silenttestrunner.py requires print_function
124 tests/sitecustomize.py not using absolute_import
123 tests/sitecustomize.py not using absolute_import
125 tests/svn-safe-append.py not using absolute_import
124 tests/svn-safe-append.py not using absolute_import
126 tests/svnxml.py not using absolute_import
125 tests/svnxml.py not using absolute_import
127 tests/test-ancestor.py requires print_function
126 tests/test-ancestor.py requires print_function
128 tests/test-atomictempfile.py not using absolute_import
127 tests/test-atomictempfile.py not using absolute_import
129 tests/test-batching.py not using absolute_import
128 tests/test-batching.py not using absolute_import
130 tests/test-batching.py requires print_function
129 tests/test-batching.py requires print_function
131 tests/test-bdiff.py not using absolute_import
130 tests/test-bdiff.py not using absolute_import
132 tests/test-bdiff.py requires print_function
131 tests/test-bdiff.py requires print_function
133 tests/test-context.py not using absolute_import
132 tests/test-context.py not using absolute_import
134 tests/test-context.py requires print_function
133 tests/test-context.py requires print_function
135 tests/test-demandimport.py not using absolute_import
134 tests/test-demandimport.py not using absolute_import
136 tests/test-demandimport.py requires print_function
135 tests/test-demandimport.py requires print_function
137 tests/test-dispatch.py not using absolute_import
136 tests/test-dispatch.py not using absolute_import
138 tests/test-dispatch.py requires print_function
137 tests/test-dispatch.py requires print_function
139 tests/test-doctest.py not using absolute_import
138 tests/test-doctest.py not using absolute_import
140 tests/test-duplicateoptions.py not using absolute_import
139 tests/test-duplicateoptions.py not using absolute_import
141 tests/test-duplicateoptions.py requires print_function
140 tests/test-duplicateoptions.py requires print_function
142 tests/test-filecache.py not using absolute_import
141 tests/test-filecache.py not using absolute_import
143 tests/test-filecache.py requires print_function
142 tests/test-filecache.py requires print_function
144 tests/test-filelog.py not using absolute_import
143 tests/test-filelog.py not using absolute_import
145 tests/test-filelog.py requires print_function
144 tests/test-filelog.py requires print_function
146 tests/test-hg-parseurl.py not using absolute_import
145 tests/test-hg-parseurl.py not using absolute_import
147 tests/test-hg-parseurl.py requires print_function
146 tests/test-hg-parseurl.py requires print_function
148 tests/test-hgweb-auth.py not using absolute_import
147 tests/test-hgweb-auth.py not using absolute_import
149 tests/test-hgweb-auth.py requires print_function
148 tests/test-hgweb-auth.py requires print_function
150 tests/test-hgwebdir-paths.py not using absolute_import
149 tests/test-hgwebdir-paths.py not using absolute_import
151 tests/test-hybridencode.py not using absolute_import
150 tests/test-hybridencode.py not using absolute_import
152 tests/test-hybridencode.py requires print_function
151 tests/test-hybridencode.py requires print_function
153 tests/test-lrucachedict.py not using absolute_import
152 tests/test-lrucachedict.py not using absolute_import
154 tests/test-lrucachedict.py requires print_function
153 tests/test-lrucachedict.py requires print_function
155 tests/test-manifest.py not using absolute_import
154 tests/test-manifest.py not using absolute_import
156 tests/test-minirst.py not using absolute_import
155 tests/test-minirst.py not using absolute_import
157 tests/test-minirst.py requires print_function
156 tests/test-minirst.py requires print_function
158 tests/test-parseindex2.py not using absolute_import
157 tests/test-parseindex2.py not using absolute_import
159 tests/test-parseindex2.py requires print_function
158 tests/test-parseindex2.py requires print_function
160 tests/test-pathencode.py not using absolute_import
159 tests/test-pathencode.py not using absolute_import
161 tests/test-pathencode.py requires print_function
160 tests/test-pathencode.py requires print_function
162 tests/test-propertycache.py not using absolute_import
161 tests/test-propertycache.py not using absolute_import
163 tests/test-propertycache.py requires print_function
162 tests/test-propertycache.py requires print_function
164 tests/test-revlog-ancestry.py not using absolute_import
163 tests/test-revlog-ancestry.py not using absolute_import
165 tests/test-revlog-ancestry.py requires print_function
164 tests/test-revlog-ancestry.py requires print_function
166 tests/test-run-tests.py not using absolute_import
165 tests/test-run-tests.py not using absolute_import
167 tests/test-simplemerge.py not using absolute_import
166 tests/test-simplemerge.py not using absolute_import
168 tests/test-status-inprocess.py not using absolute_import
167 tests/test-status-inprocess.py not using absolute_import
169 tests/test-status-inprocess.py requires print_function
168 tests/test-status-inprocess.py requires print_function
170 tests/test-symlink-os-yes-fs-no.py not using absolute_import
169 tests/test-symlink-os-yes-fs-no.py not using absolute_import
171 tests/test-trusted.py not using absolute_import
170 tests/test-trusted.py not using absolute_import
172 tests/test-trusted.py requires print_function
171 tests/test-trusted.py requires print_function
173 tests/test-ui-color.py not using absolute_import
172 tests/test-ui-color.py not using absolute_import
174 tests/test-ui-color.py requires print_function
173 tests/test-ui-color.py requires print_function
175 tests/test-ui-config.py not using absolute_import
174 tests/test-ui-config.py not using absolute_import
176 tests/test-ui-config.py requires print_function
175 tests/test-ui-config.py requires print_function
177 tests/test-ui-verbosity.py not using absolute_import
176 tests/test-ui-verbosity.py not using absolute_import
178 tests/test-ui-verbosity.py requires print_function
177 tests/test-ui-verbosity.py requires print_function
179 tests/test-url.py not using absolute_import
178 tests/test-url.py not using absolute_import
180 tests/test-url.py requires print_function
179 tests/test-url.py requires print_function
181 tests/test-walkrepo.py requires print_function
180 tests/test-walkrepo.py requires print_function
182 tests/test-wireproto.py requires print_function
181 tests/test-wireproto.py requires print_function
183 tests/tinyproxy.py requires print_function
182 tests/tinyproxy.py requires print_function
General Comments 0
You need to be logged in to leave comments. Login now