mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 03:37:43 +00:00
add a profile option to the commands
This commit is contained in:
parent
893e5bd5a3
commit
26ca63f31b
2 changed files with 23 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
tmp/
|
||||
.env
|
||||
dump.rdb
|
||||
cpu.pprof
|
||||
|
|
|
@ -2,6 +2,8 @@ package cmd
|
|||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/DataDog/datadog-go/statsd"
|
||||
"github.com/adjust/rmq/v4"
|
||||
|
@ -25,11 +27,31 @@ type Command struct {
|
|||
func Execute(ctx context.Context) int {
|
||||
_ = godotenv.Load()
|
||||
|
||||
profile := false
|
||||
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "apollo",
|
||||
Short: "Apollo is an amazing Reddit client for iOS. This isn't it, but it helps.",
|
||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !profile {
|
||||
return nil
|
||||
}
|
||||
f, perr := os.Create("cpu.pprof")
|
||||
if perr != nil {
|
||||
return perr
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
return nil
|
||||
},
|
||||
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
||||
if profile {
|
||||
pprof.StopCPUProfile()
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
rootCmd.PersistentFlags().BoolVarP(&profile, "profile", "p", false, "record CPU pprof")
|
||||
|
||||
rootCmd.AddCommand(APICmd(ctx))
|
||||
rootCmd.AddCommand(SchedulerCmd(ctx))
|
||||
rootCmd.AddCommand(WorkerCmd(ctx))
|
||||
|
|
Loading…
Reference in a new issue