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

Side by Side Diff: tools/metrics/histograms/update_net_error_codes.py

Issue 1143323006: Histograms.xml python script housekeeping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bad_message
Patch Set: Fix imports (sadface) Created 5 years, 6 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
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 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 """Updates NetErrorCodes enum in histograms.xml file with values read 6 """Updates NetErrorCodes enum in histograms.xml file with values read
7 from net_error_list.h. 7 from net_error_list.h.
8 8
9 If the file was pretty-printed, the updated version is pretty-printed too. 9 If the file was pretty-printed, the updated version is pretty-printed too.
10 """ 10 """
11 11
12 import os.path 12 import os.path
13 import re 13 import re
14 import sys 14 import sys
15 15
16 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common')) 16 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'common'))
17 from update_histogram_enum import UpdateHistogramFromDict 17 import path_util
18 18
19 NET_ERROR_LIST_PATH = '../../../net/base/net_error_list.h' 19 import update_histogram_enum
20
21 NET_ERROR_LIST_PATH = 'net/base/net_error_list.h'
20 22
21 POSITIVE_ERROR_REGEX = re.compile(r'^NET_ERROR\(([\w]+), -([0-9]+)\)') 23 POSITIVE_ERROR_REGEX = re.compile(r'^NET_ERROR\(([\w]+), -([0-9]+)\)')
22 NEGATIVE_ERROR_REGEX = re.compile(r'^NET_ERROR\(([\w]+), (-[0-9]+)\)') 24 NEGATIVE_ERROR_REGEX = re.compile(r'^NET_ERROR\(([\w]+), (-[0-9]+)\)')
23 25
24 def ReadNetErrorCodes(filename, error_regex): 26 def ReadNetErrorCodes(filename, error_regex):
25 """Reads in values from net_error_list.h, returning a dictionary mapping 27 """Reads in values from net_error_list.h, returning a dictionary mapping
26 error code to error name. 28 error code to error name.
27 """ 29 """
28 # Read the file as a list of lines 30 # Read the file as a list of lines
29 with open(filename) as f: 31 with open(path_util.GetInputFile(filename)) as f:
30 content = f.readlines() 32 content = f.readlines()
31 33
32 # Parse out lines that are net errors. 34 # Parse out lines that are net errors.
33 errors = {} 35 errors = {}
34 for line in content: 36 for line in content:
35 m = error_regex.match(line) 37 m = error_regex.match(line)
36 if m: 38 if m:
37 errors[int(m.group(2))] = m.group(1) 39 errors[int(m.group(2))] = m.group(1)
38 return errors 40 return errors
39 41
42
40 def main(): 43 def main():
41 if len(sys.argv) > 1: 44 if len(sys.argv) > 1:
42 print >>sys.stderr, 'No arguments expected!' 45 print >>sys.stderr, 'No arguments expected!'
43 sys.stderr.write(__doc__) 46 sys.stderr.write(__doc__)
44 sys.exit(1) 47 sys.exit(1)
45 48
46 UpdateHistogramFromDict( 49 update_histogram_enum.UpdateHistogramFromDict(
47 'NetErrorCodes', 50 'NetErrorCodes',
48 ReadNetErrorCodes(NET_ERROR_LIST_PATH, POSITIVE_ERROR_REGEX), 51 ReadNetErrorCodes(NET_ERROR_LIST_PATH, POSITIVE_ERROR_REGEX),
49 NET_ERROR_LIST_PATH) 52 NET_ERROR_LIST_PATH)
50 53
51 UpdateHistogramFromDict( 54 update_histogram_enum.UpdateHistogramFromDict(
52 'CombinedHttpResponseAndNetErrorCode', 55 'CombinedHttpResponseAndNetErrorCode',
53 ReadNetErrorCodes(NET_ERROR_LIST_PATH, NEGATIVE_ERROR_REGEX), 56 ReadNetErrorCodes(NET_ERROR_LIST_PATH, NEGATIVE_ERROR_REGEX),
54 NET_ERROR_LIST_PATH) 57 NET_ERROR_LIST_PATH)
55 58
56 if __name__ == '__main__': 59 if __name__ == '__main__':
57 main() 60 main()
OLDNEW
« no previous file with comments | « tools/metrics/histograms/update_histogram_enum.py ('k') | tools/metrics/histograms/update_policies.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698