Skip to content

Commit

Permalink
layer: Introduce explicit "sdk" feature that can be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dflemstr committed Nov 18, 2024
1 parent 9857fcb commit 5cd575b
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 48 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ jobs:
run: cargo build --all
- name: Run tests
run: cargo test --all
build-no-default-features:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Protoc
uses: arduino/setup-protoc@v3
- name: Build
run: cargo build --all --no-default-features
- name: Run tests
run: cargo test --all --no-default-features
build-tokio:
runs-on: ubuntu-latest
steps:
Expand Down
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bytes = "1.8.0"
cxx = { version = "1.0.129", features = ["c++17"] }
cxx-build = { version = "1.0.129", features = ["parallel"] }
futures = "0.3.31"
nix = "0.29.0"
pbjson = "0.6.0"
pbjson-build = "0.6.2"
pbjson-types = "0.6.0"
Expand Down
5 changes: 4 additions & 1 deletion crates/layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ edition.workspace = true
[dependencies]
bytes.workspace = true
cxx.workspace = true
nix = { workspace = true, features = ["time"] }
prost.workspace = true
thiserror.workspace = true
thread-id.workspace = true
thread_local.workspace = true
tokio = { workspace = true, optional = true }
tracing.workspace = true
tracing-perfetto-sdk-schema.workspace = true
tracing-perfetto-sdk-sys.workspace = true
tracing-perfetto-sdk-sys = { workspace = true, optional = true }
tracing-subscriber.workspace = true

[dev-dependencies]
Expand All @@ -26,8 +27,10 @@ tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"] }
tracing-appender.workspace = true

[features]
default = ["sdk"]
tokio = ["dep:tokio"]
serde = ["tracing-perfetto-sdk-schema/serde"]
sdk = ["dep:tracing-perfetto-sdk-sys"]

[[example]]
name = "native-layer"
Expand Down
4 changes: 4 additions & 0 deletions crates/layer/src/debug_annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ use schema::debug_annotation;
use tracing::field;
use tracing_perfetto_sdk_schema as schema;
use tracing_perfetto_sdk_schema::track_event;
#[cfg(feature = "sdk")]
use tracing_perfetto_sdk_sys::ffi;

const COUNTER_FIELD_PREFIX: &str = "counter.";
const SUPPRESS_EVENT_FIELD: &str = "perfetto.suppress_event";

#[cfg(feature = "sdk")]
#[derive(Default)]
pub struct FFIDebugAnnotations {
counters: Vec<Counter>,
Expand Down Expand Up @@ -42,6 +44,7 @@ pub enum CounterValue {
Int(i64),
}

#[cfg(feature = "sdk")]
impl FFIDebugAnnotations {
pub fn as_ffi(&self) -> ffi::DebugAnnotations {
ffi::DebugAnnotations {
Expand All @@ -57,6 +60,7 @@ impl FFIDebugAnnotations {
}
}

#[cfg(feature = "sdk")]
impl field::Visit for FFIDebugAnnotations {
fn record_f64(&mut self, field: &field::Field, value: f64) {
if !populate_counter(&mut self.counters, field, value) {
Expand Down
4 changes: 4 additions & 0 deletions crates/layer/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#[cfg(feature = "sdk")]
use tracing_perfetto_sdk_sys::ffi;

#[allow(unused_variables)]
pub fn global_init(enable_in_process_backend: bool, enable_system_backend: bool) {
#[cfg(feature = "sdk")]
ffi::perfetto_global_init(
log_callback,
enable_in_process_backend,
enable_system_backend,
);
}

#[cfg(feature = "sdk")]
fn log_callback(level: ffi::LogLev, line: i32, filename: &str, message: &str) {
match level {
ffi::LogLev::Debug => {
Expand Down
3 changes: 3 additions & 0 deletions crates/layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
// Internal modules:
mod debug_annotations;
#[cfg(feature = "sdk")]
mod ffi_utils;
mod ids;
mod init;
Expand All @@ -179,10 +180,12 @@ mod init;
pub mod error;
pub mod flavor;
pub mod native_layer;
#[cfg(feature = "sdk")]
pub mod sdk_layer;

// Convenience re-exports:
pub use error::Error;
pub use flavor::Flavor;
pub use native_layer::NativeLayer;
#[cfg(feature = "sdk")]
pub use sdk_layer::SdkLayer;
Loading

0 comments on commit 5cd575b

Please sign in to comment.