tools/metrics/histograms/find_unmapped_histograms.py
def readChromiumHistograms():
  """Searches the Chromium source for all histogram names.

  Also prints warnings for any invocations of the UMA_HISTOGRAM_* macros with
  names that might vary during a single run of the app.

  Returns:
    A tuple of
      a set containing any found literal histogram names, and
      a set mapping histogram name to first filename:line where it was found
  """
  logging.info('Scanning Chromium source for histograms...')

  # Use git grep to find all invocations of the UMA_HISTOGRAM_* macros.
  # Examples:
  #   'path/to/foo.cc:420:  UMA_HISTOGRAM_COUNTS_100("FooGroup.FooName",'
  #   'path/to/bar.cc:632:  UMA_HISTOGRAM_ENUMERATION('
  locations = RunGit(['gs', 'UMA_HISTOGRAM']).split('\n')
  all_filenames = set(location.split(':')[0] for location in locations);
  filenames = [f for f in all_filenames
               if C_FILENAME.match(f) and not TEST_FILENAME.match(f)]

  histograms = set()
  location_map = dict()
  unknown_macros = set()
  all_suffixes = STANDARD_HISTOGRAM_SUFFIXES | STANDARD_LIKE_SUFFIXES
  all_others = OTHER_STANDARD_HISTOGRAMS | OTHER_STANDARD_LIKE_HISTOGRAMS
  for filename in filenames:
    contents = ''
    with open(filename, 'r') as f:
      contents = removeComments(f.read())

    # TODO(isherman): Look for histogram function calls like
    # base::UmaHistogramSparse() in addition to macro invocations.
    for match in HISTOGRAM_REGEX.finditer(contents):
      line_number = contents[:match.start()].count('\n') + 1
      if (match.group(2) not in all_suffixes and
          match.group(1) not in all_others):
        full_macro_name = match.group(1)
        if (full_macro_name not in unknown_macros):
          logging.warning('%s:%d: Unknown macro name: <%s>' %
                          (filename, line_number, match.group(1)))
          unknown_macros.add(full_macro_name)

        continue

      histogram = match.group(3).strip()
      histogram = collapseAdjacentCStrings(histogram)

      # Must begin and end with a quotation mark.
      if not histogram or histogram[0] != '"' or histogram[-1] != '"':
        logNonLiteralHistogram(filename, histogram)
        continue

      # Must not include any quotation marks other than at the beginning or end.
      histogram_stripped = histogram.strip('"')
      if '"' in histogram_stripped:
        logNonLiteralHistogram(filename, histogram)
        continue

      if histogram_stripped not in histograms:
        histograms.add(histogram_stripped)
        location_map[histogram_stripped] = '%s:%d' % (filename, line_number)

  return histograms, location_map
Searches the Chromium source for all histogram names.

  Also prints warnings for any invocations of the UMA_HISTOGRAM_* macros with
  names that might vary during a single run of the app.

  Returns:
    A tuple of
      a set containing any found literal histogram names, and
      a set mapping histogram name to first filename:line where it was found
  
Searches the Chromium source for all histogram names.
Also prints warnings for any invocations of the UMA_HISTOGRAM_* macros with
names that might vary during a single run of the app.
Searches the Chromium source for all histogram names . Also prints warnings for any invocations of the UMA_HISTOGRAM_ * macros with names that might vary during a single run of the app .
def readChromiumHistograms():
  logging.info('Scanning Chromium source for histograms...')
  locations = RunGit(['gs', 'UMA_HISTOGRAM']).split('\n')
  all_filenames = set(location.split(':')[0] for location in locations);
  filenames = [f for f in all_filenames
               if C_FILENAME.match(f) and not TEST_FILENAME.match(f)]
  histograms = set()
  location_map = dict()
  unknown_macros = set()
  all_suffixes = STANDARD_HISTOGRAM_SUFFIXES | STANDARD_LIKE_SUFFIXES
  all_others = OTHER_STANDARD_HISTOGRAMS | OTHER_STANDARD_LIKE_HISTOGRAMS
  for filename in filenames:
    contents = ''
    with open(filename, 'r') as f:
      contents = removeComments(f.read())
    for match in HISTOGRAM_REGEX.finditer(contents):
      line_number = contents[:match.start()].count('\n') + 1
      if (match.group(2) not in all_suffixes and
          match.group(1) not in all_others):
        full_macro_name = match.group(1)
        if (full_macro_name not in unknown_macros):
          logging.warning('%s:%d: Unknown macro name: <%s>' %
                          (filename, line_number, match.group(1)))
          unknown_macros.add(full_macro_name)
        continue
      histogram = match.group(3).strip()
      histogram = collapseAdjacentCStrings(histogram)
      if not histogram or histogram[0] != '"' or histogram[-1] != '"':
        logNonLiteralHistogram(filename, histogram)
        continue
      histogram_stripped = histogram.strip('"')
      if '"' in histogram_stripped:
        logNonLiteralHistogram(filename, histogram)
        continue
      if histogram_stripped not in histograms:
        histograms.add(histogram_stripped)
        location_map[histogram_stripped] = '%s:%d' % (filename, line_number)
  return histograms, location_map
