Skip to content

Commit e6d5187

Browse files
authored
Merge pull request #33161 from vespa-engine/havardpe/add-minimal-vespa-inspect-profile
wire in vespa inspect profile command
2 parents e020972 + 6c73315 commit e6d5187

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

client/go/internal/cli/cmd/inspect.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/cobra"
6+
"github.com/vespa-engine/vespa/client/go/internal/vespa/slime"
7+
"os"
8+
)
9+
10+
type inspectProfileOptions struct {
11+
profileFile string
12+
}
13+
14+
func inspectProfile(cli *CLI, opts *inspectProfileOptions) error {
15+
file, err := os.Open(opts.profileFile)
16+
if err != nil {
17+
return fmt.Errorf("failed to open profile file '%s': %w", opts.profileFile, err)
18+
}
19+
defer file.Close()
20+
root := slime.DecodeJson(file)
21+
if !root.Valid() {
22+
return fmt.Errorf("profile file '%s' does not contain valid JSON", opts.profileFile)
23+
}
24+
trace := root.Field("trace")
25+
slime.EncodeJson(trace, false, cli.Stdout)
26+
return nil
27+
}
28+
29+
func newInspectProfileCmd(cli *CLI) *cobra.Command {
30+
opts := inspectProfileOptions{}
31+
32+
cmd := &cobra.Command{
33+
Use: "profile",
34+
Short: "Inspect profiling results",
35+
Long: `Inspect profiling results previously obtained by vespa query --profile
36+
37+
Note: this feature is experimental and currently under development
38+
profiling results can also be analyzed with vespa-query-analyzer (part of vespa installation)`,
39+
40+
RunE: func(cmd *cobra.Command, args []string) error {
41+
return inspectProfile(cli, &opts)
42+
},
43+
}
44+
45+
cmd.Flags().StringVarP(&opts.profileFile, "profile-file", "f", "vespa_query_profile_result.json", "Name of the profile file to inspect")
46+
return cmd
47+
}
48+
49+
func newInspectCmd(cli *CLI) *cobra.Command {
50+
cmd := &cobra.Command{
51+
Use: "inspect",
52+
Short: "Provides insight",
53+
Long: "Provides subcommands to inspect various things in more detail",
54+
}
55+
cmd.AddCommand(newInspectProfileCmd(cli))
56+
return cmd
57+
}

client/go/internal/cli/cmd/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ func (c *CLI) configureCommands() {
321321
rootCmd.AddCommand(newVisitCmd(c)) // visit
322322
rootCmd.AddCommand(newFeedCmd(c)) // feed
323323
rootCmd.AddCommand(newFetchCmd(c)) // fetch
324+
rootCmd.AddCommand(newInspectCmd(c)) // inspect
324325
}
325326

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

0 commit comments

Comments
 (0)