Skip to content

Commit 3d127bc

Browse files
allow to enable all experimental features
1 parent 9688e0f commit 3d127bc

File tree

5 files changed

+194
-6
lines changed

5 files changed

+194
-6
lines changed

profiling/src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub(crate) unsafe fn get_value(id: ConfigId) -> &'static mut zval {
137137
#[derive(Clone, Copy)]
138138
pub(crate) enum ConfigId {
139139
ProfilingEnabled = 0,
140+
ProfilingExperimentalFeaturesEnabled,
140141
ProfilingEndpointCollectionEnabled,
141142
ProfilingExperimentalCpuTimeEnabled,
142143
ProfilingAllocationEnabled,
@@ -162,6 +163,7 @@ impl ConfigId {
162163
const fn env_var_name(&self) -> ZaiStr {
163164
let bytes: &'static [u8] = match self {
164165
ProfilingEnabled => b"DD_PROFILING_ENABLED\0",
166+
ProfilingExperimentalFeaturesEnabled => b"DD_PROFILING_EXPERIMENTAL_FEATURES_ENABLED\0",
165167
ProfilingEndpointCollectionEnabled => b"DD_PROFILING_ENDPOINT_COLLECTION_ENABLED\0",
166168
ProfilingExperimentalCpuTimeEnabled => b"DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED\0",
167169
ProfilingAllocationEnabled => b"DD_PROFILING_ALLOCATION_ENABLED\0",
@@ -200,6 +202,13 @@ pub(crate) unsafe fn profiling_enabled() -> bool {
200202
get_bool(ProfilingEnabled, true)
201203
}
202204

205+
/// # Safety
206+
/// This function must only be called after config has been initialized in
207+
/// rinit, and before it is uninitialized in mshutdown.
208+
pub(crate) unsafe fn profiling_experimental_features_enabled() -> bool {
209+
get_bool(ProfilingExperimentalFeaturesEnabled, false)
210+
}
211+
203212
/// # Safety
204213
/// This function must only be called after config has been initialized in
205214
/// rinit, and before it is uninitialized in mshutdown.
@@ -449,6 +458,16 @@ pub(crate) fn minit(module_number: libc::c_int) {
449458
ini_change: None,
450459
parser: None,
451460
},
461+
zai_config_entry {
462+
id: transmute(ProfilingExperimentalFeaturesEnabled),
463+
name: ProfilingExperimentalFeaturesEnabled.env_var_name(),
464+
type_: ZAI_CONFIG_TYPE_BOOL,
465+
default_encoded_value: ZaiStr::literal(b"0\0"),
466+
aliases: std::ptr::null_mut(),
467+
aliases_count: 0,
468+
ini_change: None,
469+
parser: None,
470+
},
452471
zai_config_entry {
453472
id: transmute(ProfilingEndpointCollectionEnabled),
454473
name: ProfilingEndpointCollectionEnabled.env_var_name(),
@@ -628,6 +647,10 @@ mod tests {
628647
(b"DD_TRACE_AGENT_PORT\0", "datadog.trace.agent_port"),
629648
(b"DD_AGENT_HOST\0", "datadog.agent_host"),
630649
(b"DD_PROFILING_ENABLED\0", "datadog.profiling.enabled"),
650+
(
651+
b"DD_PROFILING_EXPERIMENTAL_FEATURES_ENABLED\0",
652+
"datadog.profiling.experimental_features_enabled",
653+
),
631654
(
632655
b"DD_PROFILING_ENDPOINT_COLLECTION_ENABLED\0",
633656
"datadog.profiling.endpoint_collection_enabled",

profiling/src/lib.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ pub struct RequestLocals {
371371
pub env: Option<Cow<'static, str>>,
372372
pub interrupt_count: AtomicU32,
373373
pub profiling_enabled: bool,
374+
pub profiling_experimental_features_enabled: bool,
374375
pub profiling_endpoint_collection_enabled: bool,
375376
pub profiling_experimental_cpu_time_enabled: bool,
376377
pub profiling_allocation_enabled: bool,
@@ -387,6 +388,7 @@ pub struct RequestLocals {
387388
impl RequestLocals {
388389
pub fn disable(&mut self) {
389390
self.profiling_enabled = false;
391+
self.profiling_experimental_features_enabled = false;
390392
self.profiling_endpoint_collection_enabled = false;
391393
self.profiling_experimental_cpu_time_enabled = false;
392394
self.profiling_allocation_enabled = false;
@@ -401,6 +403,7 @@ impl Default for RequestLocals {
401403
env: None,
402404
interrupt_count: AtomicU32::new(0),
403405
profiling_enabled: false,
406+
profiling_experimental_features_enabled: false,
404407
profiling_endpoint_collection_enabled: true,
405408
profiling_experimental_cpu_time_enabled: true,
406409
profiling_allocation_enabled: true,
@@ -465,6 +468,7 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
465468
// Safety: We are after first rinit and before mshutdown.
466469
let (
467470
profiling_enabled,
471+
profiling_experimental_features_enabled,
468472
profiling_endpoint_collection_enabled,
469473
profiling_experimental_cpu_time_enabled,
470474
profiling_allocation_enabled,
@@ -475,13 +479,19 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
475479
output_pprof,
476480
) = unsafe {
477481
let profiling_enabled = config::profiling_enabled();
482+
let profiling_experimental_features_enabled =
483+
profiling_enabled && config::profiling_experimental_features_enabled();
478484
(
479485
profiling_enabled,
486+
profiling_experimental_features_enabled,
480487
profiling_enabled && config::profiling_endpoint_collection_enabled(),
481-
profiling_enabled && config::profiling_experimental_cpu_time_enabled(),
488+
profiling_experimental_features_enabled
489+
|| profiling_enabled && config::profiling_experimental_cpu_time_enabled(),
482490
profiling_enabled && config::profiling_allocation_enabled(),
483-
profiling_enabled && config::profiling_experimental_timeline_enabled(),
484-
profiling_enabled && config::profiling_experimental_exception_enabled(),
491+
profiling_experimental_features_enabled
492+
|| profiling_enabled && config::profiling_experimental_timeline_enabled(),
493+
profiling_experimental_features_enabled
494+
|| profiling_enabled && config::profiling_experimental_exception_enabled(),
485495
config::profiling_experimental_exception_sampling_distance(),
486496
config::profiling_log_level(),
487497
config::profiling_output_pprof(),
@@ -496,6 +506,7 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult {
496506
locals.interrupt_count.store(0, Ordering::SeqCst);
497507

498508
locals.profiling_enabled = profiling_enabled;
509+
locals.profiling_experimental_features_enabled = profiling_experimental_features_enabled;
499510
locals.profiling_endpoint_collection_enabled = profiling_endpoint_collection_enabled;
500511
locals.profiling_experimental_cpu_time_enabled = profiling_experimental_cpu_time_enabled;
501512
locals.profiling_allocation_enabled = profiling_allocation_enabled;
@@ -766,6 +777,7 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) {
766777
REQUEST_LOCALS.with(|cell| {
767778
let locals = cell.borrow();
768779
let yes: &[u8] = b"true\0";
780+
let yes_exp: &[u8] = b"true (all experimental features enabled)\0";
769781
let no: &[u8] = b"false\0";
770782
let no_all: &[u8] = b"false (profiling disabled)\0";
771783
zend::php_info_print_table_start();
@@ -776,11 +788,27 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) {
776788
if locals.profiling_enabled { yes } else { no },
777789
);
778790

791+
zend::php_info_print_table_row(
792+
2,
793+
b"Profiling Experimental Features Enabled\0".as_ptr(),
794+
if locals.profiling_experimental_features_enabled {
795+
yes
796+
} else if locals.profiling_enabled {
797+
no
798+
} else {
799+
no_all
800+
},
801+
);
802+
779803
zend::php_info_print_table_row(
780804
2,
781805
b"Experimental CPU Time Profiling Enabled\0".as_ptr(),
782806
if locals.profiling_experimental_cpu_time_enabled {
783-
yes
807+
if locals.profiling_experimental_features_enabled {
808+
yes_exp
809+
} else {
810+
yes
811+
}
784812
} else if locals.profiling_enabled {
785813
no
786814
} else {
@@ -818,7 +846,11 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) {
818846
2,
819847
b"Experimental Timeline Enabled\0".as_ptr(),
820848
if locals.profiling_experimental_timeline_enabled {
821-
yes
849+
if locals.profiling_experimental_features_enabled {
850+
yes_exp
851+
} else {
852+
yes
853+
}
822854
} else if locals.profiling_enabled {
823855
no
824856
} else {
@@ -840,7 +872,11 @@ unsafe extern "C" fn minfo(module_ptr: *mut zend::ModuleEntry) {
840872
2,
841873
b"Experimental Exception Profiling Enabled\0".as_ptr(),
842874
if locals.profiling_experimental_exception_enabled {
843-
yes
875+
if locals.profiling_experimental_features_enabled {
876+
yes_exp
877+
} else {
878+
yes
879+
}
844880
} else if locals.profiling_enabled {
845881
no
846882
} else {

profiling/src/profiling/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,7 @@ mod tests {
11101110
env: None,
11111111
interrupt_count: AtomicU32::new(0),
11121112
profiling_enabled: true,
1113+
profiling_experimental_features_enabled: false,
11131114
profiling_endpoint_collection_enabled: true,
11141115
profiling_experimental_cpu_time_enabled: false,
11151116
profiling_allocation_enabled: false,

profiling/tests/phpt/phpinfo_05.phpt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
[profiling] test profiler's extension info with experimental feature override
3+
--DESCRIPTION--
4+
The profiler's phpinfo section contains important debugging information. This
5+
test verifies that certain information is present.
6+
--SKIPIF--
7+
<?php
8+
if (!extension_loaded('datadog-profiling'))
9+
echo "skip: test requires Datadog Continuous Profiler\n";
10+
?>
11+
--ENV--
12+
DD_PROFILING_ENABLED=yes
13+
DD_PROFILING_EXPERIMENTAL_FEATURES_ENABLED=yes
14+
DD_PROFILING_LOG_LEVEL=off
15+
DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED=no
16+
DD_PROFILING_ALLOCATION_ENABLED=no
17+
DD_PROFILING_EXPERIMENTAL_EXCEPTION_ENABLED=no
18+
DD_PROFILING_EXPERIMENTAL_TIMELINE_ENABLED=no
19+
--INI--
20+
assert.exception=1
21+
opcache.jit=off
22+
--FILE--
23+
<?php
24+
25+
ob_start();
26+
$extension = new ReflectionExtension('datadog-profiling');
27+
$extension->info();
28+
$output = ob_get_clean();
29+
30+
$lines = preg_split("/\R/", $output);
31+
$values = [];
32+
foreach ($lines as $line) {
33+
$pair = explode("=>", $line);
34+
if (count($pair) != 2) {
35+
continue;
36+
}
37+
$values[trim($pair[0])] = trim($pair[1]);
38+
}
39+
40+
// Check that Version exists, but not its value
41+
assert(isset($values["Version"]));
42+
43+
// Check exact values for this set
44+
$sections = [
45+
["Profiling Enabled", "true"],
46+
["Profiling Experimental Features Enabled", "true"],
47+
["Experimental CPU Time Profiling Enabled", "true (all experimental features enabled)"],
48+
["Allocation Profiling Enabled", "false"],
49+
["Experimental Exception Profiling Enabled", "true (all experimental features enabled)"],
50+
["Experimental Timeline Enabled", "true (all experimental features enabled)"],
51+
];
52+
53+
foreach ($sections as [$key, $expected]) {
54+
assert(
55+
$values[$key] === $expected,
56+
"Expected '{$expected}', found '{$values[$key]}', for key '{$key}'"
57+
);
58+
}
59+
60+
echo "Done.";
61+
62+
?>
63+
--EXPECT--
64+
Done.

profiling/tests/phpt/phpinfo_06.phpt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
[profiling] test profiler's extension info with experimental feature override
3+
--DESCRIPTION--
4+
The profiler's phpinfo section contains important debugging information. This
5+
test verifies that certain information is present.
6+
--SKIPIF--
7+
<?php
8+
if (!extension_loaded('datadog-profiling'))
9+
echo "skip: test requires Datadog Continuous Profiler\n";
10+
?>
11+
--ENV--
12+
DD_PROFILING_ENABLED=no
13+
DD_PROFILING_EXPERIMENTAL_FEATURES_ENABLED=yes
14+
DD_PROFILING_LOG_LEVEL=off
15+
DD_PROFILING_EXPERIMENTAL_CPU_TIME_ENABLED=no
16+
DD_PROFILING_ALLOCATION_ENABLED=no
17+
DD_PROFILING_EXPERIMENTAL_EXCEPTION_ENABLED=no
18+
DD_PROFILING_EXPERIMENTAL_TIMELINE_ENABLED=no
19+
--INI--
20+
assert.exception=1
21+
opcache.jit=off
22+
--FILE--
23+
<?php
24+
25+
ob_start();
26+
$extension = new ReflectionExtension('datadog-profiling');
27+
$extension->info();
28+
$output = ob_get_clean();
29+
30+
$lines = preg_split("/\R/", $output);
31+
$values = [];
32+
foreach ($lines as $line) {
33+
$pair = explode("=>", $line);
34+
if (count($pair) != 2) {
35+
continue;
36+
}
37+
$values[trim($pair[0])] = trim($pair[1]);
38+
}
39+
40+
// Check that Version exists, but not its value
41+
assert(isset($values["Version"]));
42+
43+
// Check exact values for this set
44+
$sections = [
45+
["Profiling Enabled", "false"],
46+
["Profiling Experimental Features Enabled", "false (profiling disabled)"],
47+
["Experimental CPU Time Profiling Enabled", "false (profiling disabled)"],
48+
["Allocation Profiling Enabled", "false (profiling disabled)"],
49+
["Experimental Exception Profiling Enabled", "false (profiling disabled)"],
50+
["Experimental Timeline Enabled", "false (profiling disabled)"],
51+
];
52+
53+
foreach ($sections as [$key, $expected]) {
54+
assert(
55+
$values[$key] === $expected,
56+
"Expected '{$expected}', found '{$values[$key]}', for key '{$key}'"
57+
);
58+
}
59+
60+
echo "Done.";
61+
62+
?>
63+
--EXPECT--
64+
Done.

0 commit comments

Comments
 (0)