From 768fbd4c301d802c461d655c36678e2aaf987301 Mon Sep 17 00:00:00 2001 From: renancloudwalk <53792026+renancloudwalk@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:24:08 -0300 Subject: [PATCH] Fix flamegraph details (#268) * chore: create a way to stop poller if there is no more blocks * chore: add missing details to justfile * doc: explain snippet --- justfile | 6 +++++- src/bin/rpc_server_poller.rs | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index 839cdf118..fc5ed1fba 100644 --- a/justfile +++ b/justfile @@ -15,6 +15,9 @@ setup: @echo "* Installing Cargo wait-service" cargo install wait-service + @echo "* Installing Cargo flamegraph" + cargo install flamegraph + @echo "* Cloning Solidity repositories" just contracts-clone @@ -231,6 +234,7 @@ e2e-lint: fi node_modules/.bin/prettier . --write +# E2E: profiles rpc sync and generates a flamegraph e2e-flamegraph: # Start PostgreSQL with Docker Compose echo "Starting PostgreSQL with Docker Compose..." @@ -252,7 +256,7 @@ e2e-flamegraph: # Run cargo flamegraph with necessary environment variables echo "Running cargo flamegraph..." - sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin rpc-server-poller -- --external-rpc=http://localhost:3003/rpc --storage={{postgres_url}} + sudo CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin rpc-server-poller -- --external-rpc=http://localhost:3003/rpc # ------------------------------------------------------------------------------ diff --git a/src/bin/rpc_server_poller.rs b/src/bin/rpc_server_poller.rs index 9d3e25c26..977cb5194 100644 --- a/src/bin/rpc_server_poller.rs +++ b/src/bin/rpc_server_poller.rs @@ -64,16 +64,24 @@ async fn main() -> anyhow::Result<()> { .import(ethers_core_block.into(), ethers_core_receipts.into_iter().map(|(k, v)| (k, v.into())).collect()) .await?; current_block_number = current_block_number.next(); - if current_block_number >= Arc::clone(&chain).get_current_block_number().await? { + let current_substrate_block = Arc::clone(&chain).get_current_block_number().await?; + if current_block_number >= current_substrate_block { tracing::info!("waiting for block number: {}", current_block_number); tokio::time::sleep(POLL_LATENCY).await; + + //XXX this is here in order for the flamegraph profiler to work, without this the loop never ends + if let Ok(_) = std::env::var("CARGO_PROFILE_RELEASE_DEBUG") { + break; + } } } + Ok(()) } async fn block_json(chain: Arc, current: BlockNumber) -> anyhow::Result { // keep trying to download until success //TODO add a backoff limit, not to give up, but to raise latency in hope of network recovery + //TODO add a sleep to avoid spamming the network loop { match timeout(POLL_LATENCY, chain.get_block_by_number(current)).await { Ok(Ok(block)) => {