OLD | NEW |
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Profile reporting service.""" | 5 """Profile reporting service.""" |
6 | 6 |
7 import datetime | 7 import datetime |
8 import logging | 8 import logging |
9 | 9 |
10 import simplejson as json | 10 import simplejson as json |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 self.response.out.write(json.dumps(data, separators=(',',':'))) | 77 self.response.out.write(json.dumps(data, separators=(',',':'))) |
78 | 78 |
79 def post(self): | 79 def post(self): |
80 """Adds a new profile report. | 80 """Adds a new profile report. |
81 | 81 |
82 Anyone can add a report. | 82 Anyone can add a report. |
83 """ | 83 """ |
84 blacklist = ('timestamp', 'executable', 'first_arg') | 84 blacklist = ('timestamp', 'executable', 'first_arg') |
85 required = ('argv', 'duration', 'platform', 'domain') | 85 required = ('argv', 'duration', 'platform', 'domain') |
86 accepted_keys = list(set(ProfileReport.properties()) - set(blacklist)) | 86 accepted_keys = list(set(ProfileReport.properties()) - set(blacklist)) |
| 87 arguments = self.request.arguments() |
87 kwargs = dict( | 88 kwargs = dict( |
88 (k, self.request.get(k)) for k in accepted_keys if k in self.request) | 89 (k, self.request.get(k)) for k in accepted_keys if k in arguments) |
89 | 90 |
90 if not all(kwargs.get(k, None) for k in required): | 91 if not all(kwargs.get(k, None) for k in required): |
91 logging.info('missing required keys. %r' % kwargs) | 92 logging.info('missing required keys. %r' % kwargs) |
92 self.response.out.write('fail') | 93 self.response.out.write('fail') |
93 return | 94 return |
94 | 95 |
95 try: | 96 try: |
96 kwargs['duration'] = float(kwargs['duration']) | 97 kwargs['duration'] = float(kwargs['duration']) |
97 except ValueError: | 98 except ValueError: |
98 logging.info('duration(%s) is invalid' % kwargs['duration']) | 99 logging.info('duration(%s) is invalid' % kwargs['duration']) |
(...skipping 11 matching lines...) Expand all Loading... |
110 """A cron job.""" | 111 """A cron job.""" |
111 @utils.work_queue_only | 112 @utils.work_queue_only |
112 def get(self): | 113 def get(self): |
113 """Delete reports older than ~6 months.""" | 114 """Delete reports older than ~6 months.""" |
114 cutoff = datetime.datetime.now() - datetime.timedelta(days=31*6) | 115 cutoff = datetime.datetime.now() - datetime.timedelta(days=31*6) |
115 # Will only delete 1000 reports at a time max. Shouldn't be a problem unless | 116 # Will only delete 1000 reports at a time max. Shouldn't be a problem unless |
116 # we get more than 1000 reports/day. | 117 # we get more than 1000 reports/day. |
117 for report in db.Query(ProfileReport, keys_only=True).filter( | 118 for report in db.Query(ProfileReport, keys_only=True).filter( |
118 'date <', cutoff): | 119 'date <', cutoff): |
119 db.delete(report) | 120 db.delete(report) |
OLD | NEW |