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

Side by Side Diff: appengine/findit/waterfall/suspected_cl_util.py

Issue 2439553002: [Findit] Reduce redundant ndb reads by querying necessary entities ahead of time and share them amo… (Closed)
Patch Set: rebase Created 4 years, 1 month 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 # 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 from google.appengine.ext import ndb 5 from google.appengine.ext import ndb
6 6
7 from common import time_util 7 from common import time_util
8 from common.waterfall import failure_type 8 from common.waterfall import failure_type
9 from model import analysis_approach_type 9 from model import analysis_approach_type
10 from model.wf_suspected_cl import WfSuspectedCL 10 from model.wf_suspected_cl import WfSuspectedCL
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 'status': _GetsStatusFromSameFailure(suspected_cl.builds, failures), 53 'status': _GetsStatusFromSameFailure(suspected_cl.builds, failures),
54 'top_score': top_score 54 'top_score': top_score
55 } 55 }
56 else: 56 else:
57 build = suspected_cl.builds[build_key] 57 build = suspected_cl.builds[build_key]
58 if approach not in build['approaches']: 58 if approach not in build['approaches']:
59 build['approaches'].append(approach) 59 build['approaches'].append(approach)
60 60
61 suspected_cl.put() 61 suspected_cl.put()
62 62
63
63 def _RoundConfidentToInteger(confidence): 64 def _RoundConfidentToInteger(confidence):
64 return round(confidence * 100) 65 return int(round(confidence * 100))
65 66
66 67
67 def GetSuspectedCLConfidenceScore(confidences, cl_build): 68 def GetSuspectedCLConfidenceScore(confidences, cl_from_analyzed_build):
68 69 if not confidences or not cl_from_analyzed_build:
69 if not confidences or not cl_build:
70 return None 70 return None
71 71
72 if cl_build['failure_type'] == failure_type.COMPILE: 72 if cl_from_analyzed_build['failure_type'] == failure_type.COMPILE:
73 if cl_build['approaches'] == [ 73 if sorted(cl_from_analyzed_build['approaches']) == sorted([
74 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]: 74 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]):
75 return _RoundConfidentToInteger( 75 return _RoundConfidentToInteger(
76 confidences.compile_heuristic_try_job.confidence) 76 confidences.compile_heuristic_try_job.confidence)
77 elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]: 77 elif cl_from_analyzed_build['approaches'] == [
78 analysis_approach_type.TRY_JOB]:
78 return _RoundConfidentToInteger( 79 return _RoundConfidentToInteger(
79 confidences.compile_try_job.confidence) 80 confidences.compile_try_job.confidence)
80 elif (cl_build['approaches'] == [analysis_approach_type.HEURISTIC] and 81 elif (cl_from_analyzed_build['approaches'] == [
81 cl_build['top_score']): 82 analysis_approach_type.HEURISTIC] and
83 cl_from_analyzed_build['top_score']):
82 for confidences_info in confidences.compile_heuristic: 84 for confidences_info in confidences.compile_heuristic:
83 if confidences_info.score == cl_build['top_score']: 85 if confidences_info.score == cl_from_analyzed_build['top_score']:
84 return _RoundConfidentToInteger(confidences_info.confidence) 86 return _RoundConfidentToInteger(confidences_info.confidence)
85 return None 87 return None
86 else: 88 else:
87 if cl_build['approaches'] == [ 89 if sorted(cl_from_analyzed_build['approaches']) == sorted([
88 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]: 90 analysis_approach_type.HEURISTIC, analysis_approach_type.TRY_JOB]):
89 return _RoundConfidentToInteger( 91 return _RoundConfidentToInteger(
90 confidences.test_heuristic_try_job.confidence) 92 confidences.test_heuristic_try_job.confidence)
91 elif cl_build['approaches'] == [analysis_approach_type.TRY_JOB]: 93 elif cl_from_analyzed_build['approaches'] == [
94 analysis_approach_type.TRY_JOB]:
92 return _RoundConfidentToInteger(confidences.test_try_job.confidence) 95 return _RoundConfidentToInteger(confidences.test_try_job.confidence)
93 elif (cl_build['approaches'] == [analysis_approach_type.HEURISTIC] and 96 elif (cl_from_analyzed_build['approaches'] == [
94 cl_build['top_score']): 97 analysis_approach_type.HEURISTIC] and
98 cl_from_analyzed_build['top_score']):
95 for confidences_info in confidences.test_heuristic: 99 for confidences_info in confidences.test_heuristic:
96 if confidences_info.score == cl_build['top_score']: 100 if confidences_info.score == cl_from_analyzed_build['top_score']:
97 return _RoundConfidentToInteger(confidences_info.confidence) 101 return _RoundConfidentToInteger(confidences_info.confidence)
98 return None 102 return None
103
104
105 def _HasNewFailures(current_failures, new_failures):
106 """Checks if there are any new failures in the current build."""
107 if current_failures == new_failures:
108 return False
109
110 for step, tests in current_failures.iteritems():
111 if not new_failures.get(step): # New step.
112 return True
113
114 for test in tests:
115 if not test in new_failures[step]: # New test.
116 return True
117
118 return False
119
120
121 def GetSuspectedCLConfidenceScoreAndApproach(
122 confidences, cl_from_analyzed_build, cl_from_first_failed_build):
123 if not confidences or not cl_from_analyzed_build:
124 return None, None
125
126 if (cl_from_first_failed_build and not _HasNewFailures(
127 cl_from_analyzed_build.get('failures'),
128 cl_from_first_failed_build.get('failures'))):
129 # For non-first-time failures, the try job result is not recorded.
130 # If there is no new failures in current build, use first failed build to
131 # make sure the confidence score is correct.
132 cl_from_analyzed_build = cl_from_first_failed_build
133
134 confidence = GetSuspectedCLConfidenceScore(
135 confidences, cl_from_analyzed_build)
136 approach = (
137 analysis_approach_type.TRY_JOB if analysis_approach_type.TRY_JOB in
138 cl_from_analyzed_build['approaches'] else
139 analysis_approach_type.HEURISTIC)
140
141 return confidence, approach
OLDNEW
« no previous file with comments | « appengine/findit/test/findit_api_test.py ('k') | appengine/findit/waterfall/test/suspected_cl_util_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698