diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-05-19 11:30:28 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-05-19 11:30:28 +0000 |
commit | 9d410faa31d5d9039f72a4cf9e72a6622dca5fca (patch) | |
tree | e2e402a3267a3febf0f27bde0ee0203f9b1f5de6 | |
parent | aedfd079f11831b73fd997d801fa0a44c20957d6 (diff) | |
parent | 147b96bd21834fd81ce86db03f11a5e5b31e24a2 (diff) | |
download | osprofiler-9d410faa31d5d9039f72a4cf9e72a6622dca5fca.tar.gz |
Merge "Add exception type to stop trace info"
-rw-r--r-- | osprofiler/profiler.py | 6 | ||||
-rw-r--r-- | osprofiler/tests/test_profiler.py | 12 |
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): |