예제 #1
0
    def _UpdateDiagnostics(self):
        """ Benchmarks that add histograms but don't use
    timeline_base_measurement need to add shared diagnostics separately.
    Make them available on the telemetry info."""
        for name, value in self.AsDict().items():
            if name in self.diagnostics:
                # If it is of type name, description or start time don't create new
                if name in [
                        reserved_infos.BENCHMARKS.name,
                        reserved_infos.BENCHMARK_START.name,
                        reserved_infos.BENCHMARK_DESCRIPTIONS.name
                ]:
                    continue
                else:
                    # this a stale value from the last run, remove it.
                    del self.diagnostics[name]

            if isinstance(value, list):
                keep = False
                for val in value:
                    if val:
                        keep = True
                if not keep:
                    continue
            else:
                if value is None:
                    continue

            name_type = reserved_infos.GetTypeForName(name)
            diag_class = all_diagnostics.GetDiagnosticClassForName(name_type)
            diag = diag_class(value)
            self.diagnostics[name] = diag
예제 #2
0
 def __setitem__(self, name, diag):
     if not isinstance(name, basestring):
         raise TypeError('name must be string')
     if not isinstance(
             diag, (diagnostic.Diagnostic, diagnostic_ref.DiagnosticRef)):
         raise TypeError('diag must be Diagnostic or DiagnosticRef')
     if (not self._allow_reserved_names
             and not isinstance(diag, UnmergeableDiagnosticSet)
             and not isinstance(diag, diagnostic_ref.DiagnosticRef)):
         expected_type = reserved_infos.GetTypeForName(name)
         if expected_type and diag.__class__.__name__ != expected_type:
             raise TypeError('Diagnostics names "%s" must be %s, not %s' %
                             (name, expected_type, diag.__class__.__name__))
     dict.__setitem__(self, name, diag)