Beispiel #1
0
    def _gen_latency_percentile(self, axes, args):
        # format axes
        if args.title:
            axes.set_title(args.title, fontsize=ssplot.PLOT_TITLE_FONTSIZE)
        if args.latency_units:
            axes.set_xlabel('Latency ({0})'.format(args.latency_units))
        else:
            axes.set_xlabel('Latency')
        axes.set_ylabel('Percentile')
        if self._stats.size == 0:
            nines = 5
        elif args.nines:
            nines = args.nines
        else:
            nines = self._stats.nines()
        axes.set_yscale('percentile', nines=nines)

        # plot bounds
        if self._stats.size > 0:
            xspan = self._stats.smax - self._stats.smin
            lpxmin = self._stats.smin - (xspan * 0.001)
            lpxmax = self._stats.smax + (xspan * 0.001)
        else:
            lpxmin = 0
            lpxmax = 1
        if args.xmin is not None:
            lpxmin = args.xmin
        if args.xmax is not None:
            lpxmax = args.xmax
        axes.set_xlim(lpxmin, lpxmax)
        axes.set_ylim(0, 1.0 - 10**(-nines))

        # grid
        grid_style = ssplot.GridStyle.style(args.grid_style)
        if args.xgrid:
            axes.xaxis.grid(True, **grid_style)
        if args.ygrid:
            axes.yaxis.grid(True, **grid_style)
        axes.set_axisbelow(True)

        # detect non-empty data set
        if self._stats.size > 0:
            # create the plot
            color = 'k' if args.gray else 'b'
            axes.scatter(self._stats.cdfx, self._stats.cdfy, c=color, s=2)
        else:
            ssplot.empty_text(axes, (lpxmax - lpxmin) / 2, 0.9965)
Beispiel #2
0
    def _gen_time_latency_scatter(self, axes, args):
        # format axes
        if args.title:
            axes.set_title(args.title, fontsize=ssplot.PLOT_TITLE_FONTSIZE)
        if args.latency_units:
            axes.set_xlabel('Time ({0})'.format(args.latency_units))
            axes.set_ylabel('Latency ({0})'.format(args.latency_units))
        else:
            axes.set_xlabel('Time')
            axes.set_ylabel('Latency')

        # plot bounds
        if self._stats.size > 0:
            spxmin = self._stats.tmin
            spxmax = self._stats.tmax
            yspan = self._stats.smax - self._stats.smin
            spymin = self._stats.smin
            spymax = self._stats.smax + (yspan * 0.02)
        else:
            spxmin = 0
            spxmax = 1
            spymin = 0
            spymax = 1
        if args.xmin is not None:
            spxmin = args.xmin
        if args.xmax is not None:
            spxmax = args.xmax
        if args.ymin is not None:
            spymin = args.ymin
        if args.ymax is not None:
            spymax = args.ymax
        axes.set_xlim(spxmin, spxmax)
        if spymin == spymax:
            axes.set_ylim(spymin - 1, spymax + 1)
        else:
            axes.set_ylim(spymin, spymax)

        # grid
        grid_style = ssplot.GridStyle.style(args.grid_style)
        if args.xgrid:
            axes.xaxis.grid(True, **grid_style)
        if args.ygrid:
            axes.yaxis.grid(True, **grid_style)
        axes.set_axisbelow(True)

        # detect non-empty data set
        if self._stats.size > 0:
            # scatter plot
            dotsize = 1 if args.figure_size[1] < 8 else 2
            color = '0.5' if args.gray else 'b'
            axes.scatter(self._stats.times,
                         self._stats.samples,
                         c=color,
                         s=dotsize)

            # percentile lines
            if args.show_percentiles:
                pstats = [
                    self._stats.p50, self._stats.p90, self._stats.p99,
                    self._stats.p999, self._stats.p9999
                ]
                labels = ['50th', '90th', '99th', '99.9th', '99.99th']
                color = 'black' if args.gray else 'red'
                ps = ssplot.PlotLineStyle(color, self._plt, len(pstats))
                lines = []
                for idx, perc in enumerate(pstats):
                    lines.append(
                        axes.plot(numpy.linspace(spxmin, spxmax, 10),
                                  numpy.linspace(perc, perc, 10),
                                  color=ps[idx]['color'],
                                  linestyle=ps[idx]['line_style'],
                                  linewidth=ps[idx]['line_width'],
                                  marker=ps[idx]['marker_style'],
                                  markersize=ps[idx]['marker_size'] * 1.5)[0])

                # legend
                if args.show_legend:
                    unitstr = ' ' + args.latency_units if args.latency_units else ''
                    for idx in range(len(labels)):
                        labels[idx] += ' ({0:.3f}{1})'.format(
                            pstats[idx], unitstr)
                    axes.legend(lines,
                                labels,
                                loc=args.legend_location,
                                ncol=args.legend_columns,
                                title=r'$\bf{{{}}}$'.format('Percentiles'),
                                fancybox=True,
                                facecolor='white',
                                edgecolor='black',
                                framealpha=1.0)

        else:
            ssplot.empty_text(axes, (spxmax - spxmin) / 2,
                              (spymax - spymin) / 2)
