Esempio n. 1
0
    def _ParseHistograms(self, json_data):
        histograms = histogram_set.HistogramSet()
        try:
            histograms.ImportDicts(json_data)
        except BaseException:
            raise errors.ReadValueUnknownFormat(self._results_filename)

        self._trace_urls = FindTraceUrls(histograms)
        histograms_by_path = CreateHistogramSetByTestPathDict(histograms)
        histograms_by_path_optional_grouping_label = (
            CreateHistogramSetByTestPathDict(histograms,
                                             ignore_grouping_label=True))
        test_paths_to_match = set([
            histogram_helpers.ComputeTestPathFromComponents(
                self._metric,
                grouping_label=self._grouping_label,
                story_name=self._trace_or_story),
            histogram_helpers.ComputeTestPathFromComponents(
                self._metric,
                grouping_label=self._grouping_label,
                story_name=self._trace_or_story,
                needs_escape=False)
        ])
        logging.debug('Test paths to match: %s', test_paths_to_match)

        try:
            result_values = ExtractValuesFromHistograms(
                test_paths_to_match, histograms_by_path, self._metric,
                self._grouping_label, self._trace_or_story, self._statistic)
        except errors.ReadValueNotFound:
            result_values = ExtractValuesFromHistograms(
                test_paths_to_match,
                histograms_by_path_optional_grouping_label, self._metric, None,
                self._trace_or_story, self._statistic)
        return result_values
Esempio n. 2
0
    def _Poll(self):
        if self.cas_root_ref:
            isolate_output = RetrieveCASOutput(
                self.cas_root_ref,
                self.results_path,
            )
        else:
            isolate_output = RetrieveIsolateOutput(
                self._isolate_server,
                self._isolate_hash,
                self._results_filename,
            )

        result_values = []
        histogram_exception = None
        graph_json_exception = None
        json_data = None
        proto_data = None
        try:
            json_data = json.loads(isolate_output)
        except ValueError:
            proto_data = isolate_output

        try:
            logging.debug('Attempting to parse as a HistogramSet.')
            result_values = self._ParseHistograms(json_data, proto_data)
            self._mode = 'histograms'
            logging.debug('Succeess.')
        except (errors.ReadValueNotFound, errors.ReadValueNoValues,
                errors.FatalError):
            raise
        except (errors.InformationalError, errors.ReadValueUnknownFormat) as e:
            # In case we encounter any other error, we should log and proceed.
            logging.error('Failed parsing histograms: %s', e)
            histogram_exception = sys.exc_info()[1]

        if histogram_exception:
            try:
                logging.debug('Attempting to parse as GraphJSON.')
                result_values = self._ParseGraphJson(json_data)
                self._mode = 'graphjson'
                logging.debug('Succeess.')
            except (errors.ReadValueChartNotFound,
                    errors.ReadValueTraceNotFound, errors.FatalError):
                raise
            except errors.InformationalError as e:
                logging.error('Failed parsing histograms: %s', e)
                graph_json_exception = sys.exc_info()[1]

        if histogram_exception and graph_json_exception:
            raise errors.ReadValueUnknownFormat(self._results_filename)

        self._Complete(result_values=tuple(result_values))