Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native-layer: Fix build on MacOS #15

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 42 additions & 17 deletions crates/layer/src/native_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use tracing_perfetto_sdk_schema::{
use tracing_perfetto_sdk_sys::ffi;
use tracing_subscriber::{fmt, layer, registry};

use crate::{debug_annotations, error, flavor, ids, init};
#[cfg(feature = "sdk")]
use crate::ffi_utils;
use crate::{debug_annotations, error, flavor, ids, init};

/// A layer to be used with `tracing-subscriber` that natively writes the
/// Perfetto trace packets in Rust code, but also polls the Perfetto SDK for
Expand Down Expand Up @@ -1003,8 +1003,8 @@ where
flush_timeout: time::Duration,
poll_timeout: time::Duration,
) -> error::Result<()> {

#[cfg(feature = "sdk")] {
#[cfg(feature = "sdk")]
{
use std::io::Write as _;

let data = ffi_utils::with_session_lock(&*self.ffi_session, |session| {
Expand All @@ -1019,7 +1019,8 @@ where
}

fn stop(&self) -> error::Result<()> {
#[cfg(feature = "sdk")] {
#[cfg(feature = "sdk")]
{
// Can't use ffi_utils::with_session_lock here because we want to take the
// session object
let mut session = self
Expand All @@ -1044,36 +1045,60 @@ where
}
}

#[cfg(not(feature="sdk"))]
#[cfg(not(feature = "sdk"))]
static HAS_BOOTTIME: sync::LazyLock<bool> = sync::LazyLock::new(|| {
nix::time::clock_gettime(nix::time::ClockId::CLOCK_BOOTTIME).is_ok()
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
{
nix::time::clock_gettime(nix::time::ClockId::CLOCK_BOOTTIME).is_ok()
}
#[cfg(not(any(linux_android, target_os = "emscripten", target_os = "fuchsia")))]
{
false
}
});

#[cfg(feature="sdk")]
#[cfg(feature = "sdk")]
fn trace_time_ns() -> u64 {
ffi::trace_time_ns()
}

#[cfg(not(feature="sdk"))]
#[cfg(not(feature = "sdk"))]
fn trace_time_ns() -> u64 {
use nix::time;
if *HAS_BOOTTIME {
std::time::Duration::from(time::clock_gettime(time::ClockId::CLOCK_BOOTTIME).unwrap()).as_nanos() as u64
} else {
std::time::Duration::from(time::clock_gettime(time::ClockId::CLOCK_MONOTONIC).unwrap()).as_nanos() as u64
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
{
if *HAS_BOOTTIME {
std::time::Duration::from(time::clock_gettime(time::ClockId::CLOCK_BOOTTIME).unwrap())
.as_nanos() as u64
} else {
std::time::Duration::from(time::clock_gettime(time::ClockId::CLOCK_MONOTONIC).unwrap())
.as_nanos() as u64
}
}
#[cfg(not(any(linux_android, target_os = "emscripten", target_os = "fuchsia")))]
{
std::time::Duration::from(time::clock_gettime(time::ClockId::CLOCK_MONOTONIC).unwrap())
.as_nanos() as u64
}
}

#[cfg(feature="sdk")]
#[cfg(feature = "sdk")]
fn trace_clock_id() -> u32 {
ffi::trace_clock_id()
}

#[cfg(not(feature="sdk"))]
#[cfg(not(feature = "sdk"))]
fn trace_clock_id() -> u32 {
if *HAS_BOOTTIME {
schema::BuiltinClock::Boottime as u32
} else {
#[cfg(any(linux_android, target_os = "emscripten", target_os = "fuchsia"))]
{
if *HAS_BOOTTIME {
schema::BuiltinClock::Boottime as u32
} else {
schema::BuiltinClock::Monotonic as u32
}
}
#[cfg(not(any(linux_android, target_os = "emscripten", target_os = "fuchsia")))]
{
schema::BuiltinClock::Monotonic as u32
}
}
Expand Down