Skip to content

Commit

Permalink
tetra: Add enable-stat debug command
Browse files Browse the repository at this point in the history
Adding enable-stat debug command that enabled bpf program
stats for as long as the command is running, like:

  # ./tetra debug enable-stats
  ^C

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Oct 30, 2024
1 parent f8255ef commit 41e5d6d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/tetra/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ func New() *cobra.Command {
cmd.AddCommand(NewMapCmd())
cmd.AddCommand(NewDumpCommand())
cmd.AddCommand(NewProgsCmd())
cmd.AddCommand(NewEnableStatsCmd())
return &cmd
}
36 changes: 36 additions & 0 deletions cmd/tetra/debug/stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Tetragon

package debug

import (
"fmt"
"time"

"github.com/cilium/ebpf"
"github.com/spf13/cobra"
"golang.org/x/sys/unix"
)

func NewEnableStatsCmd() *cobra.Command {
cmd := cobra.Command{
Use: "enable-stats",
Short: "Enable BPF stats",
RunE: func(_ *cobra.Command, _ []string) error {
// We enable BPF stats system wide keep it enabled as long as
// the stats descriptor is open - app is running
_, err := ebpf.EnableStats(uint32(unix.BPF_STATS_RUN_TIME))
if err != nil {
return fmt.Errorf("failed to enable stats: %v", err)
}

// BPF stats are enabled..

for {
time.Sleep(time.Hour)
}
},
}

return &cmd
}

0 comments on commit 41e5d6d

Please sign in to comment.