Skip to content

Commit

Permalink
test: add a flag to generate the CPU profile for the transform command (
Browse files Browse the repository at this point in the history
#1093)

Signed-off-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
HarikrishnanBalagopal authored Sep 28, 2023
1 parent 1862c9c commit 31f36fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
nameFlag = "name"
// planFlag is the name of the flag that contains the path to the plan file
planFlag = "plan"
// profileFlag is the name of the flag that contains the path where the CPU profile file should be generated
profileFlag = "profile"
// ignoreEnvFlag is the name of the flag that tells us whether to use data collected from the local machine
ignoreEnvFlag = "ignore-env"
// qaSkipFlag is the name of the flag that lets you skip all the question answers
Expand Down
13 changes: 13 additions & 0 deletions cmd/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime/pprof"

"github.com/konveyor/move2kube/common"
"github.com/konveyor/move2kube/common/download"
Expand All @@ -40,6 +41,8 @@ type transformFlags struct {
disableLocalExecution bool
// planfile is contains the path to the plan file
planfile string
// profilepath contains the path to the CPU profile file
profilepath string
// outpath contains the path to the output folder
outpath string
// SourceFlag contains path to the source folder
Expand All @@ -56,6 +59,15 @@ type transformFlags struct {
}

func transformHandler(cmd *cobra.Command, flags transformFlags) {
if flags.profilepath != "" {
if f, err := os.Create(flags.profilepath); err != nil {
panic(err)
} else if err := pprof.StartCPUProfile(f); err != nil {
panic(err)
}
defer pprof.StopCPUProfile()
}

ctx, cancel := context.WithCancel(cmd.Context())
logrus.AddHook(common.NewCleanupHook(cancel))
logrus.AddHook(common.NewCleanupHook(lib.Destroy))
Expand Down Expand Up @@ -223,6 +235,7 @@ func GetTransformCommand() *cobra.Command {
}

// Basic options
transformCmd.Flags().StringVar(&flags.profilepath, profileFlag, "", "Path where the CPU profile file should be generated. By default we don't profile.")
transformCmd.Flags().StringVarP(&flags.planfile, planFlag, "p", common.DefaultPlanFile, "Specify a plan file to execute.")
transformCmd.Flags().BoolVar(&flags.overwrite, overwriteFlag, false, "Overwrite the output directory if it exists. By default we don't overwrite.")
transformCmd.Flags().StringVarP(&flags.srcpath, sourceFlag, "s", "", "Specify source directory or a git url (see https://move2kube.konveyor.io/concepts/git-support) to transform. If you already have a m2k.plan then this will override the sourceDir value specified in that plan.")
Expand Down

0 comments on commit 31f36fe

Please sign in to comment.