Skip to content

Conversation

@danielmellado
Copy link
Contributor

@danielmellado danielmellado commented Dec 4, 2025

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]

@qmonnet
Copy link
Owner

qmonnet commented Dec 4, 2025

Thanks for the PR.

The reason we used this crate is that libc and clock_gettime() caused issues on some platforms, see #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?

@danielmellado
Copy link
Contributor Author

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

@danielmellado danielmellado force-pushed the remove-deprecated-time-dependency branch from 2bd322d to 5080644 Compare December 4, 2025 13:02
@danielmellado danielmellado changed the title feat: Replace deprecated time crate with libc feat: Replace deprecated time crate with std::time Dec 4, 2025
@danielmellado
Copy link
Contributor Author

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 ;)

@danielmellado danielmellado force-pushed the remove-deprecated-time-dependency branch from 5080644 to 28a065d Compare December 4, 2025 13:10
Copy link
Owner

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not, we can do this I suppose.

Could you please also do the following?:

  • Update the time crate dependency version in the Cargo.toml

  • Update the comment for the bpf_time_getns helper, it's not from boot time (it hasn't been since we switched to time anyway 🤦)

  • Rename (including in Cargo.toml) and change the uptime example (examples/uptime.rs). One suggestion, if you feel like: instead of reusing the existing bpf_time_getns helper, we could use re-implement a separate helper in that file, that returns the current time, and print it (and rename the example to date). If you don't want to spend too much time on this one I can understand, I can follow up with it. Note: running the JIT for the examples currently doesn't work on my setup, I had to change it to use the interpreter instead.

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.

Signed-off-by: Daniel Mellado <[email protected]>
@danielmellado danielmellado force-pushed the remove-deprecated-time-dependency branch from 28a065d to 992cd61 Compare December 5, 2025 11:55
@danielmellado
Copy link
Contributor Author

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!

@danielmellado danielmellado requested a review from qmonnet December 9, 2025 11:44
@qmonnet
Copy link
Owner

qmonnet commented Dec 9, 2025

Thanks for the update. I'll try to take a look in the next few days, sorry for the delay.

@danielmellado
Copy link
Contributor Author

@qmonnet could you PTAL? Thanks!

Copy link
Owner

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay - Looks OK, let's go for it, thank you!

@qmonnet qmonnet merged commit e42527e into qmonnet:main Jan 12, 2026
7 of 8 checks passed
@qmonnet
Copy link
Owner

qmonnet commented Jan 13, 2026

FYI I just tagged and published v0.4.0, which includes your changes.

@danielmellado
Copy link
Contributor Author

FYI I just tagged and published v0.4.0, which includes your changes.

Awesome, thanks! I was about to ask for that ;)

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

Successfully merging this pull request may close these issues.

2 participants