Merge "Add exception type to stop trace info"

This commit is contained in:
Jenkins 2016-05-19 11:30:28 +00:00 committed by Gerrit Code Review
commit 9d410faa31
2 changed files with 17 additions and 1 deletions

View File

@ -314,7 +314,11 @@ class Trace(object):
start(self._name, info=self._info)
def __exit__(self, etype, value, traceback):
stop()
if etype:
info = {"etype": reflection.get_class_name(etype)}
stop(info=info)
else:
stop()
class _Profiler(object):

View File

@ -156,6 +156,18 @@ class WithTraceTestCase(test.TestCase):
mock_stop.reset_mock()
mock_stop.assert_called_once_with()
@mock.patch("osprofiler.profiler.stop")
@mock.patch("osprofiler.profiler.start")
def test_with_trace_etype(self, mock_start, mock_stop):
def foo():
with profiler.Trace("foo"):
raise ValueError("bar")
self.assertRaises(ValueError, foo)
mock_start.assert_called_once_with("foo", info=None)
mock_stop.assert_called_once_with(info={"etype": "ValueError"})
@profiler.trace("function", info={"info": "some_info"})
def tracede_func(i):