2 releases

0.1.1 Jun 14, 2024
0.1.0 Apr 3, 2024

#136 in Operating systems

Download history 50/week @ 2024-07-04 259/week @ 2024-07-11 132/week @ 2024-07-18 174/week @ 2024-07-25 119/week @ 2024-08-01 33/week @ 2024-08-08 64/week @ 2024-08-15 173/week @ 2024-08-22 87/week @ 2024-08-29 139/week @ 2024-09-05 153/week @ 2024-09-12 129/week @ 2024-09-19 88/week @ 2024-09-26 147/week @ 2024-10-03 150/week @ 2024-10-10 230/week @ 2024-10-17

627 downloads per month
Used in tracing_android_trace

Apache-2.0 OR MIT

26KB
262 lines

Android Trace

Support for Android NDK Tracing

Latest published version. Documentation build status. Apache 2.0 or MIT license.
Linebender Zulip chat. GitHub Actions CI status. Dependency staleness status.

⚠️ Android Trace only supports Android

Android Trace provides access to the Android NDK methods, such as ATrace_beginSection and ATrace_endSection. This enables using Android GPU Inspector for Rust code.

See tracing_android_trace for an integration of this with tracing.

Significant changes are documented in the changelog.

Quickstart

Add a dependency on Android Trace:

[target.'cfg(target_os = "android")'.dependencies]
android_trace = "0.1.0"

The main entry point to the library is AndroidTrace, which stores function pointers to each available NDK function:

use android_trace::AndroidTrace;
let trace = AndroidTrace::new();

// If the `is_enabled` method isn't available, we also shouldn't trace
let should_trace = trace.is_enabled().unwrap_or(false);
if should_trace {
  trace.begin_section(c"My expensive calculation");
}

// ...performing an expensive calculation

if should_trace {
  trace.end_section();
}

Android API levels

The first level of the tracing API has been available since Android API level 23, and a more flexible API was added in Android API level 29. To support devices with any Android API versions, we resolve these functions at runtime using dlsym. This runtime access is used unless we know (through features) that a certain API level is available.

Crate feature flags

The following feature flags are available:

  • api_level_23 (enabled by default): Require Android API level 23, to avoid some runtime symbol resolution
  • api_level_29: Require Android API level 29, to improve efficiency, to avoid runtime symbol resolution entirely

To support Android API versions less than 23, you should disable default features:

[target.'cfg(target_os = "android")'.dependencies]
android_trace = { version = "0.1.0", default-features = false }

Minimum supported Rust Version (MSRV)

This version of Android Trace has been verified to compile with Rust 1.77 and later.

Future versions of Android Trace might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.

Click here if compiling fails.

As time has passed, some of Android Trace's dependencies could have released versions with a higher Rust requirement. If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency.

# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1

Community

Discussion of Android Trace development happens in the Linebender Zulip, specifically in #general > Android Tracing. All public content can be read without logging in.

Contributions are welcome by pull request. The Rust code of conduct applies.

License

Licensed under either of

at your option.

Dependencies

~44KB