Exemplo n.º 1
0
    def create_diff_chart(self, key, report_dir):
        """
        Generate the diff chart for the specified key, comparing the
        two reports for this diff.

        `key`:
            A section key that appears in both reports

        `report_dir`:
            The directory to write the data, gnuplot, and image files
        """
        output_name = 'diff_{hash}'.format(hash=hashlib.md5(str(key)).hexdigest())
        per_second_name = output_name + '.per_second.png'
        response_times_name = output_name + '.response.png'
        per_second_path = gnuplot_scriptpath(report_dir, per_second_name)
        response_times_path = gnuplot_scriptpath(report_dir, response_times_name)
        gplot_path = str(os.path.join(report_dir, output_name + '.gplot'))
        data_path = gnuplot_scriptpath(report_dir, output_name + '.data')

        labels = []
        data = []

        left_data = self.data1[key]
        right_data = self.data2[key]

        columns = set(left_data.keys()) & set(right_data.keys())
        cycles = [int(v) for v in left_data['CUs']]

        for column_name in columns:
            labels.extend(['L_' + column_name, 'R_' + column_name])

        for idx in range(len(cycles)):
            values = []
            for column_name in columns:
                values.append(left_data[column_name][idx])
                values.append(right_data[column_name][idx])
            data.append(values)

        with open(data_path, 'w') as data_file:
            data_file.write(render_template(
                'gnuplot/data.mako',
                labels=labels,
                data=data
            ))

        with open(gplot_path, 'w') as gplot_file:
            gplot_file.write(render_template(
                'gnuplot/diff.mako',
                per_second_path=per_second_path,
                response_times_path=response_times_path,
                use_xticlabels=not strictly_monotonic(cycles),
                left_path=self.report1,
                right_path=self.report2,
                data_path=data_path,
                key=key,
                column_names=labels,
            ))
        gnuplot(gplot_path)

        return (per_second_name, response_times_name)
Exemplo n.º 2
0
    def createResultChart(self, key, stats, report_dir):
        """
        Create a single result chart using a specified key and report directory

        `key`:
            The key used to identify this result. Is hashed to generate a filename

        `stats`:
            A map of cycle to StatsAccumulator or StatsAggregator to generate the chart from

        `report_dir`:
            The directory to write the data, gnuplot, and image files
        
        Returns the relative path of the generated image in the report_dir
        """
        output_name = 'results_{hash}'.format(hash=hashlib.md5(str(key)).hexdigest())
        image_name = output_name + '.png'
        image_path = gnuplot_scriptpath(report_dir, image_name)
        gplot_path = str(os.path.join(report_dir, output_name + '.gplot'))
        data_path = gnuplot_scriptpath(report_dir, output_name + '.data')

        # data
        labels = STATS_COLUMNS + ["E", "G", "F", "P", "U"]
        data = []
        has_error = False
        apdex_t = self.options.apdex_t
        for cycle, cycle_stats in stats.items():
            values = [self.cycles[cycle]] + cycle_stats.stats_list()
            if cycle_stats.errors > 0:
                has_error = True
            score = cycle_stats.apdex_score

            apdex = ['0', '0', '0', '0', '0']
            if score < 0.5:
                apdex[4] = str(score)
            elif score < 0.7:
                apdex[3] = str(score)
            elif score < 0.85:
                apdex[2] = str(score)
            elif score < 0.94:
                apdex[1] = str(score)
            else:
                apdex[0] = str(score)
            data.append(values + apdex)
        if len(data) == 0:
            # No pages finished during a cycle
            return

        with open(data_path, 'w') as data_file:
            data_file.write(render_template('gnuplot/data.mako',
                labels=labels,
                data=data
            ))
        
        with open(gplot_path, 'w') as gplot_file:
            gplot_file.write(render_template('gnuplot/result.mako',
                image_path=image_path,
                chart_size=[800, 800],
                maxCVUs=max(self.cycles),
                datapoints=len(self.cycles),
                use_xticlabels=not strictly_monotonic(self.cycles),
                data_path=data_path,
                has_error=has_error,
                apdex_t="%0.1f" % apdex_t,
                column_names=labels,
                shared={}
            ))
        gnuplot(gplot_path)

        return image_name
Exemplo n.º 3
0
    def create_trend_chart(self, key, report_dir):
        """
        Create a chart showing data trends for the specified key across all stored reports.

        Returns a tuple with of 3 image paths, relative to the report dir:
        (entries per second, average response time, apdex score)

        `key`:
            A section key that exists in self.reports_data, that specifies the data to trend
            over

        `report_dir`:
            The path to the output directory to write the data, gnuplot, and images to
        """
        output_name = 'trend_{hash}'.format(hash=hashlib.md5(str(key)).hexdigest())
        per_second_name = output_name + '.per_second.png'
        average_response_name = output_name + '.average.png'
        apdex_name = output_name + '.apdex.png'
        per_second_path = gnuplot_scriptpath(report_dir, per_second_name)
        average_response_path = gnuplot_scriptpath(report_dir, average_response_name)
        apdex_path = gnuplot_scriptpath(report_dir, apdex_name)
        gplot_path = str(os.path.join(report_dir, output_name + '.gplot'))
        data_path = gnuplot_scriptpath(report_dir, output_name + '.data')

        labels = ['CUs', 'PS', 'Apdex*', 'AVG']
        data = []

        cycles = [int(v) for v in self.reports_data[0][key]['CUs']]

        for report_idx, report_data in enumerate(self.reports_data):
            for idx in range(len(cycles)):
                values = [report_idx]
                for column_name in labels:
                    values.append(report_data[key][column_name][idx])
                data.append(values)
            data.append(None)

        with open(data_path, 'w') as data_file:
            data_file.write(render_template(
                'gnuplot/data.mako',
                labels=labels,
                data=data
            ))

        with open(gplot_path, 'w') as gplot_file:
            gplot_file.write(render_template(
                'gnuplot/trend.mako',
                per_second_path=per_second_path,
                average_response_path=average_response_path,
                apdex_path=apdex_path,
                use_xticlabels=not strictly_monotonic(cycles),
                data_path=data_path,
                key=key,
                column_names=labels,
                reports_name=self.reports_name,
                labels=[metadata.get('label') for metadata in self.reports_metadata],
                max_cus=max(cycles),
            ))
        gnuplot(gplot_path)

        return (per_second_name, average_response_name, apdex_name)