Beispiel #3
0
    def _gen_latency_cdf(self, axes, args):
        # format axes
        if args.title:
            axes.set_title(args.title, fontsize=ssplot.PLOT_TITLE_FONTSIZE)
        if args.latency_units:
            axes.set_xlabel('Latency ({0})'.format(args.latency_units))
        else:
            axes.set_xlabel('Latency')
        axes.set_ylabel('Probability')

        # plot bounds
        if self._stats.size > 0:
            xspan = self._stats.smax - self._stats.smin
            cpxmin = self._stats.smin - (xspan * 0.01)
            cpxmax = self._stats.smax
            cpymin = -0.02
            cpymax = 1.02
        else:
            cpxmin = 0
            cpxmax = 1
            cpymin = -0.02
            cpymax = 1.02
        if args.xmin is not None:
            cpxmin = args.xmin
        if args.xmax is not None:
            cpxmax = args.xmax
        if args.ymin is not None:
            cpymin = max(0, args.ymin)
        if args.ymax is not None:
            cpymax = min(1, args.ymax)
        if cpxmin == cpxmax:
            axes.set_xlim(cpxmin - 1, cpxmax + 1)
        else:
            axes.set_xlim(cpxmin, cpxmax)
        axes.set_ylim(cpymin, cpymax)

        # grid
        grid_style = ssplot.GridStyle.style(args.grid_style)
        if args.xgrid:
            axes.xaxis.grid(True, **grid_style)
        if args.ygrid:
            axes.yaxis.grid(True, **grid_style)
        axes.set_axisbelow(True)

        # detect non-empty data set
        if self._stats.size > 0:
            # percentile lines
            if args.show_percentiles:
                pstats = [
                    self._stats.p50, self._stats.p90, self._stats.p99,
                    self._stats.p999, self._stats.p9999
                ]
                percents = [0.50, 0.90, 0.99, 0.999, 0.9999]
                labels = ['50th', '90th', '99th', '99.9th', '99.99th']
                color = 'gray' if args.gray else 'red'
                ps = ssplot.PlotLineStyle(color, self._plt, len(pstats))
                lines = []
                for idx, percentile in enumerate(pstats):
                    # vertical line
                    markers = math.ceil(
                        (5 * percents[idx]) / (cpymax - cpymin))
                    lines.append(
                        axes.plot(numpy.linspace(percentile, percentile,
                                                 markers),
                                  numpy.linspace(0, percents[idx], markers),
                                  color=ps[idx]['color'],
                                  linestyle=ps[idx]['line_style'],
                                  linewidth=ps[idx]['line_width'],
                                  marker=ps[idx]['marker_style'],
                                  markersize=ps[idx]['marker_size'] * 1.5)[0])

                # legend
                if args.show_legend:
                    unitstr = ' ' + args.latency_units if args.latency_units else ''
                    for idx in range(len(labels)):
                        labels[idx] += ' ({0:.3f}{1})'.format(
                            pstats[idx], unitstr)
                    axes.legend(lines,
                                labels,
                                loc=args.legend_location,
                                ncol=args.legend_columns,
                                title=r'$\bf{{{}}}$'.format('Percentiles'),
                                fancybox=True,
                                facecolor='white',
                                edgecolor='black',
                                framealpha=1.0)

            # CDF line
            color = 'k' if args.gray else 'b'
            axes.plot(self._stats.cdfx,
                      self._stats.cdfy,
                      c=color,
                      linewidth=1.5)
        else:
            ssplot.empty_text(axes, (cpxmax - cpxmin) / 2,
                              (cpymax - cpymin) / 2)
