Show More
@@ -1,44 +1,48 b'' | |||
|
1 | 1 | # Support code for event tracing in Mercurial. Lives in demandimport |
|
2 | 2 | # so it can also be used in demandimport. |
|
3 | 3 | # |
|
4 | 4 | # Copyright 2018 Google LLC. |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2 or any later version. |
|
8 | 8 | from __future__ import absolute_import |
|
9 | 9 | |
|
10 | 10 | import contextlib |
|
11 | 11 | import os |
|
12 | 12 | |
|
13 | 13 | _pipe = None |
|
14 | 14 | _checked = False |
|
15 | 15 | |
|
16 | @contextlib.contextmanager | |
|
17 | def log(whencefmt, *whenceargs): | |
|
16 | def _isactive(): | |
|
18 | 17 | global _pipe, _session, _checked |
|
19 | 18 | if _pipe is None: |
|
20 | 19 | if _checked: |
|
21 |
|
|
|
22 | return | |
|
20 | return False | |
|
23 | 21 | _checked = True |
|
24 | 22 | if 'HGCATAPULTSERVERPIPE' not in os.environ: |
|
23 | return False | |
|
24 | _pipe = open(os.environ['HGCATAPULTSERVERPIPE'], 'w', 1) | |
|
25 | _session = os.environ.get('HGCATAPULTSESSION', 'none') | |
|
26 | return True | |
|
27 | ||
|
28 | @contextlib.contextmanager | |
|
29 | def log(whencefmt, *whenceargs): | |
|
30 | if not _isactive(): | |
|
25 | 31 |
|
|
26 | 32 |
|
|
27 | _pipe = open(os.environ['HGCATAPULTSERVERPIPE'], 'w', 1) | |
|
28 | _session = os.environ.get('HGCATAPULTSESSION', 'none') | |
|
29 | 33 | whence = whencefmt % whenceargs |
|
30 | 34 | try: |
|
31 | 35 | # Both writes to the pipe are wrapped in try/except to ignore |
|
32 | 36 | # errors, as we can see mysterious errors in here if the pager |
|
33 | 37 | # is active. Presumably other conditions could trigger |
|
34 | 38 | # problems too. |
|
35 | 39 | try: |
|
36 | 40 | _pipe.write('START %s %s\n' % (_session, whence)) |
|
37 | 41 | except IOError: |
|
38 | 42 | pass |
|
39 | 43 | yield |
|
40 | 44 | finally: |
|
41 | 45 | try: |
|
42 | 46 | _pipe.write('END %s %s\n' % (_session, whence)) |
|
43 | 47 | except IOError: |
|
44 | 48 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now