1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 class RevisionState(object):
7 """Contains bisect state for a given revision.
10 depot: The depot that this revision is from (e.g. WebKit).
11 revision: Revision number (Git hash or SVN number).
12 index: Position of the state in the list of all revisions.
13 value: Value(s) returned from the test.
14 perf_time: Time that a test took.
15 build_time: Time that a build took.
16 passed: Represents whether the performance test was successful at that
17 revision. Possible values include: 1 (passed), 0 (failed),
18 '?' (skipped), 'F' (build failed).
19 external: If the revision is a 'src' revision, 'external' contains the
20 revisions of each of the external libraries.
23 def __init__(self
, depot
, revision
, index
):
25 self
.revision
= revision
33 # TODO(sergiyb): Update() to parse run_results from the RunTest.
36 class BisectState(object):
37 """Represents a state of the bisect as a collection of revision states."""
39 def __init__(self
, depot
, revisions
):
40 """Initializes a new BisectState object with a set of revision states.
43 depot: Name of the depot used for initial set of revision states.
44 revisions: List of revisions used for initial set of revision states.
46 self
.revision_states
= []
47 self
.revision_index
= {}
50 for revision
in revisions
:
51 new_state
= self
._InitRevisionState
(depot
, revision
, index
)
52 self
.revision_states
.append(new_state
)
56 def _RevisionKey(depot
, revision
):
57 return "%s:%s" % (depot
, revision
)
59 def _InitRevisionState(self
, depot
, revision
, index
):
60 key
= self
._RevisionKey
(depot
, revision
)
61 self
.revision_index
[key
] = index
62 return RevisionState(depot
, revision
, index
)
64 def GetRevisionState(self
, depot
, revision
):
65 """Returns a mutable revision state."""
66 key
= self
._RevisionKey
(depot
, revision
)
67 index
= self
.revision_index
.get(key
)
68 return self
.revision_states
[index
] if index
else None
70 def CreateRevisionStatesAfter(self
, depot
, revisions
, reference_depot
,
72 """Creates a set of new revision states after a specified reference state.
75 depot: Name of the depot for the new revision states.
76 revisions: List of revisions for the new revision states.
77 reference_depot: Name of the depot for the reference revision state.
78 reference_revision: Revision for the reference revision state.
81 A list containing all created revision states in order as they were added.
83 ref_key
= self
._RevisionKey
(reference_depot
, reference_revision
)
84 ref_index
= self
.revision_index
[ref_key
]
85 num_new_revisions
= len(revisions
)
86 for entry
in self
.revision_states
:
87 if entry
.index
> ref_index
:
88 entry
.index
+= num_new_revisions
90 first_index
= ref_index
+ 1
91 for index
, revision
in enumerate(revisions
, start
=first_index
):
92 new_state
= self
._InitRevisionState
(depot
, revision
, index
)
93 self
.revision_states
.insert(index
, new_state
)
95 return self
.revision_states
[first_index
:first_index
+ num_new_revisions
]
97 def GetRevisionStates(self
):
98 """Returns a copy of the list of the revision states."""
99 return list(self
.revision_states
)