Skip to content

Commit

Permalink
Added sugestions to CPU and Memory usage in logs (#2379)
Browse files Browse the repository at this point in the history
Signed-off-by: João Reigota <[email protected]>
  • Loading branch information
cx-joao-reigota committed Apr 26, 2021
1 parent f83414f commit a280a4e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
12 changes: 4 additions & 8 deletions internal/console/kics.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
noColor bool
silent bool
ci bool
metric string
profiling string

warning []string
)
Expand Down Expand Up @@ -90,15 +90,11 @@ func initialize(rootCmd *cobra.Command) error {
"",
false,
"display only log messages to CLI output (mutually exclusive with silent)")
rootCmd.PersistentFlags().StringVarP(&metric,
"metrics",
rootCmd.PersistentFlags().StringVarP(&profiling,
"profiling",
"",
"",
"display metrics for the steps of kics exucution (CPU, MEM)")

if err := rootCmd.PersistentFlags().MarkHidden("metrics"); err != nil {
return err
}
"enables performance profiler that prints resource consumption metrics in the logs during the execution (CPU, MEM)")

if err := rootCmd.PersistentFlags().MarkDeprecated(printer.LogFileFlag, "please use --log-path instead"); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/console/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func NewScanCmd() *cobra.Command {
return err
}
var err error
global.Metric, err = metrics.InitializeMetrics(cmd.InheritedFlags().Lookup("metrics"))
global.Metric, err = metrics.InitializeMetrics(cmd.InheritedFlags().Lookup("profiling"))
if err != nil {
sentry.CaptureException(err)
log.Err(err).Msg("Failed to initialize Metrics")
Expand Down
4 changes: 2 additions & 2 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func InitializeMetrics(metric *pflag.Flag) (*Metrics, error) {
metrics.Disable = true
default:
metrics.Disable = true
err = fmt.Errorf("unknonwn metric: %s (available metrics: cpu, mem)", metricStr)
err = fmt.Errorf("unknonwn metric: %s (available metrics: CPU, MEM)", metricStr)
}

// Create temporary dir to keep pprof file
Expand Down Expand Up @@ -91,7 +91,7 @@ func (m *Metrics) Stop() {
Msgf("Total %s usage for %s: %s", strings.ToUpper(m.metricsID), m.location, formatTotal(total, m.metric.getMap()))
}

// Get total goes through the profile samples summing their values according to
// getTotal goes through the profile samples summing their values according to
// the type of profile
func getTotal(prof *profile.Profile, idx int) int64 {
var total, diffTotal int64
Expand Down

0 comments on commit a280a4e

Please sign in to comment.