Chromium Code Reviews| Index: tools/metrics/actions/extract_actions.py |
| diff --git a/tools/metrics/actions/extract_actions.py b/tools/metrics/actions/extract_actions.py |
| index c7f550f6981f20f64ba124321b25639e6387a2e0..9231c39bc9c40898333258e3311ae802d9a3987e 100755 |
| --- a/tools/metrics/actions/extract_actions.py |
| +++ b/tools/metrics/actions/extract_actions.py |
| @@ -14,7 +14,6 @@ there are many possible actions. |
| See also: |
| base/metrics/user_metrics.h |
| - http://wiki.corp.google.com/twiki/bin/view/Main/ChromeUserExperienceMetrics |
| After extracting all actions, the content will go through a pretty print |
| function to make sure it's well formatted. If the file content needs to be |
| @@ -42,6 +41,10 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) |
| import diff_util |
| import pretty_print_xml |
| +USER_METRICS_ACTION_RE = re.compile(r'UserMetricsAction\(\s*(.+?)\)') |
|
Ilya Sherman
2015/01/09 22:25:43
nit: I think it might be worth using the verbose r
Ilya Sherman
2015/01/09 22:25:44
It looks like you've changed the regexes quite a b
Alexei Svitkine (slow)
2015/01/12 19:58:24
I've re-added it now.
Alexei Svitkine (slow)
2015/01/12 19:58:24
Done.
|
| +COMPUTED_ACTION_RE = re.compile(r'RecordComputedAction') |
| +QUOTED_STRING_RE = re.compile(r'\"(.+?)\"') |
| + |
| # Files that are known to use content::RecordComputedAction(), which means |
| # they require special handling code in this script. |
| # To add a new file, add it to this list and add the appropriate logic to |
| @@ -410,6 +413,21 @@ def AddExtensionActions(actions): |
| # Actions sent by 'Ok Google' Hotwording. |
| actions.add('Hotword.HotwordTrigger') |
| +def FindActionNames(contents, pos): |
| + """Finds actions from the first UserMetricsAction() call in |contents|. |
| + |
| + Arguments: |
| + contents: string to search through |
| + pos: position in |contents| to start the search from |
| + |
| + Returns: |
| + The list action names (strings) that was found. |
|
Ilya Sherman
2015/01/09 22:25:43
Please update this -- it looks like there are two
Alexei Svitkine (slow)
2015/01/12 19:58:24
Done.
|
| + """ |
| + match = USER_METRICS_ACTION_RE.search(contents, pos=pos) |
| + if not match: |
| + return None, None |
| + return QUOTED_STRING_RE.findall(match.group(1)), match.end() |
| + |
| def GrepForActions(path, actions): |
| """Grep a source file for calls to UserMetrics functions. |
| @@ -419,22 +437,19 @@ def GrepForActions(path, actions): |
| """ |
| global number_of_files_total |
| number_of_files_total = number_of_files_total + 1 |
| - # we look for the UserMetricsAction structure constructor |
| - # this should be on one line |
| - action_re = re.compile(r'[^a-zA-Z]UserMetricsAction\("([^"]*)') |
| - malformed_action_re = re.compile(r'[^a-zA-Z]UserMetricsAction\([^"]') |
| - computed_action_re = re.compile(r'RecordComputedAction') |
| + |
| + contents = open(path).read() |
| + pos = 0 |
| + while True: |
| + action_names, pos = FindActionNames(contents, pos) |
| + if not action_names: |
| + break |
| + actions.update(action_names) |
| + |
| line_number = 0 |
| for line in open(path): |
| line_number = line_number + 1 |
| - match = action_re.search(line) |
| - if match: # Plain call to RecordAction |
| - actions.add(match.group(1)) |
| - elif malformed_action_re.search(line): |
| - # Warn if this line is using RecordAction incorrectly. |
| - print >>sys.stderr, ('WARNING: %s has malformed call to RecordAction' |
| - ' at %d' % (path, line_number)) |
| - elif computed_action_re.search(line): |
| + if COMPUTED_ACTION_RE.search(line): |
| # Warn if this file shouldn't be calling RecordComputedAction. |
| if os.path.basename(path) not in KNOWN_COMPUTED_USERS: |
| print >>sys.stderr, ('WARNING: %s has RecordComputedAction at %d' % |