Skip to content

Commit 8fac8d9

Browse files
chore(prof): apply cargo fmt and fix feature builds (#3064)
* update deps * run `cargo fmt` * add missing annotations to allow removing features from default build
1 parent 89afe55 commit 8fac8d9

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

Diff for: Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: profiling/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use bindgen::callbacks::IntKind;
22
use std::collections::HashSet;
3-
use std::{env, fs};
43
use std::path::Path;
54
use std::path::PathBuf;
65
use std::process::Command;
6+
use std::{env, fs};
77

88
fn main() {
99
let php_config_includes_output = Command::new("php-config")

Diff for: profiling/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,14 @@ extern "C" fn startup(extension: *mut ZendExtension) -> ZendResult {
876876
// Safety: calling this in zend_extension startup.
877877
unsafe {
878878
pcntl::startup();
879+
#[cfg(feature = "timeline")]
879880
timeline::timeline_startup();
880881
}
881882

882-
#[cfg(all(feature = "allocation_profiling", not(php_zend_mm_set_custom_handlers_ex)))]
883+
#[cfg(all(
884+
feature = "allocation_profiling",
885+
not(php_zend_mm_set_custom_handlers_ex)
886+
))]
883887
allocation::alloc_prof_startup();
884888

885889
ZendResult::Success

Diff for: profiling/src/pcntl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "allocation_profiling")]
12
use crate::allocation::alloc_prof_rshutdown;
23
use crate::bindings::{
34
datadog_php_install_handler, datadog_php_zif_handler, zend_execute_data, zend_long, zval,
@@ -101,6 +102,7 @@ unsafe fn handle_fork(
101102
// these situations.
102103
Profiler::kill();
103104

105+
#[cfg(feature = "allocation_profiling")]
104106
alloc_prof_rshutdown();
105107

106108
// Reset some global state to prevent further profiling and to not handle

Diff for: profiling/src/profiling/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::bindings::{datadog_php_profiling_get_profiling_context, zend_execute_
1919
use crate::config::SystemSettings;
2020
use crate::{CLOCKS, TAGS};
2121
use chrono::Utc;
22+
#[cfg(feature = "timeline")]
2223
use core::{ptr, str};
2324
use crossbeam_channel::{Receiver, Sender, TrySendError};
2425
use datadog_profiling::api::{
@@ -44,15 +45,14 @@ use std::time::UNIX_EPOCH;
4445

4546
#[cfg(feature = "allocation_profiling")]
4647
use crate::allocation::ALLOCATION_PROFILING_INTERVAL;
47-
#[cfg(feature = "allocation_profiling")]
48+
#[cfg(any(feature = "allocation_profiling", feature = "exception_profiling"))]
4849
use datadog_profiling::api::UpscalingInfo;
4950

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

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

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

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

764+
#[cfg(not(feature = "timeline"))]
765+
let mut timestamp = NO_TIMESTAMP;
766+
#[cfg(feature = "timeline")]
764767
let mut timestamp = NO_TIMESTAMP;
765768
#[cfg(feature = "timeline")]
766769
{
@@ -865,6 +868,9 @@ impl Profiler {
865868

866869
let n_labels = labels.len();
867870

871+
#[cfg(not(feature = "timeline"))]
872+
let timestamp = NO_TIMESTAMP;
873+
#[cfg(feature = "timeline")]
868874
let mut timestamp = NO_TIMESTAMP;
869875
#[cfg(feature = "timeline")]
870876
{

Diff for: profiling/src/profiling/uploader.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#[cfg(feature = "allocation_profiling")]
12
use crate::allocation::{ALLOCATION_PROFILING_COUNT, ALLOCATION_PROFILING_SIZE};
23
use crate::config::AgentEndpoint;
4+
#[cfg(feature = "exception_profiling")]
35
use crate::exception::EXCEPTION_PROFILING_EXCEPTION_COUNT;
46
use crate::profiling::{UploadMessage, UploadRequest};
57
use crate::{PROFILER_NAME_STR, PROFILER_VERSION_STR};
@@ -11,6 +13,7 @@ use log::{debug, info, warn};
1113
use serde_json::json;
1214
use std::borrow::Cow;
1315
use std::str;
16+
#[cfg(any(feature = "exception_profiling", feature = "allocation_profiling"))]
1417
use std::sync::atomic::Ordering;
1518
use std::sync::{Arc, Barrier};
1619

@@ -42,12 +45,22 @@ impl Uploader {
4245
/// This function will not only create the internal metadata JSON representation, but is also
4346
/// in charge to reset all those counters back to 0.
4447
fn create_internal_metadata() -> Option<serde_json::Value> {
45-
let metadata = json!({
48+
#[cfg(all(feature = "exception_profiling", feature = "allocation_profiling"))]
49+
Some(json!({
4650
"exceptions_count": EXCEPTION_PROFILING_EXCEPTION_COUNT.swap(0, Ordering::SeqCst),
4751
"allocations_count": ALLOCATION_PROFILING_COUNT.swap(0, Ordering::SeqCst),
4852
"allocations_size": ALLOCATION_PROFILING_SIZE.swap(0, Ordering::SeqCst),
49-
});
50-
Some(metadata)
53+
}));
54+
#[cfg(feature = "allocation_profiling")]
55+
Some(json!({
56+
"allocations_count": ALLOCATION_PROFILING_COUNT.swap(0, Ordering::SeqCst),
57+
"allocations_size": ALLOCATION_PROFILING_SIZE.swap(0, Ordering::SeqCst),
58+
}));
59+
#[cfg(feature = "exception_profiling")]
60+
Some(json!({
61+
"exceptions_count": EXCEPTION_PROFILING_EXCEPTION_COUNT.swap(0, Ordering::SeqCst),
62+
}));
63+
None
5164
}
5265

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

0 commit comments

Comments
 (0)