package adhoc import ( "path" "github.com/sirupsen/logrus" "github.com/pyroscope-io/pyroscope/pkg/agent/spy" "github.com/pyroscope-io/pyroscope/pkg/agent/types" "github.com/pyroscope-io/pyroscope/pkg/agent/upstream/direct" "github.com/pyroscope-io/pyroscope/pkg/config" "github.com/pyroscope-io/pyroscope/pkg/exec" "github.com/pyroscope-io/pyroscope/pkg/exporter" "github.com/pyroscope-io/pyroscope/pkg/storage" ) func newExec(cfg *config.Adhoc, args []string, st *storage.Storage, logger *logrus.Logger) (runner, error) { spyName := cfg.SpyName if spyName == "auto" { baseName := path.Base(args[0]) spyName = spy.ResolveAutoName(baseName) if spyName == "" { return nil, exec.UnsupportedSpyError{Subcommand: "adhoc", Args: args} } } if err := exec.PerformChecks(spyName); err != nil { return nil, err } upstream := direct.New(st, exporter.MetricsExporter{}) // if the sample rate is zero, use the default value sampleRate := uint32(types.DefaultSampleRate) if cfg.SampleRate != 0 { sampleRate = uint32(cfg.SampleRate) } return &exec.Exec{ Args: args, Logger: logger, Upstream: upstream, SpyName: spyName, ApplicationName: exec.CheckApplicationName(logger, cfg.ApplicationName, spyName, args), SampleRate: sampleRate, DetectSubprocesses: cfg.DetectSubprocesses, PHPSpyArgs: cfg.PHPSpyArgs, }, nil }