mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
add profiler dev option
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
737a81c38c
commit
be5917a058
28
cmd/root.go
28
cmd/root.go
@ -5,14 +5,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/distro"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/pkg"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/source"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/internal"
|
"github.com/anchore/syft/internal"
|
||||||
"github.com/anchore/syft/internal/anchore"
|
"github.com/anchore/syft/internal/anchore"
|
||||||
"github.com/anchore/syft/internal/bus"
|
"github.com/anchore/syft/internal/bus"
|
||||||
@ -20,8 +15,11 @@ import (
|
|||||||
"github.com/anchore/syft/internal/ui"
|
"github.com/anchore/syft/internal/ui"
|
||||||
"github.com/anchore/syft/internal/version"
|
"github.com/anchore/syft/internal/version"
|
||||||
"github.com/anchore/syft/syft"
|
"github.com/anchore/syft/syft"
|
||||||
|
"github.com/anchore/syft/syft/distro"
|
||||||
"github.com/anchore/syft/syft/event"
|
"github.com/anchore/syft/syft/event"
|
||||||
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/presenter"
|
"github.com/anchore/syft/syft/presenter"
|
||||||
|
"github.com/anchore/syft/syft/source"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
@ -56,7 +54,25 @@ You can also explicitly specify the scheme to use:
|
|||||||
}
|
}
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if appConfig.Dev.ProfileCPU {
|
||||||
|
f, err := os.Create("cpu.profile")
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("unable to create CPU profile: %+v", err)
|
||||||
|
} else {
|
||||||
|
err := pprof.StartCPUProfile(f)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("unable to start CPU profile: %+v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := doRunCmd(cmd, args)
|
err := doRunCmd(cmd, args)
|
||||||
|
|
||||||
|
if appConfig.Dev.ProfileCPU {
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(err.Error())
|
log.Errorf(err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@ -17,14 +17,15 @@ import (
|
|||||||
|
|
||||||
// Application is the main syft application configuration.
|
// Application is the main syft application configuration.
|
||||||
type Application struct {
|
type Application struct {
|
||||||
ConfigPath string `yaml:",omitempty"` // the location where the application config was read from (either from -c or discovered while loading)
|
ConfigPath string `yaml:",omitempty"` // the location where the application config was read from (either from -c or discovered while loading)
|
||||||
PresenterOpt presenter.Option `yaml:"-"` // -o, the native Presenter.Option to use for report formatting
|
PresenterOpt presenter.Option `yaml:"-"` // -o, the native Presenter.Option to use for report formatting
|
||||||
Output string `yaml:"output" mapstructure:"output"` // -o, the Presenter hint string to use for report formatting
|
Output string `yaml:"output" mapstructure:"output"` // -o, the Presenter hint string to use for report formatting
|
||||||
ScopeOpt source.Scope `yaml:"-"` // -s, the native source.Scope option to use for how to catalog the container image
|
ScopeOpt source.Scope `yaml:"-"` // -s, the native source.Scope option to use for how to catalog the container image
|
||||||
Scope string `yaml:"scope" mapstructure:"scope"` // -s, the source.Scope string hint for how to catalog the container image
|
Scope string `yaml:"scope" mapstructure:"scope"` // -s, the source.Scope string hint for how to catalog the container image
|
||||||
Quiet bool `yaml:"quiet" mapstructure:"quiet"` // -q, indicates to not show any status output to stderr (ETUI or logging UI)
|
Quiet bool `yaml:"quiet" mapstructure:"quiet"` // -q, indicates to not show any status output to stderr (ETUI or logging UI)
|
||||||
Log logging `yaml:"log" mapstructure:"log"` // all logging-related options
|
Log logging `yaml:"log" mapstructure:"log"` // all logging-related options
|
||||||
CliOptions CliOnlyOptions `yaml:"-"` // all options only available through the CLI (not via env vars or config)
|
CliOptions CliOnlyOptions `yaml:"-"` // all options only available through the CLI (not via env vars or config)
|
||||||
|
Dev Development `mapstructure:"dev"`
|
||||||
CheckForAppUpdate bool `yaml:"check-for-app-update" mapstructure:"check-for-app-update"` // whether to check for an application update on start up or not
|
CheckForAppUpdate bool `yaml:"check-for-app-update" mapstructure:"check-for-app-update"` // whether to check for an application update on start up or not
|
||||||
Anchore anchore `yaml:"anchore" mapstructure:"anchore"` // options for interacting with Anchore Engine/Enterprise
|
Anchore anchore `yaml:"anchore" mapstructure:"anchore"` // options for interacting with Anchore Engine/Enterprise
|
||||||
}
|
}
|
||||||
@ -53,6 +54,10 @@ type anchore struct {
|
|||||||
Dockerfile string `yaml:"dockerfile" mapstructure:"dockerfile"` // -d , dockerfile to attach for upload
|
Dockerfile string `yaml:"dockerfile" mapstructure:"dockerfile"` // -d , dockerfile to attach for upload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Development struct {
|
||||||
|
ProfileCPU bool `mapstructure:"profile-cpu"`
|
||||||
|
}
|
||||||
|
|
||||||
// LoadApplicationConfig populates the given viper object with application configuration discovered on disk
|
// LoadApplicationConfig populates the given viper object with application configuration discovered on disk
|
||||||
func LoadApplicationConfig(v *viper.Viper, cliOpts CliOnlyOptions, wasHostnameSet bool) (*Application, error) {
|
func LoadApplicationConfig(v *viper.Viper, cliOpts CliOnlyOptions, wasHostnameSet bool) (*Application, error) {
|
||||||
// the user may not have a config, and this is OK, we can use the default config + default cobra cli values instead
|
// the user may not have a config, and this is OK, we can use the default config + default cobra cli values instead
|
||||||
@ -216,4 +221,5 @@ func setNonCliDefaultValues(v *viper.Viper) {
|
|||||||
v.SetDefault("log.file", "")
|
v.SetDefault("log.file", "")
|
||||||
v.SetDefault("log.structured", false)
|
v.SetDefault("log.structured", false)
|
||||||
v.SetDefault("check-for-app-update", true)
|
v.SetDefault("check-for-app-update", true)
|
||||||
|
v.SetDefault("dev.profile-cpu", false)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user