Skip to content

Commit

Permalink
tetragon: Add Monotonic function to ktime object
Browse files Browse the repository at this point in the history
Adding Monotonic function to ktime object so it can
be used in following changes.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Mar 28, 2024
1 parent 9811d40 commit a64a1f8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/ktime/ktime.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ func NanoTimeSince(ktime int64) (time.Duration, error) {
diff := currentTime.Nano() - ktime
return time.Duration(diff), nil
}

func Monotonic() (time.Duration, error) {
clk := int32(unix.CLOCK_MONOTONIC)
currentTime := unix.Timespec{}
if err := unix.ClockGettime(clk, &currentTime); err != nil {
return 0, err
}
return time.Duration(currentTime.Nano()), nil
}

func DecodeKtime(ktime int64, monotonic bool) (time.Time, error) {
var clk int32
if monotonic {
Expand Down

0 comments on commit a64a1f8

Please sign in to comment.