Skip to content

Commit

Permalink
feature gate metrics usage in program-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinheavey committed Nov 5, 2024
1 parent b39364f commit deeac27
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 2 additions & 1 deletion program-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions program-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![deny(clippy::arithmetic_side_effects)]
#![deny(clippy::indexing_slicing)]

#[cfg(feature = "metrics")]
#[macro_use]
extern crate solana_metrics;

Expand Down
32 changes: 24 additions & 8 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -16,7 +15,6 @@ use {
pubkey::Pubkey,
saturating_add_assign,
},
solana_timings::ExecuteDetailsTimings,
solana_type_overrides::{
rand::{thread_rng, Rng},
sync::{
Expand All @@ -31,6 +29,8 @@ use {
sync::Weak,
},
};
#[cfg(feature = "metrics")]
use {solana_measure::measure::Measure, solana_timings::ExecuteDetailsTimings};

pub type ProgramRuntimeEnvironment = Arc<BuiltinProgram<InvokeContext<'static>>>;
pub const MAX_LOADED_ENTRY_COUNT: usize = 256;
Expand Down Expand Up @@ -272,6 +272,7 @@ impl ProgramCacheStats {
}
}

#[cfg(feature = "metrics")]
/// Time measurements for loading a single [ProgramCacheEntry].
#[derive(Debug, Default)]
pub struct LoadProgramMetrics {
Expand All @@ -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!(
Expand Down Expand Up @@ -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, Box<dyn std::error::Error>> {
Self::new_internal(
loader_key,
Expand All @@ -333,6 +335,7 @@ impl ProgramCacheEntry {
effective_slot,
elf_bytes,
account_size,
#[cfg(feature = "metrics")]
metrics,
false, /* reloading */
)
Expand All @@ -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, Box<dyn std::error::Error>> {
Self::new_internal(
loader_key,
Expand All @@ -362,6 +365,7 @@ impl ProgramCacheEntry {
effective_slot,
elf_bytes,
account_size,
#[cfg(feature = "metrics")]
metrics,
true, /* reloading */
)
Expand All @@ -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<Self, Box<dyn std::error::Error>> {
#[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::<RequisiteVerifier>()?;
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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion svm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit deeac27

Please sign in to comment.