Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
gunlee01 committed Jan 17, 2021
1 parent 767165e commit 8b0ded1
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions scouterx/strace/tracemain.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,33 @@ func findXLogDiscard(tctx *netio.TraceContext, elapsed int32) netdata.XlogDiscar
}

func StartMethod(ctx context.Context) *netdata.MethodStep {
return startMethodWithParam(ctx)
defer common.ReportScouterPanic()
return startMethodWithParam(ctx) //do not call StartMethodWithParam (because of method name finding depth)
}

func StartMethodWithParam(ctx context.Context, params ...interface{}) *netdata.MethodStep {
defer common.ReportScouterPanic()
return startMethodWithParam(ctx, params)
}

func startMethodWithParam(ctx context.Context, params ...interface{}) *netdata.MethodStep {
func StartCustomMethod(ctx context.Context, methodName string) *netdata.MethodStep {
return StartCustomMethodWithParam(ctx, methodName)
}

func StartCustomMethodWithParam(ctx context.Context, methodName string, params ...interface{}) *netdata.MethodStep {
defer common.ReportScouterPanic()
if ctx == nil {
return nil
}
tctx := tctxmanager.GetTraceContext(ctx)
if tctx == nil {
return nil
}

return startMethodWithParam0(tctx, methodName, methodName, params)
}

func startMethodWithParam(ctx context.Context, params ...interface{}) *netdata.MethodStep {
if ctx == nil {
return nil
}
Expand All @@ -428,13 +445,17 @@ func startMethodWithParam(ctx context.Context, params ...interface{}) *netdata.M
pc, _, _, _ := runtime.Caller(2)
funcName := fmt.Sprintf("%s", runtime.FuncForPC(pc).Name())
split := strings.Split(funcName, "/")
shortName := split[len(split)-1] + "()"
methodName := split[len(split)-1] + "()"

return startMethodWithParam0(tctx, funcName, methodName, params)
}

func startMethodWithParam0(tctx *netio.TraceContext, funcName string, methodName string, params ...interface{}) *netdata.MethodStep {
addMessageStepIfParamExist(tctx, params)
tctx.LastMethod = funcName

step := netdata.NewMethodStep()
step.Hash = netio.SendMethod(shortName)
step.Hash = netio.SendMethod(methodName)
step.StartTime = util.MillisToNow(tctx.StartTime)
tctx.Profile.Push(step)
return step
Expand Down

0 comments on commit 8b0ded1

Please sign in to comment.