https://github.com/embarkstudios/tracing-ext-ffi-subscriber
Simple subscriber for forwarding tracing spans to a C or C++ profiling API.
https://github.com/embarkstudios/tracing-ext-ffi-subscriber
Last synced: about 1 year ago
JSON representation
Simple subscriber for forwarding tracing spans to a C or C++ profiling API.
- Host: GitHub
- URL: https://github.com/embarkstudios/tracing-ext-ffi-subscriber
- Owner: EmbarkStudios
- License: apache-2.0
- Created: 2022-05-15T09:25:15.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-19T11:18:21.000Z (almost 3 years ago)
- Last Synced: 2025-06-24T19:14:23.036Z (about 1 year ago)
- Language: Rust
- Size: 48.8 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE-APACHE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# `⏱️ tracing-ext-ffi-subscriber`
**Subscriber for passing spans from a rust library to a profiling tool in a host application via FFI.**
[](https://embark.dev)
[](https://discord.gg/dAuKfZS)
[](https://crates.io/crates/tracing-ext-ffi-subscriber)
[](https://docs.rs/tracing-ext-ffi-subscriber)
[](https://deps.rs/repo/github/EmbarkStudios/tracing-ext-ffi-subscriber)
[](https://github.com/EmbarkStudios/tracing-ext-ffi-subscriber/actions)
A simple crate for passing spans generated by the tracing ecosystem to a C or C++ profiling system when Rust is
integrated into an existing framework. To help with integration into other tools you can use the environment variable
`TRACING_FFI_RELATIVE_OUT_DIR` to configure where the include file ends relative to the build output (`OUT_DIR`). For
example, `TRACING_FFI_RELATIVE_OUT_DIR = "../../../../../include"` will normally lead to the files being generated in an
`include` dir next to your Cargo.toml.
## Example usage
```c
#include
#include
#include
int main(int argc, const char* argv[]) {
tracing_ffi_ReturnCode result = tracing_ffi_install_global_with_enable(
profiling_begin_named_scope,
profiling_end_named_scope,
profiling_is_enabled,
);
if (result != tracing_ffi_ReturnCode_Success) {
return (int)result;
}
myrustlib_execute(10, 20);
profiling_write_file("profile.json");
}
```
You can of course also configure this from Rust code; and bypass the C-api. In that case, use
`subscriber::ExternFFISpanSubscriber` directly, and install with your preferred `tracing` method.
## Contribution
[](../main/CODE_OF_CONDUCT.md)
We welcome community contributions to this project.
Please read our [Contributor Guide](CONTRIBUTING.md) for more information on how to get started.
Please also read our [Contributor Terms](CONTRIBUTING.md#contributor-terms) before you make any contributions.
Any contribution intentionally submitted for inclusion in an Embark Studios project, shall comply with the Rust standard licensing model (MIT OR Apache 2.0) and therefore be dual licensed as described below, without any additional terms or conditions:
### License
This contribution is dual licensed under EITHER OF
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license ([LICENSE-MIT](LICENSE-MIT) or )
at your option.
For clarity, "your" refers to Embark or any other licensee/user of the contribution.