Skip to content

Commit fb41292

Browse files
Trace module return file name and line number of a object
1 parent 0e4120b commit fb41292

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/outliner/modules/trace.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import collections
33

4+
from pathlib import Path
45
from ..views import RunningObject
56

67

@@ -10,20 +11,30 @@ class ExceptionWhileTracing(Exception):
1011
pass
1112

1213

13-
14-
1514
class Trace:
1615

1716
def __init__(self):
1817
self.detailed_data = collections.defaultdict(
19-
lambda: {"call": 0, "return": 0, "line": 0, "exception": 0}
18+
lambda: {
19+
"call": 0,
20+
"return": 0,
21+
"line": 0,
22+
"exception": 0,
23+
"file": Path(),
24+
"start_line": int,
25+
}
2026
)
2127
self.functions_flow = collections.OrderedDict()
2228

2329
def _trace_function(self, frame, event, arg):
2430
self.detailed_data[frame.f_code.co_name][str(event)] += 1
2531
self.functions_flow[frame.f_code.co_name] = None
26-
32+
self.detailed_data[frame.f_code.co_name]["file"] = Path(
33+
frame.f_code.co_filename
34+
)
35+
self.detailed_data[frame.f_code.co_name][
36+
"start_line"
37+
] = frame.f_code.co_firstlineno
2738
if str(event) == "exception":
2839
raise ExceptionWhileTracing()
2940

@@ -46,6 +57,9 @@ def trace_obj(self, running_obj: RunningObject):
4657
raise Exception(f"Given object '{running_obj}' is not callable.")
4758
self._running_trace(running_obj)
4859

60+
def abc(self):
61+
print("")
62+
4963
def __str__(self):
5064
text = "Trace object\nrunned objects:\n "
5165

0 commit comments

Comments
 (0)