Skip to content

Commit 9d73dd0

Browse files
committed
add with profile block
1 parent efed434 commit 9d73dd0

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
@@ -28,6 +28,16 @@
2828

2929
@wrapt.decorator
3030
def profile_method(wrapped, instance, args, kwargs):
31+
"""
32+
33+
Profile method decorator
34+
Usage:
35+
36+
from template_profiler_panel.panels.template import profile_method
37+
@profile method
38+
def method():
39+
...
40+
"""
3141
start = time()
3242

3343
result = wrapped(*args, **kwargs)
@@ -48,6 +58,34 @@ def profile_method(wrapped, instance, args, kwargs):
4858
return result
4959

5060

61+
class Profile:
62+
"""
63+
Profile with block
64+
Usage:
65+
66+
from template_profiler_panel.panels.template import Profile
67+
with Profile("block name"):
68+
...
69+
"""
70+
def __init__(self, name="Profile with", *args, **kwargs):
71+
self.name = name
72+
73+
def __enter__(self):
74+
self.start = time()
75+
76+
def __exit__(self, type, value, traceback):
77+
self.end = time()
78+
79+
template_rendered.send(
80+
sender=self.__class__,
81+
instance=self.name,
82+
start=self.start,
83+
end=self.end,
84+
processing_timeline=[],
85+
level=1,
86+
)
87+
88+
5189
def get_nodelist_timeline(nodelist, level):
5290
timeline = []
5391
for node in nodelist:

0 commit comments

Comments
 (0)