OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2006-2008 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 # Issue a series of GetHash requests to the SafeBrowsing servers and measure the | 6 """Issue a series of GetHash requests to the SafeBrowsing servers and measure |
7 # response times. | 7 the response times. |
8 # | 8 |
9 # Usage: | 9 Usage: |
10 # | 10 |
11 # $ ./gethash_timer.py --period=600 --samples=20 --output=resp.csv | 11 $ ./gethash_timer.py --period=600 --samples=20 --output=resp.csv |
12 # | 12 |
13 # --period (or -p): The amount of time (in seconds) to wait between GetHash | 13 --period (or -p): The amount of time (in seconds) to wait between GetHash |
14 # requests. Using a value of more than 300 (5 minutes) to | 14 requests. Using a value of more than 300 (5 minutes) to |
15 # include the effect of DNS. | 15 include the effect of DNS. |
16 # | 16 |
17 # --samples (or -s): The number of requests to issue. If this parameter is not | 17 --samples (or -s): The number of requests to issue. If this parameter is not |
18 # specified, the test will run indefinitely. | 18 specified, the test will run indefinitely. |
19 # | 19 |
20 # --output (or -o): The path to a file where the output will be written in | 20 --output (or -o): The path to a file where the output will be written in |
21 # CSV format: sample_number,response_code,elapsed_time_ms | 21 CSV format: sample_number,response_code,elapsed_time_ms |
| 22 """ |
22 | 23 |
23 import getopt | 24 import getopt |
24 import httplib | 25 import httplib |
25 import sys | 26 import sys |
26 import time | 27 import time |
27 | 28 |
28 _GETHASH_HOST = 'safebrowsing.clients.google.com' | 29 _GETHASH_HOST = 'safebrowsing.clients.google.com' |
29 _GETHASH_REQUEST = '/safebrowsing/gethash?client=googleclient&appver=1.0&pver=2.
1' | 30 _GETHASH_REQUEST = ( |
| 31 '/safebrowsing/gethash?client=googleclient&appver=1.0&pver=2.1') |
30 | 32 |
31 # Global logging file handle. | 33 # Global logging file handle. |
32 g_file_handle = None | 34 g_file_handle = None |
33 | 35 |
34 | 36 |
35 def IssueGetHash(prefix): | 37 def IssueGetHash(prefix): |
36 '''Issue one GetHash request to the safebrowsing servers. | 38 '''Issue one GetHash request to the safebrowsing servers. |
37 Args: | 39 Args: |
38 prefix: A 4 byte value to look up on the server. | 40 prefix: A 4 byte value to look up on the server. |
39 Returns: | 41 Returns: |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 '''Open a file for logging results. | 110 '''Open a file for logging results. |
109 Args: | 111 Args: |
110 file_name: A path to a file to store the output. | 112 file_name: A path to a file to store the output. |
111 Returns: | 113 Returns: |
112 None. | 114 None. |
113 ''' | 115 ''' |
114 global g_file_handle | 116 global g_file_handle |
115 g_file_handle = open(file_name, 'w') | 117 g_file_handle = open(file_name, 'w') |
116 | 118 |
117 | 119 |
118 if __name__ == '__main__': | 120 def main(): |
119 period = 10 | 121 period = 10 |
120 samples = None | 122 samples = None |
121 | 123 |
122 options, args = getopt.getopt(sys.argv[1:], | 124 options, args = getopt.getopt(sys.argv[1:], |
123 's:p:o:', | 125 's:p:o:', |
124 ['samples=', 'period=', 'output=']) | 126 ['samples=', 'period=', 'output=']) |
125 for option, value in options: | 127 for option, value in options: |
126 if option == '-s' or option == '--samples': | 128 if option == '-s' or option == '--samples': |
127 samples = int(value) | 129 samples = int(value) |
128 elif option == '-p' or option == '--period': | 130 elif option == '-p' or option == '--period': |
129 period = float(value) | 131 period = float(value) |
130 elif option == '-o' or option == '--output': | 132 elif option == '-o' or option == '--output': |
131 file_name = value | 133 file_name = value |
132 else: | 134 else: |
133 print 'Bad option: %s' % option | 135 print 'Bad option: %s' % option |
134 sys.exit(1) | 136 return 1 |
135 try: | 137 try: |
136 print 'Starting Timed GetHash ----------' | 138 print 'Starting Timed GetHash ----------' |
137 SetupOutputFile(file_name) | 139 SetupOutputFile(file_name) |
138 RunTimedGetHash(period, samples) | 140 RunTimedGetHash(period, samples) |
139 except KeyboardInterrupt: | 141 except KeyboardInterrupt: |
140 pass | 142 pass |
141 | 143 |
142 print 'Timed GetHash complete ----------' | 144 print 'Timed GetHash complete ----------' |
143 g_file_handle.close() | 145 g_file_handle.close() |
144 | 146 |
| 147 |
| 148 if __name__ == '__main__': |
| 149 sys.exit(main()) |
OLD | NEW |