Add support for calculating the estimate time remaining (#71)
This commit is contained in:
parent
0c6862bb87
commit
bc1314ca61
|
@ -109,9 +109,11 @@ func (h *Handler) TypedLog(t string, e *log.Entry) error {
|
|||
return nil
|
||||
case "progress":
|
||||
perc := e.Fields.Get("percentage").(float64) * 100
|
||||
s := fmt.Sprintf(" %s %-25s",
|
||||
eta := e.Fields.Get("eta").(float64)
|
||||
s := fmt.Sprintf(" %s %-25s (%ss left)",
|
||||
bold.Sprintf("%.2f%%", perc),
|
||||
e.Message)
|
||||
e.Message,
|
||||
bold.Sprintf("%.2f", eta))
|
||||
fmt.Fprint(h.Writer, s)
|
||||
fmt.Fprintln(h.Writer)
|
||||
return nil
|
||||
|
|
|
@ -20,11 +20,12 @@ func MeasurementJSON(j map[string]interface{}) {
|
|||
}
|
||||
|
||||
// Progress logs a progress type event
|
||||
func Progress(key string, perc float64, msg string) {
|
||||
func Progress(key string, perc float64, eta float64, msg string) {
|
||||
log.WithFields(log.Fields{
|
||||
"type": "progress",
|
||||
"key": key,
|
||||
"percentage": perc,
|
||||
"eta": eta,
|
||||
}).Info(msg)
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ type Controller struct {
|
|||
nt Nettest
|
||||
ntCount int
|
||||
ntIndex int
|
||||
ntStartTime time.Time // used to calculate the eta
|
||||
msmts map[int64]*database.Measurement
|
||||
msmtPath string // XXX maybe we can drop this and just use a temporary file
|
||||
inputIdxMap map[int64]int64 // Used to map mk idx to database id
|
||||
|
@ -105,6 +106,7 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err
|
|||
}
|
||||
}
|
||||
|
||||
c.ntStartTime = time.Now()
|
||||
for idx, input := range inputs {
|
||||
c.curInputIdx = idx // allow for precise progress
|
||||
idx64 := int64(idx)
|
||||
|
@ -185,18 +187,21 @@ func (c *Controller) Run(builder *engine.ExperimentBuilder, inputs []string) err
|
|||
// OnProgress should be called when a new progress event is available.
|
||||
func (c *Controller) OnProgress(perc float64, msg string) {
|
||||
log.Debugf("OnProgress: %f - %s", perc, msg)
|
||||
var eta float64
|
||||
eta = -1.0
|
||||
if c.numInputs >= 1 {
|
||||
// make the percentage relative to the current input over all inputs
|
||||
floor := (float64(c.curInputIdx) / float64(c.numInputs))
|
||||
step := 1.0 / float64(c.numInputs)
|
||||
perc = floor + perc*step
|
||||
eta = (float64(time.Now().Sub(c.ntStartTime).Seconds()) / float64(c.curInputIdx)) * float64(c.numInputs-c.curInputIdx)
|
||||
}
|
||||
if c.ntCount > 0 {
|
||||
// make the percentage relative to the current nettest over all nettests
|
||||
perc = float64(c.ntIndex)/float64(c.ntCount) + perc/float64(c.ntCount)
|
||||
}
|
||||
key := fmt.Sprintf("%T", c.nt)
|
||||
output.Progress(key, perc, msg)
|
||||
output.Progress(key, perc, eta, msg)
|
||||
}
|
||||
|
||||
// OnDataUsage should be called when we have a data usage update.
|
||||
|
|
Loading…
Reference in New Issue
Block a user