Skip to content

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

Open

Description

@StLeoX

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.

Activity

  1. StLeoX commented on Nov 28, 2024

    @StLeoX
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions