-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tetra: Add enable-stat debug command
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
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |