Skip to content

Commit

Permalink
feat(prof) I/O profiling preview (#3083)
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl authored Feb 20, 2025
1 parent 4da93b3 commit c5148ba
Show file tree
Hide file tree
Showing 13 changed files with 974 additions and 9 deletions.
3 changes: 2 additions & 1 deletion profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ name = "stack_walking"
harness = false

[features]
default = ["allocation_profiling", "timeline", "exception_profiling"]
default = ["allocation_profiling", "timeline", "exception_profiling", "io_profiling"]
allocation_profiling = []
timeline = []
exception_profiling = []
stack_walking_tests = []
test = []
io_profiling = []

# only for testing:
trigger_time_sample = []
Expand Down
37 changes: 37 additions & 0 deletions profiling/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct SystemSettings {
pub profiling_exception_enabled: bool,
pub profiling_exception_message_enabled: bool,
pub profiling_wall_time_enabled: bool,
pub profiling_io_enabled: bool,

// todo: can't this be Option<String>? I don't think the string can ever be static.
pub output_pprof: Option<Cow<'static, str>>,
Expand All @@ -46,6 +47,7 @@ impl SystemSettings {
self.profiling_timeline_enabled = false;
self.profiling_exception_enabled = false;
self.profiling_exception_message_enabled = false;
self.profiling_io_enabled = false;
}

/// # Safety
Expand All @@ -68,6 +70,7 @@ impl SystemSettings {
profiling_exception_enabled: profiling_exception_enabled(),
profiling_exception_message_enabled: profiling_exception_message_enabled(),
profiling_wall_time_enabled: profiling_wall_time_enabled(),
profiling_io_enabled: profiling_io_enabled(),
output_pprof: profiling_output_pprof(),
profiling_exception_sampling_distance: profiling_exception_sampling_distance(),
profiling_log_level: profiling_log_level(),
Expand Down Expand Up @@ -131,6 +134,7 @@ impl SystemSettings {
profiling_exception_enabled: false,
profiling_exception_message_enabled: false,
profiling_wall_time_enabled: false,
profiling_io_enabled: false,
output_pprof: None,
profiling_exception_sampling_distance: 0,
profiling_log_level: LevelFilter::Off,
Expand All @@ -148,6 +152,7 @@ impl SystemSettings {
system_settings.profiling_timeline_enabled = false;
system_settings.profiling_exception_enabled = false;
system_settings.profiling_exception_message_enabled = false;
system_settings.profiling_io_enabled = false;
}
}

Expand Down Expand Up @@ -344,6 +349,7 @@ pub(crate) enum ConfigId {
ProfilingExceptionEnabled,
ProfilingExceptionMessageEnabled,
ProfilingExceptionSamplingDistance,
ProfilingExperimentalIOEnabled,
ProfilingLogLevel,
ProfilingOutputPprof,
ProfilingWallTimeEnabled,
Expand Down Expand Up @@ -372,6 +378,7 @@ impl ConfigId {
ProfilingExceptionEnabled => b"DD_PROFILING_EXCEPTION_ENABLED\0",
ProfilingExceptionMessageEnabled => b"DD_PROFILING_EXCEPTION_MESSAGE_ENABLED\0",
ProfilingExceptionSamplingDistance => b"DD_PROFILING_EXCEPTION_SAMPLING_DISTANCE\0",
ProfilingExperimentalIOEnabled => b"DD_PROFILING_EXPERIMENTAL_IO_ENABLED\0",
ProfilingLogLevel => b"DD_PROFILING_LOG_LEVEL\0",

// Note: this group is meant only for debugging and testing. Please
Expand Down Expand Up @@ -415,6 +422,7 @@ lazy_static::lazy_static! {
profiling_exception_enabled: false,
profiling_exception_message_enabled: false,
profiling_wall_time_enabled: false,
profiling_io_enabled: false,
output_pprof: None,
profiling_exception_sampling_distance: u32::MAX,
profiling_log_level: LevelFilter::Off,
Expand All @@ -432,6 +440,7 @@ lazy_static::lazy_static! {
profiling_exception_enabled: true,
profiling_exception_message_enabled: false,
profiling_wall_time_enabled: true,
profiling_io_enabled: false,
output_pprof: None,
profiling_exception_sampling_distance: 100,
profiling_log_level: LevelFilter::Off,
Expand Down Expand Up @@ -533,6 +542,18 @@ unsafe fn profiling_exception_sampling_distance() -> u32 {
)
}

/// # Safety
/// This function must only be called after config has been initialized in
/// rinit, and before it is uninitialized in mshutdown.
unsafe fn profiling_io_enabled() -> bool {
profiling_enabled()
&& (profiling_experimental_features_enabled()
|| get_system_bool(
ProfilingExperimentalIOEnabled,
DEFAULT_SYSTEM_SETTINGS.profiling_io_enabled,
))
}

/// # Safety
/// This function must only be called after config has been initialized in
/// first rinit, and before it is uninitialized in mshutdown.
Expand Down Expand Up @@ -874,6 +895,17 @@ pub(crate) fn minit(module_number: libc::c_int) {
parser: Some(parse_exception_sampling_distance_filter),
env_config_fallback: None,
},
zai_config_entry {
id: transmute::<ConfigId, u16>(ProfilingExperimentalIOEnabled),
name: ProfilingExperimentalIOEnabled.env_var_name(),
type_: ZAI_CONFIG_TYPE_BOOL,
default_encoded_value: ZaiStr::literal(b"0\0"),
aliases: ptr::null_mut(),
aliases_count: 0,
ini_change: Some(zai_config_system_ini_change),
parser: None,
env_config_fallback: None,
},
zai_config_entry {
id: transmute::<ConfigId, u16>(ProfilingLogLevel),
name: ProfilingLogLevel.env_var_name(),
Expand Down Expand Up @@ -1064,6 +1096,11 @@ mod tests {
b"DD_PROFILING_TIMELINE_ENABLED\0",
"datadog.profiling.timeline_enabled",
),
#[cfg(feature = "io_profiling")]
(
b"DD_PROFILING_EXPERIMENTAL_IO_ENABLED\0",
"datadog.profiling.experimental_io_enabled",
),
(b"DD_PROFILING_LOG_LEVEL\0", "datadog.profiling.log_level"),
(
b"DD_PROFILING_OUTPUT_PPROF\0",
Expand Down
Loading

0 comments on commit c5148ba

Please sign in to comment.