timesync

package
v0.8.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package timesync provides time conversion utilities for converting kernel boot-clock timestamps from eBPF events to wall-clock time.

eBPF events are stamped with bpf_ktime_get_boot_ns() (CLOCK_BOOTTIME): nanoseconds since system boot, including time spent suspended. This package converts them to absolute wall-clock time by adding the boot instant, which it derives from a paired CLOCK_REALTIME/CLOCK_BOOTTIME reading (falling back to /proc/stat btime).

CLOCK_BOOTTIME rather than CLOCK_MONOTONIC is deliberate: CLOCK_MONOTONIC freezes across suspend, which would drift these spans behind the wall-clock (CLOCK_REALTIME) root span by the host's cumulative suspend time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

Converter handles conversion from kernel boot-clock timestamps to wall-clock time.

eBPF events are stamped with bpf_ktime_get_boot_ns() (CLOCK_BOOTTIME): nanoseconds since boot, INCLUDING time spent suspended. We reconstruct wall-clock as bootTime + boottime_ns, where bootTime is the wall-clock instant of boot.

The distinction from CLOCK_MONOTONIC matters: CLOCK_MONOTONIC freezes across suspend, so btime + monotonic_ns drifts behind real wall-clock by the host's cumulative suspend time. That desynced these spans from the process.tree root span (stamped with the userspace CLOCK_REALTIME clock) and inflated the rendered trace duration by hours on any machine that had suspended.

func NewConverter

func NewConverter() (*Converter, error)

NewConverter creates a new time converter.

Primary path: anchor on a paired reading of CLOCK_REALTIME and CLOCK_BOOTTIME captured together, so bootTime = realtimeNow - boottimeElapsed. This is sub-second accurate, tracks any NTP adjustments to realtime since boot (which keeps us consistent with the time.Now() used for the root span), and needs no /proc parsing.

Fallback: /proc/stat btime (integer-second boot wall time). This is still correct for CLOCK_BOOTTIME-domain events (btime + boottime_ns ≈ realtime), just coarser. Last resort is a conservative estimate.

func (*Converter) BootNanosToWallClock added in v0.8.12

func (c *Converter) BootNanosToWallClock(bootNanos uint64) time.Time

BootNanosToWallClock converts a CLOCK_BOOTTIME timestamp (nanoseconds since boot, including suspend) to wall-clock time. Pure function over the boot time captured at initialization.

func (*Converter) BootTime

func (c *Converter) BootTime() time.Time

BootTime returns the system boot time used for conversions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL