diff --git a/core/Cargo.toml b/core/Cargo.toml index 3b8f37a0db3298..f8236eb01de733 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -109,7 +109,7 @@ solana-cost-model = { workspace = true, features = ["dev-context-only-utils"] } solana-ledger = { workspace = true, features = ["dev-context-only-utils"] } solana-logger = { workspace = true } solana-poh = { workspace = true, features = ["dev-context-only-utils"] } -solana-program-runtime = { workspace = true } +solana-program-runtime = { workspace = true, features = ["metrics"] } solana-sdk = { workspace = true, features = ["dev-context-only-utils"] } solana-stake-program = { workspace = true } solana-unified-scheduler-pool = { workspace = true, features = [ diff --git a/ledger-tool/Cargo.toml b/ledger-tool/Cargo.toml index 9e9fc9838df959..702bf1c76513bf 100644 --- a/ledger-tool/Cargo.toml +++ b/ledger-tool/Cargo.toml @@ -42,7 +42,7 @@ solana-ledger = { workspace = true, features = ["dev-context-only-utils"] } solana-log-collector = { workspace = true } solana-logger = { workspace = true } solana-measure = { workspace = true } -solana-program-runtime = { workspace = true } +solana-program-runtime = { workspace = true, features = ["metrics"] } solana-rpc = { workspace = true } solana-runtime = { workspace = true, features = ["dev-context-only-utils"] } solana-runtime-transaction = { workspace = true } diff --git a/ledger/Cargo.toml b/ledger/Cargo.toml index f4b1a560a52002..268e31e0be6512 100644 --- a/ledger/Cargo.toml +++ b/ledger/Cargo.toml @@ -56,7 +56,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ solana-measure = { workspace = true } solana-metrics = { workspace = true } solana-perf = { workspace = true } -solana-program-runtime = { workspace = true } +solana-program-runtime = { workspace = true, features = ["metrics"] } solana-rayon-threadlimit = { workspace = true } solana-runtime = { workspace = true } solana-runtime-transaction = { workspace = true } diff --git a/program-runtime/Cargo.toml b/program-runtime/Cargo.toml index 4e764de35b5854..015b392e75d45d 100644 --- a/program-runtime/Cargo.toml +++ b/program-runtime/Cargo.toml @@ -31,7 +31,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ ] } solana-log-collector = { workspace = true } solana-measure = { workspace = true } -solana-metrics = { workspace = true } +solana-metrics = { workspace = true, optional = true } solana-sdk = { workspace = true } solana-timings = { workspace = true } solana-type-overrides = { workspace = true } @@ -59,6 +59,7 @@ frozen-abi = [ "solana-compute-budget/frozen-abi", "solana-sdk/frozen-abi", ] +metrics = ["dep:solana-metrics"] shuttle-test = ["solana-type-overrides/shuttle-test", "solana_rbpf/shuttle-test"] [lints] diff --git a/program-runtime/src/lib.rs b/program-runtime/src/lib.rs index 3a690d1d0824e9..d374e2a5fe5f24 100644 --- a/program-runtime/src/lib.rs +++ b/program-runtime/src/lib.rs @@ -2,6 +2,7 @@ #![deny(clippy::arithmetic_side_effects)] #![deny(clippy::indexing_slicing)] +#[cfg(feature = "metrics")] #[macro_use] extern crate solana_metrics; diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 181f5280db71d6..e4e2572d49b800 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -2,7 +2,6 @@ use { crate::invoke_context::{BuiltinFunctionWithContext, InvokeContext}, log::{debug, error, log_enabled, trace}, percentage::PercentageInteger, - solana_measure::measure::Measure, solana_rbpf::{ elf::Executable, program::{BuiltinProgram, FunctionRegistry}, @@ -16,7 +15,6 @@ use { pubkey::Pubkey, saturating_add_assign, }, - solana_timings::ExecuteDetailsTimings, solana_type_overrides::{ rand::{thread_rng, Rng}, sync::{ @@ -31,6 +29,8 @@ use { sync::Weak, }, }; +#[cfg(feature = "metrics")] +use {solana_measure::measure::Measure, solana_timings::ExecuteDetailsTimings}; pub type ProgramRuntimeEnvironment = Arc>>; pub const MAX_LOADED_ENTRY_COUNT: usize = 256; @@ -272,6 +272,7 @@ impl ProgramCacheStats { } } +#[cfg(feature = "metrics")] /// Time measurements for loading a single [ProgramCacheEntry]. #[derive(Debug, Default)] pub struct LoadProgramMetrics { @@ -287,6 +288,7 @@ pub struct LoadProgramMetrics { pub jit_compile_us: u64, } +#[cfg(feature = "metrics")] impl LoadProgramMetrics { pub fn submit_datapoint(&self, timings: &mut ExecuteDetailsTimings) { saturating_add_assign!( @@ -324,7 +326,7 @@ impl ProgramCacheEntry { effective_slot: Slot, elf_bytes: &[u8], account_size: usize, - metrics: &mut LoadProgramMetrics, + #[cfg(feature = "metrics")] metrics: &mut LoadProgramMetrics, ) -> Result> { Self::new_internal( loader_key, @@ -333,6 +335,7 @@ impl ProgramCacheEntry { effective_slot, elf_bytes, account_size, + #[cfg(feature = "metrics")] metrics, false, /* reloading */ ) @@ -353,7 +356,7 @@ impl ProgramCacheEntry { effective_slot: Slot, elf_bytes: &[u8], account_size: usize, - metrics: &mut LoadProgramMetrics, + #[cfg(feature = "metrics")] metrics: &mut LoadProgramMetrics, ) -> Result> { Self::new_internal( loader_key, @@ -362,6 +365,7 @@ impl ProgramCacheEntry { effective_slot, elf_bytes, account_size, + #[cfg(feature = "metrics")] metrics, true, /* reloading */ ) @@ -374,27 +378,39 @@ impl ProgramCacheEntry { effective_slot: Slot, elf_bytes: &[u8], account_size: usize, - metrics: &mut LoadProgramMetrics, + #[cfg(feature = "metrics")] metrics: &mut LoadProgramMetrics, reloading: bool, ) -> Result> { + #[cfg(feature = "metrics")] let load_elf_time = Measure::start("load_elf_time"); // The following unused_mut exception is needed for architectures that do not // support JIT compilation. #[allow(unused_mut)] let mut executable = Executable::load(elf_bytes, program_runtime_environment.clone())?; - metrics.load_elf_us = load_elf_time.end_as_us(); + #[cfg(feature = "metrics")] + { + metrics.load_elf_us = load_elf_time.end_as_us(); + } if !reloading { + #[cfg(feature = "metrics")] let verify_code_time = Measure::start("verify_code_time"); executable.verify::()?; - metrics.verify_code_us = verify_code_time.end_as_us(); + #[cfg(feature = "metrics")] + { + metrics.verify_code_us = verify_code_time.end_as_us(); + } } #[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))] { + #[cfg(feature = "metrics")] let jit_compile_time = Measure::start("jit_compile_time"); executable.jit_compile()?; - metrics.jit_compile_us = jit_compile_time.end_as_us(); + #[cfg(feature = "metrics")] + { + metrics.jit_compile_us = jit_compile_time.end_as_us(); + } } Ok(Self { diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b7eefcea5a76b2..069d11724f39f8 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -71,7 +71,7 @@ solana-measure = { workspace = true } solana-metrics = { workspace = true } solana-perf = { workspace = true } solana-program = { workspace = true } -solana-program-runtime = { workspace = true } +solana-program-runtime = { workspace = true, features = ["metrics"] } solana-rayon-threadlimit = { workspace = true } solana-runtime-transaction = { workspace = true } solana-sdk = { workspace = true } diff --git a/svm/Cargo.toml b/svm/Cargo.toml index a6edc55fc1fca2..505c76fdab6927 100644 --- a/svm/Cargo.toml +++ b/svm/Cargo.toml @@ -29,7 +29,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ solana-loader-v4-program = { workspace = true } solana-log-collector = { workspace = true } solana-measure = { workspace = true } -solana-program-runtime = { workspace = true } +solana-program-runtime = { workspace = true, features = ["metrics"] } solana-runtime-transaction = { workspace = true } solana-sdk = { workspace = true } solana-svm-rent-collector = { workspace = true }