Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire in vespa inspect profile command #33161

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions client/go/internal/cli/cmd/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"github.com/vespa-engine/vespa/client/go/internal/vespa/slime"
"os"
)

type inspectProfileOptions struct {
profileFile string
}

func inspectProfile(cli *CLI, opts *inspectProfileOptions) error {
file, err := os.Open(opts.profileFile)
if err != nil {
return fmt.Errorf("failed to open profile file '%s': %w", opts.profileFile, err)
}
defer file.Close()
root := slime.DecodeJson(file)
if !root.Valid() {
return fmt.Errorf("profile file '%s' does not contain valid JSON", opts.profileFile)
}
trace := root.Field("trace")
slime.EncodeJson(trace, false, cli.Stdout)
return nil
}

func newInspectProfileCmd(cli *CLI) *cobra.Command {
opts := inspectProfileOptions{}

cmd := &cobra.Command{
Use: "profile",
Short: "Inspect profiling results",
Long: `Inspect profiling results previously obtained by vespa query --profile

Note: this feature is experimental and currently under development
profiling results can also be analyzed with vespa-query-analyzer (part of vespa installation)`,

RunE: func(cmd *cobra.Command, args []string) error {
return inspectProfile(cli, &opts)
},
}

cmd.Flags().StringVarP(&opts.profileFile, "profile-file", "f", "vespa_query_profile_result.json", "Name of the profile file to inspect")
return cmd
}

func newInspectCmd(cli *CLI) *cobra.Command {
cmd := &cobra.Command{
Use: "inspect",
Short: "Provides insight",
Long: "Provides subcommands to inspect various things in more detail",
}
cmd.AddCommand(newInspectProfileCmd(cli))
return cmd
}
1 change: 1 addition & 0 deletions client/go/internal/cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func (c *CLI) configureCommands() {
rootCmd.AddCommand(newVisitCmd(c)) // visit
rootCmd.AddCommand(newFeedCmd(c)) // feed
rootCmd.AddCommand(newFetchCmd(c)) // fetch
rootCmd.AddCommand(newInspectCmd(c)) // inspect
}

func (c *CLI) bindWaitFlag(cmd *cobra.Command, defaultSecs int, value *int) {
Expand Down
Loading