feat: Replace deprecated time crate with std::time
The v0.2 time crate is deprecated and time::precise_time_ns() has been removed in newer versions. This causes build failures with modern Rust toolchains.
This replaces that function with std::time::Instant, which provides cross-platform monotonic time functionality using only the standard library. The bpf_time_getns() helper now returns elapsed nanoseconds since the first call, and the documentation has been updated to reflect this behavior.
The uptime.rs example has been replaced with a new date.rs example. This new example defines a helper that returns the current Unix timestamp and prints the current date and time.
Signed-off-by: Daniel Mellado [email protected]
Thanks for the PR.
The reason we used this crate is that libc and clock_gettime() caused issues on some platforms, see https://github.com/qmonnet/rbpf/issues/19.
Do you know if there's another alternative? Does the API from the current time crate version offers a way to reproduce the timestamp generated in the helper?
Hey, thanks for the quick response. Tbh I've been really surprised about the windows in appveyor, but it did really pick up the cross-platform issue. I'll update this xD
Hi, @qmonnet, I took a look and saw no direct way to do this in time v0.3. I assume this should also work in cross-platforms. It now uses std::time::Instant to capture a reference time on the first call and returns elapsed nanoseconds from that point. TL;DR time intervals should be the same, which should work the same for eBPF programs since they typically just measure elapsed time between events anyway. Let me know ;)
Hi @qmonnet, yeah, JIT also crashed for me. I kept it as it was later but I'm wondering if it'd make sense to just change it. Thanks!
Thanks for the update. I'll try to take a look in the next few days, sorry for the delay.