Skip to content

Commit 954f114

Browse files
committed
add with profile block
1 parent 6293e56 commit 954f114

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

template_profiler_panel/panels/template.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919

2020
@wrapt.decorator
2121
def profile_method(wrapped, instance, args, kwargs):
22+
"""
23+
24+
Profile method decorator
25+
Usage:
26+
27+
from template_profiler_panel.panels.template import profile_method
28+
@profile method
29+
def method():
30+
...
31+
"""
2232
start = time()
2333

2434
result = wrapped(*args, **kwargs)
@@ -39,6 +49,34 @@ def profile_method(wrapped, instance, args, kwargs):
3949
return result
4050

4151

52+
class Profile:
53+
"""
54+
Profile with block
55+
Usage:
56+
57+
from template_profiler_panel.panels.template import Profile
58+
with Profile("block name"):
59+
...
60+
"""
61+
def __init__(self, name="Profile with", *args, **kwargs):
62+
self.name = name
63+
64+
def __enter__(self):
65+
self.start = time()
66+
67+
def __exit__(self, type, value, traceback):
68+
self.end = time()
69+
70+
template_rendered.send(
71+
sender=self.__class__,
72+
instance=self.name,
73+
start=self.start,
74+
end=self.end,
75+
processing_timeline=[],
76+
level=1,
77+
)
78+
79+
4280
def get_nodelist_timeline(nodelist, level):
4381
timeline = []
4482
for node in nodelist:

0 commit comments

Comments
 (0)