github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/adhoc/exec.go (about) 1 package adhoc 2 3 import ( 4 "path" 5 6 "github.com/sirupsen/logrus" 7 8 "github.com/pyroscope-io/pyroscope/pkg/agent/spy" 9 "github.com/pyroscope-io/pyroscope/pkg/agent/types" 10 "github.com/pyroscope-io/pyroscope/pkg/agent/upstream/direct" 11 "github.com/pyroscope-io/pyroscope/pkg/config" 12 "github.com/pyroscope-io/pyroscope/pkg/exec" 13 "github.com/pyroscope-io/pyroscope/pkg/exporter" 14 "github.com/pyroscope-io/pyroscope/pkg/storage" 15 ) 16 17 func newExec(cfg *config.Adhoc, args []string, st *storage.Storage, logger *logrus.Logger) (runner, error) { 18 spyName := cfg.SpyName 19 if spyName == "auto" { 20 baseName := path.Base(args[0]) 21 spyName = spy.ResolveAutoName(baseName) 22 if spyName == "" { 23 return nil, exec.UnsupportedSpyError{Subcommand: "adhoc", Args: args} 24 } 25 } 26 if err := exec.PerformChecks(spyName); err != nil { 27 return nil, err 28 } 29 30 upstream := direct.New(st, exporter.MetricsExporter{}) 31 32 // if the sample rate is zero, use the default value 33 sampleRate := uint32(types.DefaultSampleRate) 34 if cfg.SampleRate != 0 { 35 sampleRate = uint32(cfg.SampleRate) 36 } 37 38 return &exec.Exec{ 39 Args: args, 40 Logger: logger, 41 Upstream: upstream, 42 SpyName: spyName, 43 ApplicationName: exec.CheckApplicationName(logger, cfg.ApplicationName, spyName, args), 44 SampleRate: sampleRate, 45 DetectSubprocesses: cfg.DetectSubprocesses, 46 PHPSpyArgs: cfg.PHPSpyArgs, 47 }, nil 48 }