pub fn estimate(snapshot: &Snapshot, expected: &Expected, now: Duration) -> f64Expand description
Estimates the fraction done of a build, from 0 to 1: the fraction of the
root row of snapshot, with its rows weighed by expected.
now is the host’s time, from the same origin as the times the host’s
observer returned; the caller reads it. The function keeps no memory and
reads no clock.
The fraction of a row:
| Row | Fraction |
|---|---|
Finished or Failed | 1 |
Pending | 0 |
NotRun | left out of its parent’s fraction |
Running, with a count | (done + the fractions of its running children) / total, at most 1 |
Running, no count, with children | the weighted average of its children’s fractions |
Running, no count, no children | the time since it started / the duration of a whole row of its kind, at most 0.95; 0 when either is unknown |
A child of a counted row stands for one of the counted units. A count whose total is zero counts as no count.
The weight of a row, where its parent averages its children, is the first of:
- for a row that has ended with both times, the time it took;
- for a row with a count, whose kind has a duration per unit, that duration times its total;
- for a row whose kind has a duration for a whole row, that duration;
- otherwise the median of the weights that the first three rules gave among its siblings, and 1 when they gave none.
A parent’s own weight comes from these rules applied to it, never from the sum of its children, so a row declared late changes the fraction of its parent and the share of no other row.
Two consequences for a display:
- The fraction can decrease from one call to the next: the total of a row, known when it starts, replaces the duration of a whole row in its weight, and a row declared late lowers the fraction of its parent. A row declared in advance and then not run moves the fraction forward instead. A display keeps the highest value it has shown, and shows the whole only when the root row has finished.
- Under batches that run in parallel, the fraction is representative of the work done, not a measure of the time left.