summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/common/text_opts.py
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2015-12-14 16:03:27 +0200
committerHanoh Haim <hhaim@cisco.com>2015-12-14 16:03:27 +0200
commita3611f0f06cb8fca0692eab5e4aafd5827fb88cc (patch)
tree3094b889a322dd4655a6b48a4630b92c81809db5 /scripts/automation/trex_control_plane/common/text_opts.py
parent4e0f17da4400a9db25a4919242000ec44fa03763 (diff)
parent3f94a09f66657970636a532aac9411ad6a5290ad (diff)
merge from master
Diffstat (limited to 'scripts/automation/trex_control_plane/common/text_opts.py')
-rwxr-xr-xscripts/automation/trex_control_plane/common/text_opts.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py
index 06c2c056..5a86149c 100755
--- a/scripts/automation/trex_control_plane/common/text_opts.py
+++ b/scripts/automation/trex_control_plane/common/text_opts.py
@@ -19,6 +19,50 @@ TEXT_CODES = {'bold': {'start': '\x1b[1m',
'end': '\x1b[24m'}}
+def format_num (size, suffix = ""):
+ for unit in ['','K','M','G','T','P']:
+ if abs(size) < 1000.0:
+ return "%3.2f %s%s" % (size, unit, suffix)
+ size /= 1000.0
+
+ return "NaN"
+
+def format_time (t_sec):
+ if t_sec < 0:
+ return "infinite"
+
+ if t_sec < 1:
+ # low numbers
+ for unit in ['ms', 'usec', 'ns']:
+ t_sec *= 1000.0
+ if t_sec >= 1.0:
+ return '{:,.2f} [{:}]'.format(t_sec, unit)
+
+ return "NaN"
+
+ else:
+ # seconds
+ if t_sec < 60.0:
+ return '{:,.2f} [{:}]'.format(t_sec, 'sec')
+
+ # minutes
+ t_sec /= 60.0
+ if t_sec < 60.0:
+ return '{:,.2f} [{:}]'.format(t_sec, 'minutes')
+
+ # hours
+ t_sec /= 60.0
+ if t_sec < 24.0:
+ return '{:,.2f} [{:}]'.format(t_sec, 'hours')
+
+ # days
+ t_sec /= 24.0
+ return '{:,.2f} [{:}]'.format(t_sec, 'days')
+
+
+def format_percentage (size):
+ return "%0.2f %%" % (size)
+
def bold(text):
return text_attribute(text, 'bold')