diff options
author | Alexey Yelistratov <ayelistratov@mirantis.com> | 2016-06-24 17:58:46 +0300 |
---|---|---|
committer | Dina Belova <dbelova@mirantis.com> | 2016-08-04 11:07:15 -0700 |
commit | f1824b90b4610791bba87da52b4c145452be0d26 (patch) | |
tree | d25f90e585685f555dc492f79863b21a9725407f | |
parent | 8936362cd797c56dcd2f54cf0df75daad3a33ba0 (diff) | |
download | osprofiler-f1824b90b4610791bba87da52b4c145452be0d26.tar.gz |
Add overall profiler stats by operation
Change-Id: I07f0dd1bcb15edba4c0184b9c16747fd1bdac840
-rw-r--r-- | osprofiler/drivers/base.py | 25 | ||||
-rw-r--r-- | osprofiler/tests/drivers/test_ceilometer.py | 8 |
2 files changed, 27 insertions, 6 deletions
diff --git a/osprofiler/drivers/base.py b/osprofiler/drivers/base.py index 3c34838..37f3e5e 100644 --- a/osprofiler/drivers/base.py +++ b/osprofiler/drivers/base.py @@ -197,6 +197,8 @@ class Driver(object): 1e6) return int(microsec / 1000.0) + stats = {} + for r in self.result.values(): # NOTE(boris-42): We are not able to guarantee that the backend # consumed all messages => so we should at make duration 0ms. @@ -206,9 +208,23 @@ class Driver(object): if "finished" not in r["info"]: r["info"]["finished"] = r["info"]["started"] - r["info"]["started"] = msec(r["info"]["started"] - self.started_at) - r["info"]["finished"] = msec(r["info"]["finished"] - - self.started_at) + op_type = r["info"]["name"] + op_started = msec(r["info"]["started"] - self.started_at) + op_finished = msec(r["info"]["finished"] - + self.started_at) + duration = op_finished - op_started + + r["info"]["started"] = op_started + r["info"]["finished"] = op_finished + + if op_type not in stats: + stats[op_type] = { + "count": 1, + "duration": duration + } + else: + stats[op_type]["count"] += 1 + stats[op_type]["duration"] += duration return { "info": { @@ -217,5 +233,6 @@ class Driver(object): "finished": msec(self.finished_at - self.started_at) if self.started_at else None }, - "children": self._build_tree(self.result) + "children": self._build_tree(self.result), + "stats": stats } diff --git a/osprofiler/tests/drivers/test_ceilometer.py b/osprofiler/tests/drivers/test_ceilometer.py index 6987ce7..10ccebe 100644 --- a/osprofiler/tests/drivers/test_ceilometer.py +++ b/osprofiler/tests/drivers/test_ceilometer.py @@ -90,7 +90,8 @@ class CeilometerParserTestCase(test.TestCase): "started": 0, "finished": None }, - "children": [] + "children": [], + "stats": {}, } base_id = "10" @@ -399,7 +400,10 @@ class CeilometerParserTestCase(test.TestCase): "started": 88}, "parent_id": "7253ca8c-33b3-4f84-b4f1-f5a4311ddfa4", "trace_id": "016c97fd-87f3-40b2-9b55-e431156b694b"}], - "info": {"finished": 88, "name": "total", "started": 0}} + "info": {"finished": 88, "name": "total", "started": 0}, + "stats": {"db": {"count": 1, "duration": 20}, + "wsgi": {"count": 2, "duration": -47}}, + } base_id = "10" |