Skip to content

Commit

Permalink
Fix sidecar_mockgen for mac
Browse files Browse the repository at this point in the history
On mac symbol sizes are not known and underscore prefixed

Signed-off-by: Bob Weinand <bob.weinand@datadoghq.com>
  • Loading branch information
bwoebi authored and iamluc committed Apr 12, 2024
1 parent 7526a1a commit b9dbe10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 5 additions & 2 deletions sidecar/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ impl<S: Subscriber> Filter<S> for &MultiEnvFilter {
}

fn event_enabled(&self, event: &Event<'_>, cx: &Context<'_, S>) -> bool {
let enabled = self.maps
let enabled = self
.maps
.read()
.unwrap()
.values()
Expand Down Expand Up @@ -354,7 +355,9 @@ pub(crate) fn enable_logging() -> anyhow::Result<()> {

#[cfg(test)]
mod test {
use super::{TemporarilyRetainedKeyParser, TemporarilyRetainedMap, enable_logging, MULTI_LOG_FILTER};
use super::{
enable_logging, TemporarilyRetainedKeyParser, TemporarilyRetainedMap, MULTI_LOG_FILTER,
};
use lazy_static::lazy_static;
use std::sync::atomic::{AtomicI32, Ordering};
use std::time::Duration;
Expand Down
7 changes: 5 additions & 2 deletions sidecar/src/self_telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
use crate::config::Config;
use crate::interface::SidecarServer;
use crate::watchdog::WatchdogHandle;
use crate::log;
use crate::watchdog::WatchdogHandle;
use ddcommon::tag::Tag;
use ddtelemetry::data::metrics::{MetricNamespace, MetricType};
use ddtelemetry::metrics::ContextKey;
Expand Down Expand Up @@ -53,7 +53,10 @@ impl<'a> MetricData<'a> {
vec![],
),
];
for (level, count) in log::MULTI_LOG_FILTER.collect_logs_created_count().into_iter() {
for (level, count) in log::MULTI_LOG_FILTER
.collect_logs_created_count()
.into_iter()
{
futures.push(self.send(
self.logs_created,
count as f64,
Expand Down
21 changes: 18 additions & 3 deletions tools/sidecar_mockgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,33 @@ pub fn generate_mock_symbols(binary: &Path, objects: &[&Path]) -> Result<String,
if sym.is_definition() {
if let Ok(name) = sym.name() {
if missing_symbols.remove(name) {
// strip leading underscore
#[cfg(target_os = "macos")]
let name = &name[1..];
_ = match sym.kind() {
SymbolKind::Text => writeln!(generated, "void {}() {{}}", name),
// Ignore symbols of size 0, like _GLOBAL_OFFSET_TABLE_ on alpine
SymbolKind::Data => {
SymbolKind::Data | SymbolKind::Unknown => {
if sym.size() > 0 {
writeln!(generated, "char {}[{}];", name, sym.size())
} else {
Ok(())
#[cfg(not(target_os = "macos"))]
let ret = Ok(());
#[cfg(target_os = "macos")]
let ret = writeln!(generated, "char {}[1];", name);
ret
}
}
SymbolKind::Tls => {
writeln!(generated, "__thread char {}[{}];", name, sym.size())
if sym.size() > 0 {
writeln!(generated, "__thread char {}[{}];", name, sym.size())
} else {
#[cfg(not(target_os = "macos"))]
let ret = Ok(());
#[cfg(target_os = "macos")]
let ret = writeln!(generated, "__thread char {}[1];", name);
ret
}
}
_ => Ok(()),
};
Expand Down

0 comments on commit b9dbe10

Please sign in to comment.