Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: createSpan should use event time instead of processing time #126

Open
StLeoX opened this issue Sep 19, 2024 · 1 comment
Open

Comments

@StLeoX
Copy link

StLeoX commented Sep 19, 2024

end := time.Now()

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.

@StLeoX
Copy link
Author

StLeoX commented Nov 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant