dexter has uploaded this change for review.

View Change

pySim-shell: add utility to measure execution time

It sometimes may be necessary to measure the execution time of certain
card operations. Let's add a command for that.

Related: SYS#7177
Change-Id: I356ea44e08efe93fe927dbc20564bf850278b546
---
M pySim-shell.py
1 file changed, 19 insertions(+), 1 deletion(-)

git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/59/38659/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 08f00f9..9bdd6c7 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -45,7 +45,7 @@
import inspect
from pathlib import Path
from io import StringIO
-
+from datetime import datetime
from pprint import pprint as pp

from osmocom.utils import h2b, b2h, i2h, swap_nibbles, rpad, JsonEncoder, is_hexstr, is_decimal
@@ -109,6 +109,9 @@
self.py_locals = {'card': self.card, 'rs': self.rs, 'lchan': self.lchan}
self.sl = sl
self.ch = ch
+ self.timestamp_startup = datetime.utcnow()
+ self.timestamp_last_reset = self.timestamp_startup
+ self.timestamp_last_check = self.timestamp_startup

self.numeric_path = False
self.conserve_write = True
@@ -462,6 +465,21 @@

first = False

+ time_parser = argparse.ArgumentParser()
+ time_parser.add_argument('--reset', help='reset time counter', action='store_true')
+
+ @cmd2.with_argparser(time_parser)
+ @cmd2.with_category(CUSTOM_CATEGORY)
+ def do_time(self, opts):
+ """Print elapsed time"""
+ timestamp_now = datetime.utcnow()
+ if opts.reset:
+ self.timestamp_last_reset = timestamp_now
+ self.poutput("elapsed time in total: " + str(timestamp_now-self.timestamp_startup))
+ self.poutput("elapsed time since last check: " + str(timestamp_now-self.timestamp_last_check))
+ self.timestamp_last_check = timestamp_now
+ self.poutput("elapsed time since last reset: " + str(timestamp_now-self.timestamp_last_reset))
+
echo_parser = argparse.ArgumentParser()
echo_parser.add_argument('STRING', help="string to echo on the shell", nargs='+')


To view, visit change 38659. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I356ea44e08efe93fe927dbc20564bf850278b546
Gerrit-Change-Number: 38659
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier@sysmocom.de>