summaryrefslogtreecommitdiffstats
path: root/repo_trace.py
diff options
context:
space:
mode:
Diffstat (limited to 'repo_trace.py')
-rw-r--r--repo_trace.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/repo_trace.py b/repo_trace.py
index fcd8650e..d79408d9 100644
--- a/repo_trace.py
+++ b/repo_trace.py
@@ -57,9 +57,9 @@ def SetTrace():
57 _TRACE = True 57 _TRACE = True
58 58
59 59
60def _SetTraceFile(): 60def _SetTraceFile(quiet):
61 global _TRACE_FILE 61 global _TRACE_FILE
62 _TRACE_FILE = _GetTraceFile() 62 _TRACE_FILE = _GetTraceFile(quiet)
63 63
64 64
65class Trace(ContextDecorator): 65class Trace(ContextDecorator):
@@ -68,13 +68,21 @@ class Trace(ContextDecorator):
68 """Generate nanoseconds of time in a py3.6 safe way""" 68 """Generate nanoseconds of time in a py3.6 safe way"""
69 return int(time.time() * 1e+9) 69 return int(time.time() * 1e+9)
70 70
71 def __init__(self, fmt, *args, first_trace=False): 71 def __init__(self, fmt, *args, first_trace=False, quiet=True):
72 """Initialize the object.
73
74 Args:
75 fmt: The format string for the trace.
76 *args: Arguments to pass to formatting.
77 first_trace: Whether this is the first trace of a `repo` invocation.
78 quiet: Whether to suppress notification of trace file location.
79 """
72 if not IsTrace(): 80 if not IsTrace():
73 return 81 return
74 self._trace_msg = fmt % args 82 self._trace_msg = fmt % args
75 83
76 if not _TRACE_FILE: 84 if not _TRACE_FILE:
77 _SetTraceFile() 85 _SetTraceFile(quiet)
78 86
79 if first_trace: 87 if first_trace:
80 _ClearOldTraces() 88 _ClearOldTraces()
@@ -109,12 +117,13 @@ class Trace(ContextDecorator):
109 return False 117 return False
110 118
111 119
112def _GetTraceFile(): 120def _GetTraceFile(quiet):
113 """Get the trace file or create one.""" 121 """Get the trace file or create one."""
114 # TODO: refactor to pass repodir to Trace. 122 # TODO: refactor to pass repodir to Trace.
115 repo_dir = os.path.dirname(os.path.dirname(__file__)) 123 repo_dir = os.path.dirname(os.path.dirname(__file__))
116 trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME) 124 trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME)
117 print(f'Trace outputs in {trace_file}', file=sys.stderr) 125 if not quiet:
126 print(f'Trace outputs in {trace_file}', file=sys.stderr)
118 return trace_file 127 return trace_file
119 128
120 129