Exemplo n.º 1
0
    def CollectComparativeBuildTimings(self, output, build_id, db):
        """Create a report comparing this build to recent history.

    Compare the timings for this build to the recent history of the
    same build config.

    Args:
      output: File like object to write too, usually sys.stdout.
      build_id: CIDB id for the current build.
      db: CIDBConnection instance.

    Returns:
      The generated report as a multiline string.
    """
        current_status = build_time_stats.BuildIdToBuildStatus(db, build_id)
        current_build = build_time_stats.GetBuildTimings(current_status)

        # We compare against seven days of history.
        end_date = datetime.datetime.now().date()
        start_date = end_date - datetime.timedelta(
            days=self._STATS_HISTORY_DAYS)

        build_config = current_status['build_config']
        historical_statuses = build_time_stats.BuildConfigToStatuses(
            db, build_config, start_date, end_date)

        historical_timing = [
            build_time_stats.GetBuildTimings(status)
            for status in historical_statuses
        ]

        description = 'This build versus last week of %s' % build_config

        build_time_stats.Report(output, description, current_build,
                                historical_timing)
Exemplo n.º 2
0
    def Run(self):
        """Run cros build."""
        self.options.Freeze()

        commandline.RunInsideChroot(self)

        credentials = self.options.cred_dir
        if not credentials:
            credentials = cros_cidbcreds.CheckAndGetCIDBCreds()

        # Delay import so sqlalchemy isn't pulled in until we need it.
        from chromite.lib import cidb

        db = cidb.CIDBConnection(credentials)

        # Timeframe for discovering builds, if options.build_id not used.
        start_date, end_date = self.OptionsToStartEndDates(self.options)

        # Trending is sufficiently different to be handled on it's own.
        if not self.options.trending and self.options.report != 'success':
            assert not self.options.csv, (
                '--csv can only be used with --trending or --report success.')

        # Data about a single build (optional).
        focus_build = None

        if self.options.build_id:
            logging.info('Gathering data for %s', self.options.build_id)
            focus_status = build_time_stats.BuildIdToBuildStatus(
                db, self.options.build_id)
            focus_build = build_time_stats.GetBuildTimings(focus_status)

            build_config = focus_status['build_config']
            builds_statuses = build_time_stats.BuildConfigToStatuses(
                db, build_config, start_date, end_date)
            description = 'Focus %d - %s' % (self.options.build_id,
                                             build_config)

        elif self.options.build_config:
            builds_statuses = build_time_stats.BuildConfigToStatuses(
                db, self.options.build_config, start_date, end_date)
            description = 'Config %s' % self.options.build_config

        elif self.options.build_type:
            builds_statuses = build_time_stats.MasterConfigToStatuses(
                db, BUILD_TYPE_MAP[self.options.build_type], start_date,
                end_date)
            description = 'Type %s' % self.options.build_type

        if not builds_statuses:
            logging.critical('No Builds Found For: %s', description)
            return 1

        if self.options.report == 'success':
            # Calculate per-build success rates and per-stage success rates.
            build_success_rates = build_time_stats.GetBuildSuccessRates(
                builds_statuses)
            stage_success_rates = (
                build_time_stats.GetStageSuccessRates(builds_statuses)
                if self.options.stages else {})
            if self.options.csv:
                build_time_stats.SuccessReportCsv(sys.stdout,
                                                  build_success_rates,
                                                  stage_success_rates)
            else:
                build_time_stats.SuccessReport(sys.stdout, description,
                                               build_success_rates,
                                               stage_success_rates)
            return 0

        # Compute per-build timing.
        builds_timings = [
            build_time_stats.GetBuildTimings(status)
            for status in builds_statuses
        ]

        if not builds_timings:
            logging.critical('No timing results For: %s', description)
            return 1

        # Report results.
        if self.options.report == 'standard':
            build_time_stats.Report(sys.stdout, description, focus_build,
                                    builds_timings, self.options.stages,
                                    self.options.trending, self.options.csv)
        elif self.options.report == 'stability':
            build_time_stats.StabilityReport(sys.stdout, description,
                                             builds_timings)