Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/tools/extract_histograms.py

Issue 8680018: Fix python scripts in src/chrome/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/env python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extract UMA histogram strings from the Chrome source. 6 """Extract UMA histogram strings from the Chrome source.
7 7
8 This program generates the list of known histograms we expect to see in 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 9 the user behavior logs. It walks the Chrome source, looking for calls
10 to UMA histogram macros. 10 to UMA histogram macros.
11 11
(...skipping 16 matching lines...) Expand all
28 path: path to the file 28 path: path to the file
29 histograms: set of histograms to add to 29 histograms: set of histograms to add to
30 """ 30 """
31 31
32 histogram_re = re.compile(r'HISTOGRAM_\w+\(L"(.*)"') 32 histogram_re = re.compile(r'HISTOGRAM_\w+\(L"(.*)"')
33 for line in open(path): 33 for line in open(path):
34 match = histogram_re.search(line) 34 match = histogram_re.search(line)
35 if match: 35 if match:
36 histograms.add(match.group(1)) 36 histograms.add(match.group(1))
37 37
38
38 def WalkDirectory(root_path, histograms): 39 def WalkDirectory(root_path, histograms):
39 for path, dirs, files in os.walk(root_path): 40 for path, dirs, files in os.walk(root_path):
40 if '.svn' in dirs: 41 if '.svn' in dirs:
41 dirs.remove('.svn') 42 dirs.remove('.svn')
42 for file in files: 43 for file in files:
43 ext = os.path.splitext(file)[1] 44 ext = os.path.splitext(file)[1]
44 if ext == '.cc': 45 if ext == '.cc':
45 GrepForHistograms(os.path.join(path, file), histograms) 46 GrepForHistograms(os.path.join(path, file), histograms)
46 47
48
47 def main(argv): 49 def main(argv):
48 histograms = set() 50 histograms = set()
49 51
50 # Walk the source tree to process all .cc files. 52 # Walk the source tree to process all .cc files.
51 WalkDirectory('..', histograms) 53 WalkDirectory('..', histograms)
52 54
53 # Print out the histograms as a sorted list. 55 # Print out the histograms as a sorted list.
54 for histogram in sorted(histograms): 56 for histogram in sorted(histograms):
55 print histogram 57 print histogram
58 return 0
59
56 60
57 if '__main__' == __name__: 61 if '__main__' == __name__:
58 main(sys.argv) 62 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698