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 Jan 1, 2025
1 parent d64e0a1 commit 1f772a8
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 @@ -116,7 +116,7 @@ solana-ledger = { workspace = true, features = ["dev-context-only-utils"] }
solana-logger = { workspace = true }
solana-net-utils = { workspace = true, features = ["dev-context-only-utils"] }
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-system-program = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 @@ -37,7 +37,7 @@ solana-instruction = { workspace = true }
solana-last-restart-slot = { workspace = true }
solana-log-collector = { workspace = true }
solana-measure = { workspace = true }
solana-metrics = { workspace = true }
solana-metrics = { workspace = true, optional = true }
solana-precompiles = { workspace = true }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
Expand Down Expand Up @@ -74,6 +74,7 @@ frozen-abi = [
"dep:solana-frozen-abi-macro",
"solana-compute-budget/frozen-abi",
]
metrics = ["dep:solana-metrics"]
shuttle-test = [
"solana-type-overrides/shuttle-test",
"solana-sbpf/shuttle-test",
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 @@ -3,7 +3,6 @@ use {
log::{debug, error, log_enabled, trace},
percentage::PercentageInteger,
solana_clock::{Epoch, Slot},
solana_measure::measure::Measure,
solana_pubkey::Pubkey,
solana_sbpf::{
elf::Executable,
Expand All @@ -14,7 +13,6 @@ use {
solana_sdk_ids::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4, native_loader,
},
solana_timings::ExecuteDetailsTimings,
solana_type_overrides::{
rand::{thread_rng, Rng},
sync::{
Expand All @@ -29,6 +27,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 = 512;
Expand Down Expand Up @@ -270,6 +270,7 @@ impl ProgramCacheStats {
}
}

#[cfg(feature = "metrics")]
/// Time measurements for loading a single [ProgramCacheEntry].
#[derive(Debug, Default)]
pub struct LoadProgramMetrics {
Expand All @@ -285,6 +286,7 @@ pub struct LoadProgramMetrics {
pub jit_compile_us: u64,
}

#[cfg(feature = "metrics")]
impl LoadProgramMetrics {
pub fn submit_datapoint(&self, timings: &mut ExecuteDetailsTimings) {
timings.create_executor_register_syscalls_us += self.register_syscalls_us;
Expand Down Expand Up @@ -319,7 +321,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 @@ -328,6 +330,7 @@ impl ProgramCacheEntry {
effective_slot,
elf_bytes,
account_size,
#[cfg(feature = "metrics")]
metrics,
false, /* reloading */
)
Expand All @@ -348,7 +351,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 @@ -357,6 +360,7 @@ impl ProgramCacheEntry {
effective_slot,
elf_bytes,
account_size,
#[cfg(feature = "metrics")]
metrics,
true, /* reloading */
)
Expand All @@ -369,27 +373,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 @@ -70,7 +70,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 @@ -41,7 +41,7 @@ solana-message = { workspace = true }
solana-nonce = { workspace = true }
solana-precompiles = { workspace = true }
solana-program = { workspace = true, default-features = false }
solana-program-runtime = { workspace = true }
solana-program-runtime = { workspace = true, features = ["metrics"] }
solana-pubkey = { workspace = true }
solana-rent = { workspace = true }
solana-rent-debits = { workspace = true }
Expand Down

0 comments on commit 1f772a8

Please sign in to comment.