summaryrefslogtreecommitdiff
path: root/test/test-counter
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2010-07-08 14:17:41 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2010-07-08 14:57:06 +0200
commit8431b7dba0a0e32fba4cf1b5053ece0698cc10b8 (patch)
tree400cbc20f28b0d9cfdb8791cc7b01054c299af39 /test/test-counter
parent262e526fe8029ea65e9c0655b5d7a0e6438a8bb8 (diff)
downloadconnman-8431b7dba0a0e32fba4cf1b5053ece0698cc10b8.tar.gz
connman-8431b7dba0a0e32fba4cf1b5053ece0698cc10b8.tar.bz2
connman-8431b7dba0a0e32fba4cf1b5053ece0698cc10b8.zip
Make test-counter byte counters human readable
Diffstat (limited to 'test/test-counter')
-rwxr-xr-xtest/test-counter25
1 files changed, 24 insertions, 1 deletions
diff --git a/test/test-counter b/test/test-counter
index c32cb9ef..7c2fa4ab 100755
--- a/test/test-counter
+++ b/test/test-counter
@@ -7,6 +7,22 @@ import dbus
import dbus.service
import dbus.mainloop.glib
+def make_bytes_readable(bytes):
+ SUFFIXES = [ 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' ]
+ size = 1024
+
+ if bytes < size:
+ return ''
+
+ for suffix in SUFFIXES:
+ if bytes > size * 1024:
+ size = size * 1024
+ continue
+
+ return '%.1f %s' % (bytes / float(size), suffix)
+
+ return ''
+
class Counter(dbus.service.Object):
@dbus.service.method("org.moblin.connman.Counter",
in_signature='', out_signature='')
@@ -20,7 +36,14 @@ class Counter(dbus.service.Object):
print "%s" % (path)
for key in stats.keys():
val = int(stats[key])
- print " %s = %s" % (key, val)
+ str = " %s = %s" % (key, val)
+
+ if key in ["RX.Bytes", "TX.Bytes"]:
+ hstr = make_bytes_readable(val)
+ if hstr:
+ str = "%s (%s)" % (str, hstr)
+
+ print str
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)