Skip to content

Commit

Permalink
wire in vespa inspect profile command
Browse files Browse the repository at this point in the history
  • Loading branch information
havardpe committed Jan 23, 2025
1 parent 028ed29 commit 6c73315
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
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

0 comments on commit 6c73315

Please sign in to comment.