Skip to content
Snippets Groups Projects
Commit bc57d5a6 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Minor corrections to debug.Profiler

parent 5b47eff2
No related branches found
No related tags found
No related merge requests found
...@@ -430,7 +430,7 @@ class Profiler(object): ...@@ -430,7 +430,7 @@ class Profiler(object):
try: try:
caller_object_type = type(caller_frame.f_locals["self"]) caller_object_type = type(caller_frame.f_locals["self"])
except KeyError: # we are in a regular function except KeyError: # we are in a regular function
qualifier = caller_frame.f_globals["__name__"].split(".", 1)[1] qualifier = caller_frame.f_globals["__name__"].split(".", 1)[-1]
else: # we are in a method else: # we are in a method
qualifier = caller_object_type.__name__ qualifier = caller_object_type.__name__
func_qualname = qualifier + "." + caller_frame.f_code.co_name func_qualname = qualifier + "." + caller_frame.f_code.co_name
...@@ -469,6 +469,7 @@ class Profiler(object): ...@@ -469,6 +469,7 @@ class Profiler(object):
if self._delayed: if self._delayed:
self._msgs.append((msg, args)) self._msgs.append((msg, args))
else: else:
self.flush()
print(msg % args) print(msg % args)
def __del__(self): def __del__(self):
...@@ -485,10 +486,13 @@ class Profiler(object): ...@@ -485,10 +486,13 @@ class Profiler(object):
self._newMsg("< Exiting %s, total time: %0.4f ms", self._newMsg("< Exiting %s, total time: %0.4f ms",
self._name, (ptime.time() - self._firstTime) * 1000) self._name, (ptime.time() - self._firstTime) * 1000)
type(self)._depth -= 1 type(self)._depth -= 1
if self._depth < 1 and self._msgs: if self._depth < 1:
self.flush()
def flush(self):
if self._msgs:
print("\n".join([m[0]%m[1] for m in self._msgs])) print("\n".join([m[0]%m[1] for m in self._msgs]))
type(self)._msgs = [] type(self)._msgs = []
def profile(code, name='profile_run', sort='cumulative', num=30): def profile(code, name='profile_run', sort='cumulative', num=30):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment