Improve sleep timings, use ms for elapsed time
This commit is contained in:
parent
ea32632ec9
commit
da9baa20f2
1 changed files with 14 additions and 3 deletions
17
rigol.go
17
rigol.go
|
@ -39,7 +39,7 @@ func main() {
|
||||||
toRun, header := buildQuery()
|
toRun, header := buildQuery()
|
||||||
|
|
||||||
// Output CSV header
|
// Output CSV header
|
||||||
fmt.Printf("%s, %s, %s\n", "timestamp", header, "querytime")
|
fmt.Printf("%s, %s, %s\n", "timestamp", header, "querytime(ms)")
|
||||||
|
|
||||||
for ; *count != 0; *count-- {
|
for ; *count != 0; *count-- {
|
||||||
|
|
||||||
|
@ -58,9 +58,20 @@ func main() {
|
||||||
result = strings.Replace(result, ";", ", ", -1)
|
result = strings.Replace(result, ";", ", ", -1)
|
||||||
|
|
||||||
tdone := time.Now()
|
tdone := time.Now()
|
||||||
fmt.Printf("%s, %s, %s\n", tdone.Format(time.RFC3339), result, tdone.Sub(tstart))
|
taken := tdone.Sub(tstart)
|
||||||
|
takenms := int64(taken/time.Millisecond)
|
||||||
|
|
||||||
|
fmt.Printf("%s, %s, %d\n", tdone.Format(time.RFC3339), result, takenms)
|
||||||
|
|
||||||
|
// Shorten the interval to allow for the time taken for the previous run.
|
||||||
|
// but if the time taken is longer than the interval, no need to sleep at all.
|
||||||
|
intervalms := int64(*interval * 1000)
|
||||||
|
if takenms < intervalms {
|
||||||
|
sleeptime := time.Duration(intervalms - takenms) * time.Millisecond
|
||||||
|
fmt.Println("Sleeping", sleeptime, "as duration was", taken)
|
||||||
|
time.Sleep(sleeptime)
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(time.Duration(*interval) * time.Second)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue