X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=nfvbench%2Fsummarizer.py;h=1676e9351dd3821e8a7d4470ad2369fdc2e20fa7;hb=refs%2Fchanges%2F19%2F49519%2F1;hp=1eaa8d6e15ff109a03f490e6e39350b99396d5f7;hpb=5bfd65ce5753b27c32afb9f84cf5b268f060cb03;p=nfvbench.git diff --git a/nfvbench/summarizer.py b/nfvbench/summarizer.py index 1eaa8d6..1676e93 100644 --- a/nfvbench/summarizer.py +++ b/nfvbench/summarizer.py @@ -14,14 +14,16 @@ # under the License. # -import bitmath from contextlib import contextmanager from datetime import datetime import math + +import bitmath import pytz -from specs import ChainType from tabulate import tabulate +from specs import ChainType + class Formatter(object): """Collection of string formatter methods""" @@ -40,12 +42,11 @@ class Formatter(object): @staticmethod def standard(data): - if type(data) == int: + if isinstance(data, int): return Formatter.int(data) - elif type(data) == float: + elif isinstance(data, float): return Formatter.float(4)(data) - else: - return Formatter.fixed(data) + return Formatter.fixed(data) @staticmethod def suffix(suffix_str): @@ -70,8 +71,7 @@ class Formatter(object): bps = byte_to_bit_classes.get(bit.unit, bitmath.Bit).from_other(bit) / 8.0 if bps.unit != 'Bit': return bps.format("{value:.4f} {unit}ps") - else: - return bps.format("{value:.4f} bps") + return bps.format("{value:.4f} bps") @staticmethod def percentage(data): @@ -79,8 +79,7 @@ class Formatter(object): return '' elif math.isnan(data): return '-' - else: - return Formatter.suffix('%')(Formatter.float(4)(data)) + return Formatter.suffix('%')(Formatter.float(4)(data)) class Table(object): @@ -92,7 +91,7 @@ class Table(object): self.columns = len(header_row) def add_row(self, row): - assert (self.columns == len(row)) + assert self.columns == len(row) formatted_row = [] for entry, formatter in zip(row, self.formatters): formatted_row.append(formatter(entry)) @@ -123,7 +122,7 @@ class Summarizer(object): self.marker_stack.append(marker) def __unindent(self): - assert (self.indent_size >= self.indent_per_level) + assert self.indent_size >= self.indent_per_level self.indent_size -= self.indent_per_level self.marker_stack.pop() @@ -135,7 +134,7 @@ class Summarizer(object): def _put(self, *args): self.str += self.__get_indent_string() - if len(args) and type(args[-1]) == dict: + if args and isinstance(args[-1], dict): self.str += ' '.join(map(str, args[:-1])) + '\n' self._put_dict(args[-1]) else: @@ -144,7 +143,7 @@ class Summarizer(object): def _put_dict(self, data): with self._create_block(False): for key, value in data.iteritems(): - if type(value) == dict: + if isinstance(value, dict): self._put(key + ':') self._put_dict(value) else: @@ -370,7 +369,7 @@ class NFVBenchSummarizer(Summarizer): 'type': 'NDR', 'rate_bps': analysis['ndr']['rate_bps'], 'rate_pps': analysis['ndr']['rate_pps'], - 'drop_percantage': analysis['ndr']['stats']['overall']['drop_percentage'], + 'drop_percentage': analysis['ndr']['stats']['overall']['drop_percentage'], 'avg_delay_usec': analysis['ndr']['stats']['overall']['avg_delay_usec'], 'min_delay_usec': analysis['ndr']['stats']['overall']['min_delay_usec'], 'max_delay_usec': analysis['ndr']['stats']['overall']['max_delay_usec'] @@ -393,7 +392,7 @@ class NFVBenchSummarizer(Summarizer): 'type': 'PDR', 'rate_bps': analysis['pdr']['rate_bps'], 'rate_pps': analysis['pdr']['rate_pps'], - 'drop_percantage': analysis['pdr']['stats']['overall']['drop_percentage'], + 'drop_percentage': analysis['pdr']['stats']['overall']['drop_percentage'], 'avg_delay_usec': analysis['pdr']['stats']['overall']['avg_delay_usec'], 'min_delay_usec': analysis['pdr']['stats']['overall']['min_delay_usec'], 'max_delay_usec': analysis['pdr']['stats']['overall']['max_delay_usec'] @@ -472,8 +471,7 @@ class NFVBenchSummarizer(Summarizer): def __record_send(self): if self.sender: self.record_header["@timestamp"] = datetime.utcnow().replace( - tzinfo=pytz.utc).strftime( - "%Y-%m-%dT%H:%M:%S.%f%z") + tzinfo=pytz.utc).strftime("%Y-%m-%dT%H:%M:%S.%f%z") for frame_size in self.record_data: data = self.record_header data['frame_size'] = frame_size @@ -500,5 +498,6 @@ class NFVBenchSummarizer(Summarizer): # init is called after checking for sender self.record_header = { "runlogdate": self.sender.runlogdate, + "user_label": self.config['user_label'] } self.record_data = {}