Mercurial > hg-stable
annotate mercurial/lsprofcalltree.py @ 33278:87bca10a06ed
transaction: avoid file stat ambiguity only for files in blacklist
Advancing mtime by os.utime() fails for EPERM, if the target file is
owned by another. bff5ccbe5ead and related changes made some code
paths give advancing mtime up in such case, to fix issue5418.
This causes file stat ambiguity (again), if it is owned by another.
https://www.mercurial-scm.org/wiki/ExactCacheValidationPlan
To avoid file stat ambiguity in such case, especially for
.hg/dirstate, ed66ec39933f made vfs.rename() copy the target file, and
advance mtime of renamed one again, if EPERM (see issue5584 for detail).
But straightforward "copy if EPERM" isn't reasonable for truncation of
append-only files at rollbacking, because rollbacking might cost much
for truncation of many filelogs, even though filelogs aren't
filecache-ed.
Therefore, this patch introduces blacklist "checkambigfiles", and
avoids file stat ambiguity only for files specified in this blacklist.
This patch consists of two parts below, which should be applied at
once in order to avoid regression.
- specify 'checkambig=True' at vfs.open(mode='a') in _playback()
according to checkambigfiles
- invoke _playback() with checkambigfiles
- add transaction.__init__() checkambigfiles argument, for _abort()
- make localrepo instantiate transaction with _cachedfiles
- add rollback() checkambigfiles argument, for "hg rollback/recover"
- make localrepo invoke rollback() with _cachedfiles
After this patch, straightforward "copy if EPERM" will be reasonable
at closing the file opened with checkambig=True, because this policy
is applied only on files, which are listed in blacklist
"checkambigfiles".
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 04 Jul 2017 23:13:46 +0900 |
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) |