本文整理匯總了Golang中github.com/MiniProfiler/go/miniprofiler.Timer.StepCustomTiming方法的典型用法代碼示例。如果您正苦於以下問題:Golang Timer.StepCustomTiming方法的具體用法?Golang Timer.StepCustomTiming怎麽用?Golang Timer.StepCustomTiming使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/MiniProfiler/go/miniprofiler.Timer
的用法示例。
在下文中一共展示了Timer.StepCustomTiming方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: timeTSDBRequest
func timeTSDBRequest(e *State, T miniprofiler.Timer, req *opentsdb.Request) (s opentsdb.ResponseSet, err error) {
e.tsdbQueries = append(e.tsdbQueries, *req)
if e.autods > 0 {
for _, q := range req.Queries {
if q.Downsample == "" {
if err := req.AutoDownsample(e.autods); err != nil {
return nil, err
}
}
}
}
b, _ := json.MarshalIndent(req, "", " ")
tries := 1
for {
T.StepCustomTiming("tsdb", "query", string(b), func() {
getFn := func() (interface{}, error) {
return e.tsdbContext.Query(req)
}
var val interface{}
val, err = e.cache.Get(string(b), getFn)
s = val.(opentsdb.ResponseSet).Copy()
})
if err == nil || tries == tsdbMaxTries {
break
}
slog.Errorf("Error on tsdb query %d: %s", tries, err.Error())
tries++
}
return
}
示例2: timeESRequest
// timeESRequest execute the elasticsearch query (which may set or hit cache) and returns
// the search results.
func timeESRequest(e *State, T miniprofiler.Timer, req *ElasticRequest) (resp *elastic.SearchResult, err error) {
e.elasticQueries = append(e.elasticQueries, *req.Source)
var source interface{}
source, err = req.Source.Source()
if err != nil {
return resp, fmt.Errorf("failed to get source of request while timing elastic request: %s", err)
}
b, err := json.MarshalIndent(source, "", " ")
if err != nil {
return resp, err
}
key, err := req.CacheKey()
if err != nil {
return nil, err
}
T.StepCustomTiming("elastic", "query", fmt.Sprintf("%v\n%s", req.Indices, b), func() {
getFn := func() (interface{}, error) {
return e.ElasticHosts.Query(req)
}
var val interface{}
val, err = e.Cache.Get(key, getFn)
resp = val.(*elastic.SearchResult)
})
return
}
示例3: timeLSRequest
// timeLSRequest execute the elasticsearch query (which may set or hit cache) and returns
// the search results.
func timeLSRequest(e *State, T miniprofiler.Timer, req *LogstashRequest) (resp *elastic.SearchResult, err error) {
e.logstashQueries = append(e.logstashQueries, *req.Source)
b, _ := json.MarshalIndent(req.Source.Source(), "", " ")
T.StepCustomTiming("logstash", "query", string(b), func() {
getFn := func() (interface{}, error) {
return e.LogstashHosts.Query(req)
}
var val interface{}
val, err = e.Cache.Get(string(b), getFn)
resp = val.(*elastic.SearchResult)
})
return
}
示例4: timeGraphiteRequest
func timeGraphiteRequest(e *State, T miniprofiler.Timer, req *graphite.Request) (resp graphite.Response, err error) {
e.graphiteQueries = append(e.graphiteQueries, *req)
b, _ := json.MarshalIndent(req, "", " ")
T.StepCustomTiming("graphite", "query", string(b), func() {
key := req.CacheKey()
getFn := func() (interface{}, error) {
return e.graphiteContext.Query(req)
}
var val interface{}
val, err = e.cache.Get(key, getFn)
resp = val.(graphite.Response)
})
return
}
示例5: timeInfluxRequest
func timeInfluxRequest(e *State, T miniprofiler.Timer, db, query, startDuration, endDuration, groupByInterval string) (s []influxModels.Row, err error) {
q, err := influxQueryDuration(e.now, query, startDuration, endDuration, groupByInterval)
if err != nil {
return nil, err
}
conn, err := client.NewHTTPClient(e.InfluxConfig)
if err != nil {
return nil, err
}
T.StepCustomTiming("influx", "query", q, func() {
getFn := func() (interface{}, error) {
res, err := conn.Query(client.Query{
Command: q,
Database: db,
})
if err != nil {
return nil, err
}
if res.Error() != nil {
return nil, res.Error()
}
if len(res.Results) != 1 {
return nil, fmt.Errorf("influx: expected one result")
}
r := res.Results[0]
if r.Err == "" {
return r.Series, nil
}
err = fmt.Errorf(r.Err)
return r.Series, err
}
var val interface{}
var ok bool
val, err = e.Cache.Get(q, getFn)
if s, ok = val.([]influxModels.Row); !ok {
err = fmt.Errorf("influx: did not get a valid result from InfluxDB")
}
})
return
}
示例6: Graph
//.........這裏部分代碼省略.........
}
if meta == nil {
return nil, fmt.Errorf("no metadata for %s: cannot use auto rate", q)
}
if meta.Unit != "" {
m_units[q.Metric] = meta.Unit
}
if meta.Rate != "" {
switch meta.Rate {
case metadata.Gauge:
// ignore
case metadata.Rate:
q.Rate = true
case metadata.Counter:
q.Rate = true
q.RateOptions = opentsdb.RateOptions{
Counter: true,
ResetValue: 1,
}
default:
return nil, fmt.Errorf("unknown metadata rate: %s", meta.Rate)
}
}
}
queries[i] = fmt.Sprintf(`q("%v", "%v", "%v")`, q, start, end)
if !schedule.SystemConf.GetTSDBContext().Version().FilterSupport() {
if err := schedule.Search.Expand(q); err != nil {
return nil, err
}
}
}
var tr opentsdb.ResponseSet
b, _ := json.MarshalIndent(oreq, "", " ")
t.StepCustomTiming("tsdb", "query", string(b), func() {
h := schedule.SystemConf.GetTSDBHost()
if h == "" {
err = fmt.Errorf("tsdbHost not set")
return
}
tr, err = oreq.Query(h)
})
if err != nil {
return nil, err
}
cs, err := makeChart(tr, m_units)
if err != nil {
return nil, err
}
if _, present := r.Form["png"]; present {
c := chart.ScatterChart{
Title: fmt.Sprintf("%v - %v", oreq.Start, queries),
}
c.XRange.Time = true
if min, err := strconv.ParseFloat(r.FormValue("min"), 64); err == nil {
c.YRange.MinMode.Fixed = true
c.YRange.MinMode.Value = min
}
if max, err := strconv.ParseFloat(r.FormValue("max"), 64); err == nil {
c.YRange.MaxMode.Fixed = true
c.YRange.MaxMode.Value = max
}
for ri, r := range cs {
pts := make([]chart.EPoint, len(r.Data))
for idx, v := range r.Data {
pts[idx].X = v[0]
pts[idx].Y = v[1]
示例7: QueryRowTimer
func (d DB) QueryRowTimer(t miniprofiler.Timer, query string, args ...interface{}) (row *sql.Row) {
t.StepCustomTiming("sql", "query", query, func() {
row = d.DB.QueryRow(query, args...)
})
return
}
示例8: ExecTimer
func (d DB) ExecTimer(t miniprofiler.Timer, query string, args ...interface{}) (result sql.Result, err error) {
t.StepCustomTiming("sql", "exec", query, func() {
result, err = d.DB.Exec(query, args...)
})
return
}