github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/autoprofile/internal/frame_filter.go (about)

     1  // (c) Copyright IBM Corp. 2021
     2  // (c) Copyright Instana Inc. 2020
     3  
     4  package internal
     5  
     6  import (
     7  	"path/filepath"
     8  	"strings"
     9  
    10  	"github.com/instana/go-sensor/autoprofile/internal/pprof/profile"
    11  )
    12  
    13  var (
    14  	// IncludeProfilerFrames is a setting for the frame filter whether or not to include the profiler
    15  	// frames into the profile
    16  	IncludeProfilerFrames = false
    17  	autoprofilePath       = filepath.Join("github.com", "instana", "go-sensor", "autoprofile")
    18  )
    19  
    20  func shouldSkipStack(sample *profile.Sample) bool {
    21  	return !IncludeProfilerFrames && stackContains(sample, autoprofilePath)
    22  }
    23  
    24  func stackContains(sample *profile.Sample, fileNameTest string) bool {
    25  	for i := len(sample.Location) - 1; i >= 0; i-- {
    26  		l := sample.Location[i]
    27  		_, fileName, _ := readFuncInfo(l)
    28  
    29  		if strings.Contains(fileName, fileNameTest) {
    30  			return true
    31  		}
    32  	}
    33  
    34  	return false
    35  }