Beispiel #4
0
    def plot(self, plotfile):
        # create figure
        fig = self._plt.figure(figsize=self._figure_size)
        ax = fig.add_subplot(1, 1, 1)

        # create a PlotLineStyle object
        ps = ssplot.PlotLineStyle(self._plot_style, self._plt, self._num_lines)

        # compute plot bounds
        if len(self._xdata) > 0:
            xmin = self._xmin
            xmax = self._xmax
            ymin = self._ymin
            ymax = self._ymax
            if xmin == None:
                xmin = self._x_min_val
            if xmax == None:
                xmax = self._x_max_val
            if ymin == None:
                ymin = self._y_min_val  #min(map(min, self._ydatas))
            if ymax == None:
                ymax = self._y_max_val  #max(map(max, self._ydatas))
        else:
            xmin = 0
            xmax = 1
            ymin = 0
            ymax = 1

        for limit in [xmin, xmax, ymin, ymax]:
            assert limit != None
            if isinstance(limit, numbers.Number):
                assert not math.isnan(limit)

        xspan = xmax - xmin
        yspan = ymax - ymin
        xmin -= (xspan * self._xauto_frame)
        xmax += (xspan * self._xauto_frame)
        ymin -= (yspan * self._yauto_frame)
        ymax += (yspan * self._yauto_frame)
        xspan = xmax - xmin
        yspan = ymax - ymin

        # figure out where markers should be placed (target 20 markers)
        if len(self._xdata) > 1 and isinstance(xspan, numbers.Number):
            mark_every = math.ceil(
                (int(xspan) / (self._xdata[1] - self._xdata[0])) / 20)
        else:
            mark_every = 1

        # plot the lines
        if len(self._xdata) > 0:
            for idx, ydata in enumerate(self._ydatas):
                # retrieve the plot style info
                style = ps[idx]

                # create line
                line = ax.plot(self._xdata,
                               ydata,
                               color=style['color'],
                               linestyle=style['line_style'],
                               linewidth=style['line_width'],
                               marker=style['marker_style'],
                               markersize=style['marker_size'],
                               markevery=mark_every)[0]

                # set line label
                if self._data_labels != None:
                    line.set_label(self._data_labels[idx])
        else:
            ssplot.empty_text(ax, (xmax - xmin) / 2, (ymax - ymin) / 2)

        # set title
        if self._title != None:
            ax.set_title(self._title, fontsize=ssplot.PLOT_TITLE_FONTSIZE)

        # set axis labels
        if self._xlabel != None:
            ax.set_xlabel(self._xlabel)
        if self._ylabel != None:
            ax.set_ylabel(self._ylabel)

        # create legend
        if len(self._xdata) > 0 and self._data_labels != None:
            ax.legend(loc=self._legend_location,
                      ncol=self._legend_columns,
                      title=self._legend_title,
                      fancybox=True,
                      facecolor='white',
                      edgecolor='black',
                      framealpha=1.0)

        # set plot bounds
        ax.set_xlim(xmin, xmax)
        ax.set_ylim(ymin, ymax)

        # grid
        grid_kwargs = ssplot.GridStyle.style(self._grid_style)
        if self._xgrid:
            ax.xaxis.grid(True, **grid_kwargs)
        else:
            ax.xaxis.grid(False, **grid_kwargs)
        if self._ygrid:
            ax.yaxis.grid(True, **grid_kwargs)
        else:
            ax.yaxis.grid(False, **grid_kwargs)
        ax.set_axisbelow(True)

        # set axis scales
        xlog = False
        if self._xscale != None:
            if self._xscale == 'log':
                xlog = True
                ax.set_xscale('log')
            elif self._xscale.startswith('log'):
                xlog = True
                ax.set_xscale('log', basex=int(self._xscale[3:]))
            else:
                ax.set_xscale(self._xscale)
        ylog = False
        if self._yscale != None:
            if self._yscale == 'log':
                ylog = True
                ax.set_yscale('log')
            elif self._yscale.startswith('log'):
                ylog = True
                ax.set_yscale('log', basey=int(self._yscale[3:]))
            else:
                ax.set_yscale(self._yscale)

        # default ticks
        if self._xmajor_ticks is None and not xlog:
            self._xmajor_ticks = 10
        if self._xminor_ticks is None and not xlog:
            self._xminor_ticks = 20
        if self._ymajor_ticks is None and not ylog:
            self._ymajor_ticks = 10
        if self._yminor_ticks is None and not ylog:
            self._yminor_ticks = 20

        # set ticks
        if self._xmajor_ticks != None:
            if xlog:
                raise ValueError(
                    'you can\'t set xmajor ticks with a logarithmic '
                    'x-axis')
            ax.xaxis.set_major_locator(
                matplotlib.ticker.MaxNLocator(self._xmajor_ticks))
        if self._xminor_ticks != None:
            if xlog:
                raise ValueError(
                    'you can\'t set xminor ticks with a logarithmic '
                    'x-axis')
            ax.xaxis.set_minor_locator(
                matplotlib.ticker.MaxNLocator(self._xminor_ticks))
        if self._ymajor_ticks != None:
            if ylog:
                raise ValueError(
                    'you can\'t set ymajor ticks with a logarithmic '
                    'y-axis')
            ax.yaxis.set_major_locator(
                matplotlib.ticker.MaxNLocator(self._ymajor_ticks))
        if self._yminor_ticks != None:
            if ylog:
                raise ValueError(
                    'you can\'t set yminor ticks with a logarithmic '
                    'y-axis')
            ax.yaxis.set_minor_locator(
                matplotlib.ticker.MaxNLocator(self._yminor_ticks))

        # verbose tick labels
        if self._xticklabels_verbose:
            ax.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
            ax.ticklabel_format(axis='x', style='plain', useOffset=False)
        if self._yticklabels_verbose:
            ax.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
            ax.ticklabel_format(axis='y', style='plain', useOffset=False)

        # generate the plot
        fig.tight_layout()
        fig.savefig(plotfile)
        self._plt.close(fig)