mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
batch: add remote query profiler
This commit is contained in:
parent
02a8bf4c8c
commit
824951c3d5
|
@ -8,6 +8,8 @@ import (
|
|||
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("component", "batch")
|
||||
|
@ -52,6 +54,8 @@ func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, s
|
|||
|
||||
log.Debugf("batch querying %T: %v <=> %v", q.Type, startTime, endTime)
|
||||
|
||||
queryProfiler := util.StartTimeProfile("remoteQuery")
|
||||
|
||||
sliceInf, err := q.Q(startTime, endTime)
|
||||
if err != nil {
|
||||
errC <- err
|
||||
|
@ -60,9 +64,10 @@ func (q *AsyncTimeRangedBatchQuery) Query(ctx context.Context, ch interface{}, s
|
|||
|
||||
listRef := reflect.ValueOf(sliceInf)
|
||||
listLen := listRef.Len()
|
||||
|
||||
log.Debugf("batch querying %T: %d remote records", q.Type, listLen)
|
||||
|
||||
queryProfiler.StopAndLog(log.Debugf)
|
||||
|
||||
if listLen == 0 {
|
||||
if q.JumpIfEmpty > 0 {
|
||||
startTime = startTime.Add(q.JumpIfEmpty)
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"context"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
|
|
|
@ -153,5 +153,3 @@ func buildIdMap(sel SyncTask, recordSliceRef reflect.Value) map[string]struct{}
|
|||
|
||||
return ids
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
package util
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type TimeProfile struct {
|
||||
Name string
|
||||
StartTime, EndTime time.Time
|
||||
Duration time.Duration
|
||||
}
|
||||
|
||||
func StartTimeProfile() TimeProfile {
|
||||
return TimeProfile{StartTime: time.Now()}
|
||||
func StartTimeProfile(args ...string) TimeProfile {
|
||||
name := ""
|
||||
if len(args) > 0 {
|
||||
name = args[0]
|
||||
}
|
||||
return TimeProfile{StartTime: time.Now(), Name: name}
|
||||
}
|
||||
|
||||
func (p *TimeProfile) TilNow() time.Duration {
|
||||
|
@ -20,3 +27,16 @@ func (p *TimeProfile) Stop() time.Duration {
|
|||
p.Duration = p.EndTime.Sub(p.StartTime)
|
||||
return p.Duration
|
||||
}
|
||||
|
||||
type logFunction func(format string, args ...interface{})
|
||||
|
||||
func (p *TimeProfile) StopAndLog(f logFunction) {
|
||||
duration := p.Stop()
|
||||
s := "[profile] "
|
||||
if len(p.Name) > 0 {
|
||||
s += p.Name
|
||||
}
|
||||
|
||||
s += " " + duration.String()
|
||||
f(s)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user