Increase net_unittest verbosity in isolate mode
[chromium-blink-merge.git] / chrome / tools / extract_histograms.py
blob82fc9e955a5e4461b41071160133e2d02d7aca38
1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Extract UMA histogram strings from the Chrome source.
8 This program generates the list of known histograms we expect to see in
9 the user behavior logs. It walks the Chrome source, looking for calls
10 to UMA histogram macros.
12 Run it from the chrome/browser directory like:
13 extract_histograms.py > histogram_list
14 """
16 # TODO(evanm): get all the jankometer histogram names.
18 __author__ = 'evanm (Evan Martin)'
20 import os
21 import re
22 import sys
24 def GrepForHistograms(path, histograms):
25 """Grep a source file for calls to histogram macros functions.
27 Arguments:
28 path: path to the file
29 histograms: set of histograms to add to
30 """
32 histogram_re = re.compile(r'HISTOGRAM_\w+\(L"(.*)"')
33 for line in open(path):
34 match = histogram_re.search(line)
35 if match:
36 histograms.add(match.group(1))
39 def WalkDirectory(root_path, histograms):
40 for path, dirs, files in os.walk(root_path):
41 if '.svn' in dirs:
42 dirs.remove('.svn')
43 for file in files:
44 ext = os.path.splitext(file)[1]
45 if ext == '.cc':
46 GrepForHistograms(os.path.join(path, file), histograms)
49 def main(argv):
50 histograms = set()
52 # Walk the source tree to process all .cc files.
53 WalkDirectory('..', histograms)
55 # Print out the histograms as a sorted list.
56 for histogram in sorted(histograms):
57 print histogram
58 return 0
61 if '__main__' == __name__:
62 sys.exit(main(sys.argv))