summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-05-19 11:30:28 +0000
committerGerrit Code Review <review@openstack.org>2016-05-19 11:30:28 +0000
commit9d410faa31d5d9039f72a4cf9e72a6622dca5fca (patch)
treee2e402a3267a3febf0f27bde0ee0203f9b1f5de6
parentaedfd079f11831b73fd997d801fa0a44c20957d6 (diff)
parent147b96bd21834fd81ce86db03f11a5e5b31e24a2 (diff)
downloadosprofiler-9d410faa31d5d9039f72a4cf9e72a6622dca5fca.tar.gz
Merge "Add exception type to stop trace info"
-rw-r--r--osprofiler/profiler.py6
-rw-r--r--osprofiler/tests/test_profiler.py12
2 files changed, 17 insertions, 1 deletions
diff --git a/osprofiler/profiler.py b/osprofiler/profiler.py
index 464c327..da9c010 100644
--- a/osprofiler/profiler.py
+++ b/osprofiler/profiler.py
@@ -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):
diff --git a/osprofiler/tests/test_profiler.py b/osprofiler/tests/test_profiler.py
index 13288e7..88b96d1 100644
--- a/osprofiler/tests/test_profiler.py
+++ b/osprofiler/tests/test_profiler.py
@@ -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):