Skip to content

Commit aea34b2

Browse files
committed
start api call method
1 parent a40cfef commit aea34b2

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package netdata
2+
3+
type ApiCallStep struct {
4+
SingleStep
5+
Txid int64
6+
Hash int32
7+
Elapsed int32
8+
CpuTime int32
9+
Error int32
10+
Opt uint8
11+
Address string
12+
}
13+
14+
func NewApiCallStep() *ApiCallStep {
15+
step := new(ApiCallStep)
16+
return step
17+
}
18+
19+
func (s *ApiCallStep) ApiCallStep() byte {
20+
return APICALL
21+
}
22+
23+
func (s *ApiCallStep) Write(out *DataOutputX) error {
24+
err := s.SingleStep.Write(out)
25+
if err != nil {
26+
return err
27+
}
28+
_, err = out.WriteDecimal(s.Txid)
29+
_, err = out.WriteDecimal32(s.Hash)
30+
_, err = out.WriteDecimal32(s.Elapsed)
31+
_, err = out.WriteDecimal32(s.CpuTime)
32+
_, err = out.WriteDecimal32(s.Error)
33+
_, err = out.WriteUInt8(s.Opt)
34+
if s.Opt == 1 {
35+
_, err = out.WriteString(s.Address)
36+
}
37+
38+
return err
39+
}

scouterx/strace/tracemain.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,37 @@ func profileHttpHeaders(r *http.Request, tctx *netio.TraceContext) {
515515
tctx.Profile.Add(netdata.NewMessageStep(fmt.Sprintf("query: %s", r.URL.RawQuery), startTime))
516516
}
517517
}
518+
519+
func StartApiCall(ctx context.Context, apiCallName string, address string) *netdata.ApiCallStep {
520+
defer common.ReportScouterPanic()
521+
if ctx == nil {
522+
return nil
523+
}
524+
tctx := tctxmanager.GetTraceContext(ctx)
525+
if tctx == nil {
526+
return nil
527+
}
528+
529+
step := netdata.NewApiCallStep()
530+
step.Hash = netio.SendApicall(apiCallName)
531+
step.StartTime = util.MillisToNow(tctx.StartTime)
532+
step.Address = address
533+
tctx.Profile.Push(step)
534+
535+
return step
536+
}
537+
538+
func EndApiCall(ctx context.Context, step *netdata.MethodStep) {
539+
defer common.ReportScouterPanic()
540+
541+
if ctx == nil || step == nil {
542+
return
543+
}
544+
tctx := tctxmanager.GetTraceContext(ctx)
545+
if tctx == nil {
546+
return
547+
}
548+
step.Elapsed = util.MillisToNow(tctx.StartTime) - step.StartTime
549+
tctx.Profile.Pop(step)
550+
}
551+

0 commit comments

Comments
 (0)