From 30fd595df656c55657ac5533dc78443bf1f1a22a Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 30 May 2022 06:24:31 -0700 Subject: [PATCH] cleanup print message for 'support profile' (#4099) use single logging style, we do not use `go` logger in `mc` avoid it. --- cmd/support-profile.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cmd/support-profile.go b/cmd/support-profile.go index bb78f707..7f91f658 100644 --- a/cmd/support-profile.go +++ b/cmd/support-profile.go @@ -20,11 +20,11 @@ package cmd import ( "io" "io/ioutil" - "log" "os" "strings" "time" + "github.com/fatih/color" "github.com/minio/cli" "github.com/minio/madmin-go" "github.com/minio/mc/pkg/probe" @@ -66,14 +66,14 @@ FLAGS: {{range .VisibleFlags}}{{.}} {{end}} EXAMPLES: - 1. Fetch CPU profiling only + 1. Profile CPU for 10 seconds. {{.Prompt}} {{.HelpName}} --type cpu myminio/ - 2. Fetch CPU, Memory and Block profiling concurrently - {{.Prompt}} {{.HelpName}} --type cpu,mem,block myminio/ + 2. Profile CPU, Memory, Goroutines for 10 seconds. + {{.Prompt}} {{.HelpName}} --type cpu,mem,goroutines myminio/ - 3. Fetch CPU, Memory and Block profiling concurrently for 10 minutes - {{.Prompt}} {{.HelpName}} --type cpu,mem,block --duration 600 myminio/ + 3. Profile CPU, Memory, Goroutines for 10 minutes. + {{.Prompt}} {{.HelpName}} --type cpu,mem,goroutines --duration 600 myminio/ `, } @@ -154,11 +154,11 @@ func getProfileData(data io.ReadCloser) string { fatalIf(probe.NewError(e), "Unable to create a backup of profile.zip") } else { if !os.IsNotExist(e) { - fatal(probe.NewError(e), "Unable to download profile data.") + fatal(probe.NewError(e), "Unable to save profile data") } } - fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to download profile data.") - return downloadedFile + fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to save profile data") + return downloadPath } // mainSupportProfile is the handle for "mc support profile" command. @@ -175,14 +175,15 @@ func mainSupportProfile(ctx *cli.Context) error { // Create a new MinIO Admin Client client, err := newAdminClient(aliasedURL) if err != nil { - fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.") + fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client") return nil } - log.Printf("Collecting data for %d seconds \n", duration) + console.Infof("Profiling '%s' for %d seconds... ", aliasedURL, duration) data, adminErr := client.Profile(globalContext, madmin.ProfilerType(profilers), time.Second*time.Duration(duration)) - fatalIf(probe.NewError(adminErr), "Unable to download profile data.") - console.Infof(" Profile data successfully downloaded as %s\n", getProfileData(data)) + fatalIf(probe.NewError(adminErr), "Unable to save profile data") + clr := color.New(color.FgGreen, color.Bold) + clr.Printf("saved successfully at '%s'\n", getProfileData(data)) return nil }