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

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

Issue 6266011: chromeos: Simplify user action code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser
Patch Set: only insert user actions when metrics collection is started Created 9 years, 11 months 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/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 UserMetrics "actions" strings from the Chrome source. 6 """Extract UserMetrics "actions" strings from the Chrome source.
7 7
8 This program generates the list of known actions we expect to see in the 8 This program generates the list of known actions we expect to see in the
9 user behavior logs. It walks the Chrome source, looking for calls to 9 user behavior logs. It walks the Chrome source, looking for calls to
10 UserMetrics functions, extracting actions and warning on improper calls, 10 UserMetrics functions, extracting actions and warning on improper calls,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 # Actions for language_options_handler.cc (Chrome OS specific). 127 # Actions for language_options_handler.cc (Chrome OS specific).
128 for input_method_id in INPUT_METHOD_IDS: 128 for input_method_id in INPUT_METHOD_IDS:
129 actions.add('LanguageOptions_DisableInputMethod_%s' % input_method_id) 129 actions.add('LanguageOptions_DisableInputMethod_%s' % input_method_id)
130 actions.add('LanguageOptions_EnableInputMethod_%s' % input_method_id) 130 actions.add('LanguageOptions_EnableInputMethod_%s' % input_method_id)
131 actions.add('InputMethodOptions_Open_%s' % input_method_id) 131 actions.add('InputMethodOptions_Open_%s' % input_method_id)
132 for language_code in LANGUAGE_CODES: 132 for language_code in LANGUAGE_CODES:
133 actions.add('LanguageOptions_UiLanguageChange_%s' % language_code) 133 actions.add('LanguageOptions_UiLanguageChange_%s' % language_code)
134 actions.add('LanguageOptions_SpellCheckLanguageChange_%s' % language_code) 134 actions.add('LanguageOptions_SpellCheckLanguageChange_%s' % language_code)
135 135
136 # Actions sent by the Chrome OS window manager.
137 actions.add('Accel_NextWindow_Tab')
138 actions.add('Accel_PrevWindow_Tab')
139 actions.add('Accel_NextWindow_F5')
140 actions.add('Accel_PrevWindow_F5')
141
142 # Actions sent by the Chrome OS power manager.
143 actions.add('Accel_BrightnessDown_F6')
144 actions.add('Accel_BrightnessUp_F7')
145
146 def AddWebKitEditorActions(actions): 136 def AddWebKitEditorActions(actions):
147 """Add editor actions from editor_client_impl.cc. 137 """Add editor actions from editor_client_impl.cc.
148 138
149 Arguments: 139 Arguments:
150 actions: set of actions to add to. 140 actions: set of actions to add to.
151 """ 141 """
152 action_re = re.compile(r'''\{ [\w']+, +\w+, +"(.*)" +\},''') 142 action_re = re.compile(r'''\{ [\w']+, +\w+, +"(.*)" +\},''')
153 143
154 editor_file = os.path.join(path_utils.ScriptDir(), '..', '..', 'webkit', 144 editor_file = os.path.join(path_utils.ScriptDir(), '..', '..', 'webkit',
155 'api', 'src','EditorClientImpl.cc') 145 'api', 'src','EditorClientImpl.cc')
(...skipping 29 matching lines...) Expand all
185 for line in open(about_flags): 175 for line in open(about_flags):
186 match = flag_name_re.search(line) 176 match = flag_name_re.search(line)
187 if match: 177 if match:
188 actions.add("AboutFlags_" + match.group(1)) 178 actions.add("AboutFlags_" + match.group(1))
189 # If the line contains the marker but was not matched by the regex, put up 179 # If the line contains the marker but was not matched by the regex, put up
190 # an error if the line is not a comment. 180 # an error if the line is not a comment.
191 elif 'FLAGS:RECORD_UMA' in line and line[0:2] != '//': 181 elif 'FLAGS:RECORD_UMA' in line and line[0:2] != '//':
192 print >>sys.stderr, 'WARNING: This line is marked for recording ' + \ 182 print >>sys.stderr, 'WARNING: This line is marked for recording ' + \
193 'about:flags metrics, but is not in the proper format:\n' + line 183 'about:flags metrics, but is not in the proper format:\n' + line
194 184
185 def AddChromeOSActions(actions):
186 """Add actions reported by non-Chrome processes in Chrome OS.
187
188 Arguments:
189 actions: set of actions to add to.
190 """
191 # Actions sent by the Chrome OS window manager.
192 actions.add('Accel_NextWindow_Tab')
193 actions.add('Accel_PrevWindow_Tab')
194 actions.add('Accel_NextWindow_F5')
195 actions.add('Accel_PrevWindow_F5')
196
197 # Actions sent by the Chrome OS power manager.
198 actions.add('Accel_BrightnessDown_F6')
199 actions.add('Accel_BrightnessUp_F7')
200
195 def GrepForActions(path, actions): 201 def GrepForActions(path, actions):
196 """Grep a source file for calls to UserMetrics functions. 202 """Grep a source file for calls to UserMetrics functions.
197 203
198 Arguments: 204 Arguments:
199 path: path to the file 205 path: path to the file
200 actions: set of actions to add to 206 actions: set of actions to add to
201 """ 207 """
202 global number_of_files_total 208 global number_of_files_total
203 number_of_files_total = number_of_files_total + 1 209 number_of_files_total = number_of_files_total + 1
204 # we look for the UserMetricsAction structure constructor 210 # we look for the UserMetricsAction structure constructor
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 chrome_root = os.path.join(path_utils.ScriptDir(), '..') 263 chrome_root = os.path.join(path_utils.ScriptDir(), '..')
258 WalkDirectory(chrome_root, actions) 264 WalkDirectory(chrome_root, actions)
259 webkit_root = os.path.join(path_utils.ScriptDir(), '..', '..', 'webkit') 265 webkit_root = os.path.join(path_utils.ScriptDir(), '..', '..', 'webkit')
260 WalkDirectory(os.path.join(webkit_root, 'glue'), actions) 266 WalkDirectory(os.path.join(webkit_root, 'glue'), actions)
261 WalkDirectory(os.path.join(webkit_root, 'port'), actions) 267 WalkDirectory(os.path.join(webkit_root, 'port'), actions)
262 268
263 # print "Scanned {0} number of files".format(number_of_files_total) 269 # print "Scanned {0} number of files".format(number_of_files_total)
264 # print "Found {0} entries".format(len(actions)) 270 # print "Found {0} entries".format(len(actions))
265 271
266 AddClosedSourceActions(actions) 272 AddClosedSourceActions(actions)
273 AddChromeOSActions(actions)
267 274
268 if hash_output: 275 if hash_output:
269 f = open(chromeactions_path, "w") 276 f = open(chromeactions_path, "w")
270 277
271 278
272 # Print out the actions as a sorted list. 279 # Print out the actions as a sorted list.
273 for action in sorted(actions): 280 for action in sorted(actions):
274 if hash_output: 281 if hash_output:
275 hash = hashlib.md5() 282 hash = hashlib.md5()
276 hash.update(action) 283 hash.update(action)
277 print >>f, '0x%s\t%s' % (hash.hexdigest()[:16], action) 284 print >>f, '0x%s\t%s' % (hash.hexdigest()[:16], action)
278 else: 285 else:
279 print action 286 print action
280 287
281 if hash_output: 288 if hash_output:
282 print "Done. Do not forget to add chromeactions.txt to your changelist" 289 print "Done. Do not forget to add chromeactions.txt to your changelist"
283 290
284 if '__main__' == __name__: 291 if '__main__' == __name__:
285 main(sys.argv) 292 main(sys.argv)
OLDNEW
« chrome/browser/chromeos/external_metrics.cc ('K') | « chrome/tools/chromeactions.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698