feature: `createSpan` should use event time instead of processing time
https://github.com/coroot/coroot-node-agent/blob/a90fb2df6441b31b0640c63ed60f6a6ab0860bb7/tracing/tracing.go#L90
There may be micro difference betweentime.Now() and the time when connection closed, the former is the processing time, and the latter is the event time. The duration between these two timestamps is used for agent handling.
Here is my idea.
eBPF program can get the time since boot, by calling bpf_ktime_get_boot_ns. We can record it as event_ktime.
GoLang program can also get the time since boot, by wrapping the clock_gettime syscall. We can record it as process_ktime. Here is a GoLang demo:
func getMonotonicTime() {
const CLOCK_MONOTONIC = 1 // CLOCK_MONOTONIC is the identifier for the monotonic clock in Linux.
var ts syscall.Timespec
_, _, errCode := syscall.Syscall(syscall.SYS_CLOCK_GETTIME, CLOCK_MONOTONIC, uintptr(unsafe.Pointer(&ts)), 0)
if errCode != 0 {
fmt.Printf("Failed to call SYS_CLOCK_GETTIME.\n")
return
}
fmt.Printf("Monotonic time since boot is: %d seconds, %d nanoseconds.\n", ts.Sec, ts.Nsec)
duration, err := time.ParseDuration(fmt.Sprintf("%ds%dns", ts.Sec, ts.Nsec))
if err != nil {
return
}
fmt.Printf("That's about %d minutes\n", int(duration.Minutes()))
}
Obviously GoLang program can get the well clock time through the now() function. We can record it as process_time.
So the accurate well clock time when l7_event emitted from the tracepiont event_time = process_time - process_ktime + event_ktime.