Skip to content

Commit

Permalink
Add helper to check if ftrace is enabled (#94)
Browse files Browse the repository at this point in the history
Signed-off-by: grantseltzer <grantseltzer@gmail.com>
  • Loading branch information
grantseltzer authored Nov 23, 2021
1 parent 2b469ce commit 911d504
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions helpers/osinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package helpers

import (
"bufio"
"bytes"
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -228,3 +230,15 @@ func (btfi *OSInfo) discoverOSDistro() error {

return nil
}

func FtraceEnabled() (bool, error) {
b, err := os.ReadFile("/proc/sys/kernel/ftrace_enabled")
if err != nil {
return false, fmt.Errorf("could not read from ftrace_enabled file: %s", err.Error())
}
b = bytes.TrimSpace(b)
if len(b) != 1 {
return false, errors.New("malformed ftrace_enabled file")
}
return b[0] == '1', nil
}

0 comments on commit 911d504

Please sign in to comment.