Exemplo n.º 1
0
    def format(self, results):
        self.open_output()
        for r in results:
            self.write("Summary of %s test run " % r.meta('NAME'))
            if r.meta('TITLE'):
                self.write("'%s' (at %s)" % (r.meta('TITLE'), r.meta("TIME")))
            else:
                self.write("at %s" % r.meta("TIME"))
            self.write(":\n\n")

            if 'FROM_COMBINER' in r.meta():
                m = {}
            else:
                m = r.meta().get("SERIES_META", {})

            txtlen = max([len(n) for n in r.series_names])
            unit_len = max((len(s['units']) for s in
                            self.settings.DATA_SETS.values()))

            self.write("{spc:{txtlen}s} {avg:>{width}s}"
                       " {med:>{width}s} {datapoints:>{lwidth}s}\n".format(
                           spc="", avg="avg", med="median",
                           datapoints="# data pts", txtlen=txtlen + 3,
                           width=self.COL_WIDTH,
                           lwidth=self.COL_WIDTH + unit_len))

            for s in sorted(r.series_names):
                self.write((" %-" + str(txtlen) + "s : ") % s)
                d = [i for i in r.series(s) if i is not None]

                median = mean = None

                if s in m and 'MEAN_VALUE' in m[s]:
                    mean = m[s]['MEAN_VALUE']
                elif not d:
                    self.write("No data.\n")
                    continue

                units = self.settings.DATA_SETS[s]['units'] if s in \
                    self.settings.DATA_SETS else ''

                if d and self.np is not None:
                    mean = self.np.mean(d) if not mean else mean
                    median = self.np.median(d)
                elif d:
                    mean = sum(d) / len(d) if not mean else mean
                    median = sorted(d)[len(d) // 2]

                if mean and units == 'bytes':
                    factor, units = format_bytes(max(mean, median))
                    mean /= factor
                    median /= factor

                if mean is not None:
                    self.write("{0:{width}.2f} ".format(mean,
                                                        width=self.COL_WIDTH))
                else:
                    self.write("{0:>{width}}".format("N/A", width=self.COL_WIDTH))

                if median is not None:
                    self.write("{0:{width}.2f} {1}".format(median, units,
                                                           width=self.COL_WIDTH))
                else:
                    self.write("{0:>{width}} {1}".format("N/A", units,
                                                         width=self.COL_WIDTH))

                self.write("{0:{width}d}\n".format(len(d),
                                                   width=(self.COL_WIDTH +
                                                          unit_len - len(units))))
Exemplo n.º 2
0
    def format(self, results):
        self.open_output()
        for r in results:
            self.write("Summary of %s test run " % r.meta('NAME'))
            if r.meta('TITLE'):
                self.write("'%s' (at %s)" % (r.meta('TITLE'), r.meta("TIME")))
            else:
                self.write("at %s" % r.meta("TIME"))
            self.write(":\n\n")

            if 'FROM_COMBINER' in r.meta():
                m = {}
            else:
                m = r.meta().get("SERIES_META", {})

            txtlen = max([len(n) for n in r.series_names])
            unit_len = max(
                (len(s['units']) for s in self.settings.DATA_SETS.values()))

            self.write("{spc:{txtlen}s} {avg:>{width}s}"
                       " {med:>{width}s} {datapoints:>{lwidth}s}\n".format(
                           spc="",
                           avg="avg",
                           med="median",
                           datapoints="# data pts",
                           txtlen=txtlen + 3,
                           width=self.COL_WIDTH,
                           lwidth=self.COL_WIDTH + unit_len))

            for s in sorted(r.series_names):
                self.write((" %-" + str(txtlen) + "s : ") % s)
                try:
                    d = [i[1] for i in r.raw_series(s) if i[1] is not None]
                except KeyError:
                    d = None

                if not d:
                    d = [i for i in r.series(s) if i is not None]

                md = m.get(s, {})

                units = (md.get('UNITS')
                         or self.settings.DATA_SETS.get(s, {}).get(
                             'units', ''))

                mean = md.get('MEAN_VALUE')
                median = md.get('RTT_MEDIAN') if units == 'ms' else None

                if not mean and not d:
                    self.write("No data.\n")
                    continue

                if d and self.np is not None:
                    mean = mean or self.np.mean(d)
                    median = median or self.np.median(d)
                elif d:
                    mean = mean or sum(d) / len(d)
                    median = median or sorted(d)[len(d) // 2]

                if mean and units == 'bytes':
                    factor, units = format_bytes(max(mean, median))
                    mean /= factor
                    median /= factor

                if mean is not None:
                    self.write("{0:{width}.2f} ".format(mean,
                                                        width=self.COL_WIDTH))
                else:
                    self.write("{0:>{width}}".format("N/A",
                                                     width=self.COL_WIDTH))

                if median is not None:
                    self.write("{0:{width}.2f} {1}".format(
                        median, units, width=self.COL_WIDTH))
                else:
                    self.write("{0:>{width}} {1}".format("N/A",
                                                         units,
                                                         width=self.COL_WIDTH))

                self.write("{0:{width}d}\n".format(
                    len(d), width=(self.COL_WIDTH + unit_len - len(units))))
Exemplo n.º 3
0
    def format(self, results):
        self.open_output()
        for r in results:
            self.write("\nSummary of %s test run from %s" % (r.meta('NAME'),
                                                             r.meta("TIME")))
            if r.meta('TITLE'):
                self.write("\n  Title: '%s'" % r.meta('TITLE'))
            if self.settings.DATA_CUTOFF:
                self.write("\n  Cut data to interval: [%.2f, %.2f]" %
                           self.settings.DATA_CUTOFF)
            self.write("\n\n")

            if 'FROM_COMBINER' in r.meta():
                m = {}
            else:
                m = r.meta().get("SERIES_META", {})

            txtlen = max([len(n) for n in r.series_names])
            unit_len = max((len(s['units']) for s in
                            self.settings.DATA_SETS.values()))

            self.write("{spc:{txtlen}s} {avg:>{width}s}"
                       " {med:>{width}s} {datapoints:>{lwidth}s}\n".format(
                           spc="", avg="avg", med="median",
                           datapoints="# data pts", txtlen=txtlen + 3,
                           width=self.COL_WIDTH,
                           lwidth=self.COL_WIDTH + unit_len))

            self.make_combines(r, ['mean', 'median'])
            for s in sorted(r.series_names):
                self.write((" %-" + str(txtlen) + "s : ") % s)
                try:
                    d = [i[1] for i in r.raw_series(s) if i[1] is not None]
                except KeyError:
                    d = None

                if not d:
                    d = [i for i in r.series(s) if i is not None]

                md = m.get(s, {})

                units = (md.get('UNITS') or
                         self.settings.DATA_SETS.get(s, {}).get('units', ''))

                mean = self.get_res(s, 'mean')
                median = self.get_res(s, 'median')
                n = self.get_res(s, 'N')
                is_computed = 'COMPUTED_LATE' in m.get(s, {})

                if mean is None:
                    self.write("No data.\n")
                    continue

                if mean and units == 'bytes':
                    factor, units = format_bytes(max(mean, median))
                    mean /= factor
                    median /= factor

                if mean is not None:
                    self.write("{0:{width}.2f} ".format(mean,
                                                        width=self.COL_WIDTH))
                else:
                    self.write("{0:>{width}}".format("N/A", width=self.COL_WIDTH))

                if median is not None and not is_computed:
                    self.write("{0:{width}.2f} {1}".format(median, units,
                                                           width=self.COL_WIDTH))
                else:
                    self.write("{0:>{width}} {1}".format("N/A", units,
                                                         width=self.COL_WIDTH))

                self.write("{0:{width}d}\n".format(n,
                                                   width=(self.COL_WIDTH +
                                                          unit_len - len(units))))