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

perf: use numbers instead of numeric strings in pprof labels #1831

Merged
merged 17 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
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
34 changes: 7 additions & 27 deletions profiling/Cargo.lock

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

4 changes: 2 additions & 2 deletions profiling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datadog-php-profiling"
version = "0.13.0"
version = "0.14.0"
edition = "2021"
license = "Apache-2.0"
rust-version = "1.60"
Expand All @@ -15,7 +15,7 @@ anyhow = { version = "1.0" }
cfg-if = { version = "1.0" }
crossbeam-channel = { version = "0.5", default-features = false, features = ["std"] }
cpu-time = { version = "1.0" }
datadog-profiling = { git = "https://github.com/DataDog/libdatadog", tag = "v1.0.0" }
datadog-profiling = { git = "https://github.com/DataDog/libdatadog", tag = "v2.0.0" }
env_logger = { version = "0.9.3" }
indexmap = { version = "1.8" }
lazy_static = { version = "1.4" }
Expand Down
30 changes: 18 additions & 12 deletions profiling/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use log::{debug, info, trace, warn};
use std::borrow::{Borrow, Cow};
use std::collections::HashMap;
use std::hash::Hash;
use std::intrinsics::transmute;
use std::str;
use std::str::Utf8Error;
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
Expand Down Expand Up @@ -59,20 +60,18 @@ impl WallTime {
#[derive(Debug, Clone)]
pub enum LabelValue {
Str(Cow<'static, str>),

#[allow(dead_code)]
Num(i64, Cow<'static, str>),
Num(i64, Option<&'static str>),
}

#[derive(Debug, Clone)]
pub struct Label {
pub key: Cow<'static, str>,
pub key: &'static str,
pub value: LabelValue,
}

impl<'a> From<&'a Label> for profile::api::Label<'a> {
fn from(label: &'a Label) -> Self {
let key = label.key.as_ref();
let key = label.key;
match &label.value {
LabelValue::Str(str) => Self {
key,
Expand All @@ -84,7 +83,7 @@ impl<'a> From<&'a Label> for profile::api::Label<'a> {
key,
str: None,
num: *num,
num_unit: Some(num_unit),
num_unit: num_unit.as_deref(),
},
}
}
Expand Down Expand Up @@ -388,9 +387,9 @@ impl TimeCollector {
"Received Endpoint Profiling message for span id {}.",
message.local_root_span_id
);
let local_root_span_id = message.local_root_span_id.to_string();

let local_root_span_id = message.local_root_span_id;
for (_, profile) in profiles.iter_mut() {
let local_root_span_id = Cow::Borrowed(local_root_span_id.as_ref());
let endpoint = Cow::Borrowed(message.resource.as_str());
profile.add_endpoint(local_root_span_id, endpoint)
}
Expand Down Expand Up @@ -832,13 +831,20 @@ impl Profiler {
if let Some(get_profiling_context) = gpc {
let context = unsafe { get_profiling_context() };
if context.local_root_span_id != 0 {
/* Safety: PProf only has signed integers for label.num.
* We bit-cast u64 to i64, and the backend does the
* reverse so the conversion is lossless.
*/
let local_root_span_id: i64 = unsafe { transmute(context.local_root_span_id) };
let span_id: i64 = unsafe { transmute(context.span_id) };

labels.push(Label {
key: "local root span id".into(),
value: LabelValue::Str(format!("{}", context.local_root_span_id).into()),
key: "local root span id",
value: LabelValue::Num(local_root_span_id, None),
});
labels.push(Label {
key: "span id".into(),
value: LabelValue::Str(format!("{}", context.span_id).into()),
key: "span id",
value: LabelValue::Num(span_id, None),
});
}
}
Expand Down