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
16 # TODO(evanm): get all the jankometer histogram names.
18 __author__
= 'evanm (Evan Martin)'
24 def GrepForHistograms(path
, histograms
):
25 """Grep a source file for calls to histogram macros functions.
28 path: path to the file
29 histograms: set of histograms to add to
32 histogram_re
= re
.compile(r
'HISTOGRAM_\w+\(L"(.*)"')
33 for line
in open(path
):
34 match
= histogram_re
.search(line
)
36 histograms
.add(match
.group(1))
39 def WalkDirectory(root_path
, histograms
):
40 for path
, dirs
, files
in os
.walk(root_path
):
44 ext
= os
.path
.splitext(file)[1]
46 GrepForHistograms(os
.path
.join(path
, file), histograms
)
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
):
61 if '__main__' == __name__
:
62 sys
.exit(main(sys
.argv
))