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
|
return nil
|
||||||
case "progress":
|
case "progress":
|
||||||
perc := e.Fields.Get("percentage").(float64) * 100
|
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),
|
bold.Sprintf("%.2f%%", perc),
|
||||||
e.Message)
|
e.Message,
|
||||||
|
bold.Sprintf("%.2f", eta))
|
||||||
fmt.Fprint(h.Writer, s)
|
fmt.Fprint(h.Writer, s)
|
||||||
fmt.Fprintln(h.Writer)
|
fmt.Fprintln(h.Writer)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -14,17 +14,18 @@ import (
|
||||||
// MeasurementJSON prints the JSON of a measurement
|
// MeasurementJSON prints the JSON of a measurement
|
||||||
func MeasurementJSON(j map[string]interface{}) {
|
func MeasurementJSON(j map[string]interface{}) {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"type": "measurement_json",
|
"type": "measurement_json",
|
||||||
"measurement_json": j,
|
"measurement_json": j,
|
||||||
}).Info("Measurement JSON")
|
}).Info("Measurement JSON")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Progress logs a progress type event
|
// 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{
|
log.WithFields(log.Fields{
|
||||||
"type": "progress",
|
"type": "progress",
|
||||||
"key": key,
|
"key": key,
|
||||||
"percentage": perc,
|
"percentage": perc,
|
||||||
|
"eta": eta,
|
||||||
}).Info(msg)
|
}).Info(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,13 +43,13 @@ type MeasurementSummaryData struct {
|
||||||
|
|
||||||
func MeasurementSummary(msmt MeasurementSummaryData) {
|
func MeasurementSummary(msmt MeasurementSummaryData) {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"type": "measurement_summary",
|
"type": "measurement_summary",
|
||||||
"total_runtime": msmt.TotalRuntime,
|
"total_runtime": msmt.TotalRuntime,
|
||||||
"total_count": msmt.TotalCount,
|
"total_count": msmt.TotalCount,
|
||||||
"anomaly_count": msmt.AnomalyCount,
|
"anomaly_count": msmt.AnomalyCount,
|
||||||
"data_usage_down": msmt.DataUsageDown,
|
"data_usage_down": msmt.DataUsageDown,
|
||||||
"data_usage_up": msmt.DataUsageUp,
|
"data_usage_up": msmt.DataUsageUp,
|
||||||
"asn": msmt.ASN,
|
"asn": msmt.ASN,
|
||||||
"network_country_code": msmt.NetworkCountryCode,
|
"network_country_code": msmt.NetworkCountryCode,
|
||||||
"network_name": msmt.NetworkName,
|
"network_name": msmt.NetworkName,
|
||||||
"start_time": msmt.StartTime,
|
"start_time": msmt.StartTime,
|
||||||
|
|
|
@ -44,6 +44,7 @@ type Controller struct {
|
||||||
nt Nettest
|
nt Nettest
|
||||||
ntCount int
|
ntCount int
|
||||||
ntIndex int
|
ntIndex int
|
||||||
|
ntStartTime time.Time // used to calculate the eta
|
||||||
msmts map[int64]*database.Measurement
|
msmts map[int64]*database.Measurement
|
||||||
msmtPath string // XXX maybe we can drop this and just use a temporary file
|
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
|
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 {
|
for idx, input := range inputs {
|
||||||
c.curInputIdx = idx // allow for precise progress
|
c.curInputIdx = idx // allow for precise progress
|
||||||
idx64 := int64(idx)
|
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.
|
// OnProgress should be called when a new progress event is available.
|
||||||
func (c *Controller) OnProgress(perc float64, msg string) {
|
func (c *Controller) OnProgress(perc float64, msg string) {
|
||||||
log.Debugf("OnProgress: %f - %s", perc, msg)
|
log.Debugf("OnProgress: %f - %s", perc, msg)
|
||||||
|
var eta float64
|
||||||
|
eta = -1.0
|
||||||
if c.numInputs >= 1 {
|
if c.numInputs >= 1 {
|
||||||
// make the percentage relative to the current input over all inputs
|
// make the percentage relative to the current input over all inputs
|
||||||
floor := (float64(c.curInputIdx) / float64(c.numInputs))
|
floor := (float64(c.curInputIdx) / float64(c.numInputs))
|
||||||
step := 1.0 / float64(c.numInputs)
|
step := 1.0 / float64(c.numInputs)
|
||||||
perc = floor + perc*step
|
perc = floor + perc*step
|
||||||
|
eta = (float64(time.Now().Sub(c.ntStartTime).Seconds()) / float64(c.curInputIdx)) * float64(c.numInputs-c.curInputIdx)
|
||||||
}
|
}
|
||||||
if c.ntCount > 0 {
|
if c.ntCount > 0 {
|
||||||
// make the percentage relative to the current nettest over all nettests
|
// make the percentage relative to the current nettest over all nettests
|
||||||
perc = float64(c.ntIndex)/float64(c.ntCount) + perc/float64(c.ntCount)
|
perc = float64(c.ntIndex)/float64(c.ntCount) + perc/float64(c.ntCount)
|
||||||
}
|
}
|
||||||
key := fmt.Sprintf("%T", c.nt)
|
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.
|
// OnDataUsage should be called when we have a data usage update.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user