Skip to content

Commit

Permalink
chore(prof): apply cargo fmt and fix feature builds (#3064)
Browse files Browse the repository at this point in the history
* update deps

* run `cargo fmt`

* add missing annotations to allow removing features from default build
  • Loading branch information
realFlowControl committed Feb 14, 2025
1 parent c1b47b0 commit 72553e9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion profiling/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bindgen::callbacks::IntKind;
use std::collections::HashSet;
use std::{env, fs};
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;
use std::{env, fs};

fn main() {
let php_config_includes_output = Command::new("php-config")
Expand Down
6 changes: 5 additions & 1 deletion profiling/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,10 +877,14 @@ extern "C" fn startup(extension: *mut ZendExtension) -> ZendResult {
// Safety: calling this in zend_extension startup.
unsafe {
pcntl::startup();
#[cfg(feature = "timeline")]
timeline::timeline_startup();
}

#[cfg(feature = "allocation_profiling")]
#[cfg(all(
feature = "allocation_profiling",
not(php_zend_mm_set_custom_handlers_ex)
))]
allocation::alloc_prof_startup();

ZendResult::Success
Expand Down
2 changes: 2 additions & 0 deletions profiling/src/pcntl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "allocation_profiling")]
use crate::allocation::alloc_prof_rshutdown;
use crate::bindings::{
datadog_php_install_handler, datadog_php_zif_handler, zend_execute_data, zend_long, zval,
Expand Down Expand Up @@ -101,6 +102,7 @@ unsafe fn handle_fork(
// these situations.
Profiler::kill();

#[cfg(feature = "allocation_profiling")]
alloc_prof_rshutdown();

// Reset some global state to prevent further profiling and to not handle
Expand Down
10 changes: 8 additions & 2 deletions profiling/src/profiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::bindings::{datadog_php_profiling_get_profiling_context, zend_execute_
use crate::config::SystemSettings;
use crate::{CLOCKS, TAGS};
use chrono::Utc;
#[cfg(feature = "timeline")]
use core::{ptr, str};
use crossbeam_channel::{Receiver, Sender, TrySendError};
use datadog_profiling::api::{
Expand All @@ -44,15 +45,14 @@ use std::time::UNIX_EPOCH;

#[cfg(feature = "allocation_profiling")]
use crate::allocation::ALLOCATION_PROFILING_INTERVAL;
#[cfg(feature = "allocation_profiling")]
#[cfg(any(feature = "allocation_profiling", feature = "exception_profiling"))]
use datadog_profiling::api::UpscalingInfo;

#[cfg(feature = "exception_profiling")]
use crate::exception::EXCEPTION_PROFILING_INTERVAL;

const UPLOAD_PERIOD: Duration = Duration::from_secs(67);

#[cfg(feature = "timeline")]
pub const NO_TIMESTAMP: i64 = 0;

// Guide: upload period / upload timeout should give about the order of
Expand Down Expand Up @@ -761,6 +761,9 @@ impl Profiler {
let labels = Profiler::common_labels(0);
let n_labels = labels.len();

#[cfg(not(feature = "timeline"))]
let mut timestamp = NO_TIMESTAMP;
#[cfg(feature = "timeline")]
let mut timestamp = NO_TIMESTAMP;
#[cfg(feature = "timeline")]
{
Expand Down Expand Up @@ -865,6 +868,9 @@ impl Profiler {

let n_labels = labels.len();

#[cfg(not(feature = "timeline"))]
let timestamp = NO_TIMESTAMP;
#[cfg(feature = "timeline")]
let mut timestamp = NO_TIMESTAMP;
#[cfg(feature = "timeline")]
{
Expand Down
19 changes: 16 additions & 3 deletions profiling/src/profiling/uploader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#[cfg(feature = "allocation_profiling")]
use crate::allocation::{ALLOCATION_PROFILING_COUNT, ALLOCATION_PROFILING_SIZE};
use crate::config::AgentEndpoint;
#[cfg(feature = "exception_profiling")]
use crate::exception::EXCEPTION_PROFILING_EXCEPTION_COUNT;
use crate::profiling::{UploadMessage, UploadRequest};
use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR};
Expand All @@ -11,6 +13,7 @@ use log::{debug, info, warn};
use serde_json::json;
use std::borrow::Cow;
use std::str;
#[cfg(any(feature = "exception_profiling", feature = "allocation_profiling"))]
use std::sync::atomic::Ordering;
use std::sync::{Arc, Barrier};

Expand Down Expand Up @@ -42,12 +45,22 @@ impl Uploader {
/// This function will not only create the internal metadata JSON representation, but is also
/// in charge to reset all those counters back to 0.
fn create_internal_metadata() -> Option<serde_json::Value> {
let metadata = json!({
#[cfg(all(feature = "exception_profiling", feature = "allocation_profiling"))]
Some(json!({
"exceptions_count": EXCEPTION_PROFILING_EXCEPTION_COUNT.swap(0, Ordering::SeqCst),
"allocations_count": ALLOCATION_PROFILING_COUNT.swap(0, Ordering::SeqCst),
"allocations_size": ALLOCATION_PROFILING_SIZE.swap(0, Ordering::SeqCst),
});
Some(metadata)
}));
#[cfg(feature = "allocation_profiling")]
Some(json!({
"allocations_count": ALLOCATION_PROFILING_COUNT.swap(0, Ordering::SeqCst),
"allocations_size": ALLOCATION_PROFILING_SIZE.swap(0, Ordering::SeqCst),
}));
#[cfg(feature = "exception_profiling")]
Some(json!({
"exceptions_count": EXCEPTION_PROFILING_EXCEPTION_COUNT.swap(0, Ordering::SeqCst),
}));
None
}

fn create_profiler_info(&self) -> Option<serde_json::Value> {
Expand Down

0 comments on commit 72553e9

Please sign in to comment.