aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-11-27 23:12:48 +0100
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-12-05 14:56:23 +0000
commitfd574087e4b89e9c27aec1c9da60e1e91e009783 (patch)
tree52e318192dd0761f9fdc4ecf9a57a9d8afb7f207 /src
parent8b2fffd93f5f42ae35b0843c8a95681a13c84e90 (diff)
papi: add call stats
Type: feature Change-Id: Ic6d44122d3e62e09402e3f1946f7e57e9b5e7c5f Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index e6eded85a63..7f6efbbae07 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -27,6 +27,7 @@ import threading
import fnmatch
import weakref
import atexit
+import time
from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
@@ -353,6 +354,7 @@ class VPPApiClient(object):
self.use_socket = use_socket
self.server_address = server_address
self._apifiles = apifiles
+ self.stats = {}
if use_socket:
from . vpp_transport_socket import VppTransport
@@ -596,6 +598,24 @@ class VPPApiClient(object):
raise VPPValueError('Invalid argument {} to {}'
.format(list(d), msg.name))
+ def _add_stat(self, name, ms):
+ if not name in self.stats:
+ self.stats[name] = {'max': ms, 'count': 1, 'avg': ms}
+ else:
+ if ms > self.stats[name]['max']:
+ self.stats[name]['max'] = ms
+ self.stats[name]['count'] += 1
+ n = self.stats[name]['count']
+ self.stats[name]['avg'] = self.stats[name]['avg'] * (n - 1) / n + ms / n
+
+ def get_stats(self):
+ s = '\n=== API PAPI STATISTICS ===\n'
+ s += '{:<30} {:>4} {:>6} {:>6}\n'.format('message', 'cnt', 'avg', 'max')
+ for n in sorted(self.stats.items(), key=lambda v: v[1]['avg'], reverse=True):
+ s += '{:<30} {:>4} {:>6.2f} {:>6.2f}\n'.format(n[0], n[1]['count'],
+ n[1]['avg'], n[1]['max'])
+ return s
+
def _call_vpp(self, i, msgdef, multipart, **kwargs):
"""Given a message, send the message and await a reply.
@@ -611,7 +631,7 @@ class VPPApiClient(object):
the response. It will raise an IOError exception if there was
no response within the timeout window.
"""
-
+ ts = time.time()
if 'context' not in kwargs:
context = self.get_context()
kwargs['context'] = context
@@ -669,6 +689,8 @@ class VPPApiClient(object):
if len(s) > 80:
s = s[:80] + "..."
self.logger.debug(s)
+ te = time.time()
+ self._add_stat(msgdef.name, (te - ts) * 1000)
return rl
def _call_vpp_async(self, i, msg, **kwargs):