def readChromiumHistograms ( ) : logging . info ( 'Scanning Chromium source for histograms...' ) locations = RunGit ( [ 'gs' , 'UMA_HISTOGRAM' ] ) . split ( '\n' ) all_filenames = set ( location . split ( ':' ) [ 0 ] for location in locations ) ; filenames = [ f for f in all_filenames if C_FILENAME . match ( f ) and not TEST_FILENAME . match ( f ) ] histograms = set ( ) location_map = dict ( ) unknown_macros = set ( ) all_suffixes = STANDARD_HISTOGRAM_SUFFIXES | STANDARD_LIKE_SUFFIXES all_others = OTHER_STANDARD_HISTOGRAMS | OTHER_STANDARD_LIKE_HISTOGRAMS for filename in filenames : contents = '' with open ( filename , 'r' ) as f : contents = removeComments ( f . read ( ) ) for match in HISTOGRAM_REGEX . finditer ( contents ) : line_number = contents [ : match . start ( ) ] . count ( '\n' ) + 1 if ( match . group ( 2 ) not in all_suffixes and match . group ( 1 ) not in all_others ) : full_macro_name = match . group ( 1 ) if ( full_macro_name not in unknown_macros ) : logging . warning ( '%s:%d: Unknown macro name: <%s>' % ( filename , line_number , match . group ( 1 ) ) ) unknown_macros . add ( full_macro_name ) continue histogram = match . group ( 3 ) . strip ( ) histogram = collapseAdjacentCStrings ( histogram ) if not histogram or histogram [ 0 ] != '"' or histogram [ - 1 ] != '"' : logNonLiteralHistogram ( filename , histogram ) continue histogram_stripped = histogram . strip ( '"' ) if '"' in histogram_stripped : logNonLiteralHistogram ( filename , histogram ) continue if histogram_stripped not in histograms : histograms . add ( histogram_stripped ) location_map [ histogram_stripped ] = '%s:%d' % ( filename , line_number ) return histograms , location_map
Searches the Chromium source for all histogram names.
Searches the Chromium source for all histogram names .
"""Searches the Chromium source for all histogram names.

  Also prints warnings for any invocations of the UMA_HISTOGRAM_* macros with
  names that might vary during a single run of the app.

  Returns:
    A tuple of
      a set containing any found literal histogram names, and
      a set mapping histogram name to first filename:line where it was found
  """ # Use git grep to find all invocations of the UMA_HISTOGRAM_* macros. # Examples: #   'path/to/foo.cc:420:  UMA_HISTOGRAM_COUNTS_100("FooGroup.FooName",' #   'path/to/bar.cc:632:  UMA_HISTOGRAM_ENUMERATION(' # TODO(isherman): Look for histogram function calls like # base::UmaHistogramSparse() in addition to macro invocations. # Must begin and end with a quotation mark. # Must not include any quotation marks other than at the beginning or end.
A tuple of
a set containing any found literal histogram names, and
a set mapping histogram name to first filename:line where it was found
A tuple of a set containing any found literal histogram names and a set mapping histogram name to first filename : line where it was found