Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 """Util functions for git repository processing.""" | 5 """Util functions for git repository processing.""" |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import hashlib | 8 import hashlib |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| 11 import os | 11 import os |
| 12 import pickle | 12 import pickle |
| 13 import re | 13 import re |
| 14 import subprocess | 14 import subprocess |
| 15 import traceback | 15 import traceback |
| 16 import urllib2 | 16 import urllib2 |
| 17 | 17 |
| 18 import dev_appserver | 18 import dev_appserver |
| 19 dev_appserver.fix_sys_path() | 19 dev_appserver.fix_sys_path() |
| 20 | 20 |
| 21 from common import appengine_util | 21 from common import appengine_util |
| 22 | 22 |
| 23 # TODO(katesonia): move host to azalea host after migration. | 23 # TODO(katesonia): move host to predator host after migration. |
| 24 _FEEDBACK_URL_TEMPLATE = 'host/crash/fracas-result-feedback?key=%s' | 24 _FRACAS_FEEDBACK_URL_TEMPLATE = ( |
| 25 'https://%s.appspot.com/crash/fracas-result-feedback?key=%s') | |
| 25 GIT_HASH_PATTERN = re.compile(r'^[0-9a-fA-F]{40}$') | 26 GIT_HASH_PATTERN = re.compile(r'^[0-9a-fA-F]{40}$') |
| 26 | 27 |
| 27 | 28 |
| 28 # TODO(crbug.com/662540): Add unittests. | 29 # TODO(crbug.com/662540): Add unittests. |
| 29 def GenerateFileName(*args): # pragma: no cover | 30 def GenerateFileName(*args): # pragma: no cover |
| 30 """Encodes args and returns the generated result file.""" | 31 """Encodes args and returns the generated result file.""" |
| 31 return hashlib.md5(pickle.dumps(args)).hexdigest() | 32 return hashlib.md5(pickle.dumps(args)).hexdigest() |
| 32 | 33 |
| 33 | 34 |
| 34 # TODO(crbug.com/662540): Add unittests. | 35 # TODO(crbug.com/662540): Add unittests. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 55 # TODO(crbug.com/662540): Add unittests. | 56 # TODO(crbug.com/662540): Add unittests. |
| 56 def EnsureDirExists(path): # pragma: no cover | 57 def EnsureDirExists(path): # pragma: no cover |
| 57 directory = os.path.dirname(path) | 58 directory = os.path.dirname(path) |
| 58 if os.path.exists(directory): | 59 if os.path.exists(directory): |
| 59 return | 60 return |
| 60 | 61 |
| 61 os.makedirs(directory) | 62 os.makedirs(directory) |
| 62 | 63 |
| 63 | 64 |
| 64 # TODO(crbug.com/662540): Add unittests. | 65 # TODO(crbug.com/662540): Add unittests. |
| 65 def FlushResult(result, result_path): # pragma: no cover | 66 def FlushResult(result, result_path, serializer=pickle): # pragma: no cover |
| 66 logging.info('\nFlushing results to %s', result_path) | 67 print '\nFlushing results to', result_path |
| 67 EnsureDirExists(result_path) | 68 EnsureDirExists(result_path) |
| 68 with open(result_path, 'wb') as f: | 69 with open(result_path, 'wb') as f: |
| 69 pickle.dump(result, f) | 70 serializer.dump(result, f) |
| 70 | 71 |
| 71 | 72 |
| 72 # TODO(crbug.com/662540): Add unittests. | 73 # TODO(crbug.com/662540): Add unittests. |
| 73 def PrintDelta(deltas, crash_num): # pragma: no cover | 74 def PrintDelta(deltas, crash_num, app_id): # pragma: no cover |
| 74 logging.info(('\n+++++++++++++++++++++' | 75 print ('\n+++++++++++++++++++++' |
| 75 '\nDelta on %d crashes ' | 76 '\nDelta on %d crashes ' |
| 76 '\n+++++++++++++++++++++'), crash_num) | 77 '\n+++++++++++++++++++++') % crash_num |
| 77 | 78 |
| 78 if not deltas: | 79 if not deltas: |
| 79 logging.info('Two sets of results are the same.') | 80 print 'Two sets of results are the same.' |
| 80 return | 81 return |
| 81 | 82 |
| 82 for crash_id, delta in deltas.iteritems(): | 83 for crash_id, delta in deltas.iteritems(): |
| 83 logging.info('\nCrash: %s\n%s\n', | 84 print '\nCrash: %s\n%s\n' % ( |
| 84 _FEEDBACK_URL_TEMPLATE % crash_id, | 85 _FRACAS_FEEDBACK_URL_TEMPLATE % (app_id, crash_id), str(delta)) |
| 85 str(delta)) | |
| 86 | 86 |
| 87 | 87 |
| 88 # TODO(crbug.com/662540): Add unittests. | 88 # TODO(crbug.com/662540): Add unittests. |
| 89 def WriteDeltaToCSV(deltas, crash_num, | 89 def WriteDeltaToCSV(deltas, crash_num, app_id, |
| 90 git_hash1, git_hash2, file_path): # pragma: no cover | 90 git_hash1, git_hash2, file_path): # pragma: no cover |
| 91 EnsureDirExists(file_path) | 91 EnsureDirExists(file_path) |
| 92 def _EncodeStr(string): | 92 def _EncodeStr(string): |
| 93 return string.replace('\"', '\'') if string else '' | 93 return string.replace('\"', '\'') if string else '' |
| 94 | 94 |
| 95 logging.info('Writing delta diff to %s\n', file_path) | 95 print 'Writing delta diff to %s\n' % file_path |
|
stgao
2016/11/17 05:03:05
Why we switch from logging to print? I thought log
Sharu Jiang
2016/11/17 09:03:15
The problem is that we have tons of loggings insid
| |
| 96 with open(file_path, 'wb') as f: | 96 with open(file_path, 'wb') as f: |
| 97 f.write('Delta between githash1 %s and githash2 %s on %d crashes\n' % ( | 97 f.write('Delta between githash1 %s and githash2 %s on %d crashes\n\n' % ( |
| 98 git_hash1, git_hash2, crash_num)) | 98 git_hash1, git_hash2, crash_num)) |
| 99 f.write('project, components, cls, regression_range\n') | 99 f.write('crash url, project, components, cls, regression_range\n') |
| 100 for crash_id, delta in deltas.iteritems(): | 100 for crash_id, delta in deltas.iteritems(): |
| 101 delta_str_dict = delta.delta_str_dict | 101 delta_str_dict = delta.delta_str_dict |
| 102 feedback_url = _FEEDBACK_URL_TEMPLATE % crash_id | 102 feedback_url = _FRACAS_FEEDBACK_URL_TEMPLATE % (app_id, crash_id) |
| 103 f.write('%s, "%s", "%s", "%s", "%s"\n' % ( | 103 f.write('%s, "%s", "%s", "%s", "%s"\n' % ( |
| 104 feedback_url, | 104 feedback_url, |
| 105 _EncodeStr(delta_str_dict.get('project', '')), | 105 _EncodeStr(delta_str_dict.get('suspected_project', '')), |
| 106 _EncodeStr(delta_str_dict.get('components', '')), | 106 _EncodeStr(delta_str_dict.get('suspected_components', '')), |
| 107 _EncodeStr(delta_str_dict.get('cls', '')), | 107 _EncodeStr(delta_str_dict.get('suspected_cls', '')), |
| 108 _EncodeStr(delta_str_dict.get('regression_range', '')) | 108 _EncodeStr(delta_str_dict.get('regression_range', '')) |
| 109 )) | 109 )) |
| OLD | NEW |