trees: show its phases as N of M, with progress, elapsed time and ETA (closes #113)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
trees now runs in four phases, open, read, group and write, each under the progress display scan uses, from the line naming the database to the summary line. open covers a wait on a busy database. read counts the records first, as scan's load does, then reads them against that count; group counts the directories, and write the groups. The display gains a unit so that each rate names what its phase counts; every scan phase passes files and prints as before. The tests that pinned trees' stderr now allow the phase lines between the database line and the summary. Judgement call: opening the database is a phase of its own, so there are four phases, not the three the issue sketches. Judgement call: the count and the read are separate queries, as in scan's load, so during a scan the read can end slightly past or short of its total. Model: opus-5-5
This commit is contained in:
+12
-9
@@ -72,6 +72,7 @@ func phaseLabel(phases []string, phase string) string {
|
||||
// progressParams describe one phase's progress display as it starts.
|
||||
type progressParams struct {
|
||||
label string // the phase and its place, from phaseLabel
|
||||
unit string // what the phase counts, as "files"
|
||||
total int64 // the items the phase will complete; -1 when not known
|
||||
estimate bool // total is an estimate, which the count may pass
|
||||
waitingFor string // what the phase waits for until setTotal is called
|
||||
@@ -101,6 +102,7 @@ type progress struct {
|
||||
withBar bool // bar is the library's bar, not its spinner
|
||||
widest int // the widest line bar has drawn, in columns
|
||||
label string
|
||||
unit string
|
||||
total int64
|
||||
estimate bool
|
||||
waitingFor string
|
||||
@@ -128,8 +130,9 @@ func startProgress(params progressParams, width func() int,
|
||||
now := time.Now()
|
||||
p := &progress{
|
||||
width: width, stop: make(chan struct{}), done: make(chan struct{}),
|
||||
label: params.label, total: params.total, estimate: params.estimate,
|
||||
waitingFor: params.waitingFor, start: now, rateStart: now,
|
||||
label: params.label, unit: params.unit, total: params.total,
|
||||
estimate: params.estimate, waitingFor: params.waitingFor,
|
||||
start: now, rateStart: now,
|
||||
}
|
||||
|
||||
// Show the zero state at once: the first item may take minutes,
|
||||
@@ -311,9 +314,9 @@ func (p *progress) finish() {
|
||||
//
|
||||
// [3/5] hash: [1234/5000] 25%, 300 files/s, elapsed 4s, eta 13s
|
||||
//
|
||||
// without the percent when percent is false, as before the library's
|
||||
// bar, which shows its own. A phase with no total shows the items done
|
||||
// instead, or what it waits for.
|
||||
// where "files" is the phase's unit, without the percent when percent
|
||||
// is false, as before the library's bar, which shows its own. A phase
|
||||
// with no total shows the items done instead, or what it waits for.
|
||||
//
|
||||
// The phase and its place, the progress, the elapsed time and the ETA
|
||||
// are kept whole. A line wider than room leaves out the rate, or what
|
||||
@@ -337,7 +340,7 @@ func (p *progress) line(room int, percent bool) (string, bool) {
|
||||
}
|
||||
|
||||
head = p.label + ": " + p.itemsDone(percent) + ", "
|
||||
extra = fmt.Sprintf("%.0f files/s", rate)
|
||||
extra = fmt.Sprintf("%.0f %s/s", rate, p.unit)
|
||||
tail = fmt.Sprintf("elapsed %s, eta %s", elapsed, p.eta(rate))
|
||||
}
|
||||
|
||||
@@ -355,11 +358,11 @@ func (p *progress) line(room int, percent bool) (string, bool) {
|
||||
|
||||
// itemsDone formats the items done, as "[1234/5000] 25%", with "~"
|
||||
// before a total that is an estimate and without the percent when
|
||||
// percent is false, or as "1234 files" when the phase has no total.
|
||||
// p.mu must be held.
|
||||
// percent is false, or as "1234 files", in the phase's unit, when the
|
||||
// phase has no total. p.mu must be held.
|
||||
func (p *progress) itemsDone(percent bool) string {
|
||||
if p.total < 0 {
|
||||
return fmt.Sprintf("%d files", p.count)
|
||||
return fmt.Sprintf("%d %s", p.count, p.unit)
|
||||
}
|
||||
|
||||
approx := ""
|
||||
|
||||
Reference in New Issue
Block a user