From 220b54dc8f1f10f9810737c35c0104e9b5109bd4 Mon Sep 17 00:00:00 2001 From: AnkushinDaniil Date: Sat, 15 Feb 2025 22:47:57 +0300 Subject: [PATCH] Add sync profiling --- Makefile | 12 ++++++++ scripts/profile_juno.sh | 65 +++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index a542ee455e..9f4fff7556 100644 --- a/Makefile +++ b/Makefile @@ -201,3 +201,15 @@ estimate-fee-heap: juno-cached ## Heap profile estimateFee estimate-fee-block: juno-cached ## Goroutine blocking profile estimateFee ./scripts/profile_juno.sh block 60 scripts/payload/estimateFee.json sepolia-integration estimateFee_block.out ./p2p-dbs/sepolia-integration_node go tool pprof -http=:3005 estimateFee_block.out + +sync-profile: juno-cached ## Goroutine blocking profile estimateFee + ./scripts/profile_juno.sh profile 60 none sepolia sync-profile.out "" + go tool pprof -http=:3006 sync-profile.out + +sync-heap: juno-cached ## Goroutine blocking profile estimateFee + ./scripts/profile_juno.sh heap 60 none sepolia sync-heap.out "" + go tool pprof -http=:3007 sync-heap.out + +sync-block: juno-cached ## Goroutine blocking profile estimateFee + ./scripts/profile_juno.sh block 60 none sepolia sync-block.out "" + go tool pprof -http=:3008 sync-block.out diff --git a/scripts/profile_juno.sh b/scripts/profile_juno.sh index 5a29223502..1d463de14c 100755 --- a/scripts/profile_juno.sh +++ b/scripts/profile_juno.sh @@ -35,13 +35,15 @@ JUNO_ARGS="--network=$NETWORK \ --pprof-port "$PPROF_PORT" \ --disable-l1-verification" -# Ensure the request file exists -if [ ! -f "$REQUEST_FILE" ]; then +# Ensure the request file exists if not set to "none" +if [ "$REQUEST_FILE" != "none" ] && [ ! -f "$REQUEST_FILE" ]; then echo "Error: Request file '$REQUEST_FILE' not found." exit 1 fi -REQUEST_PAYLOAD=$(cat "$REQUEST_FILE") +if [ "$REQUEST_FILE" != "none" ]; then + REQUEST_PAYLOAD=$(cat "$REQUEST_FILE") +fi echo "Using profiling duration: $PROFILE_DURATION seconds" echo "Using request file: $REQUEST_FILE" @@ -50,7 +52,6 @@ echo "Using request file: $REQUEST_FILE" echo "Starting Juno..." tmux new-session -d -s juno_session "bash -c '$JUNO_BINARY $JUNO_ARGS > juno.log 2>&1'" - # 2. Wait for Juno to be ready echo "Waiting for Juno to start..." MAX_WAIT=60 @@ -58,9 +59,9 @@ WAIT_TIME=0 while ! curl --silent --fail --location 'http://localhost:6060' \ --header 'Content-Type: application/json' \ --data '{ - "jsonrpc":"2.0", - "method":"juno_version", - "id":1 + "jsonrpc":"2.0", + "method":"juno_version", + "id":1 }'; do if ! tmux has-session -t juno_session 2>/dev/null; then echo "Error: Juno crashed during startup." @@ -81,35 +82,37 @@ echo "Juno is up and running." echo "Capturing profile for $PROFILE_DURATION seconds..." curl -o $OUTPUT_FILE "http://localhost:$PPROF_PORT/debug/pprof/$PROFILE?seconds=$PROFILE_DURATION" & -# 4. Send requests and count responses -echo "Sending requests for $PROFILE_DURATION seconds..." -END_TIME=$((SECONDS + PROFILE_DURATION)) -TOTAL_REQUESTS=0 -SUCCESSFUL_REQUESTS=0 - -while [ $SECONDS -lt $END_TIME ]; do - RESPONSE=$(curl --silent --location "http://localhost:$JUNO_PORT" \ - --header "Content-Type: application/json" \ - --data "$REQUEST_PAYLOAD") - - ((TOTAL_REQUESTS++)) - - # Check if response contains a result field - if echo "$RESPONSE" | jq -e '.result' > /dev/null 2>&1; then - ((SUCCESSFUL_REQUESTS++)) - else - echo "Error in response: $RESPONSE" - fi -done +if [ "$REQUEST_FILE" != "none" ]; then + # 4. Send requests and count responses + echo "Sending requests for $PROFILE_DURATION seconds..." + END_TIME=$((SECONDS + PROFILE_DURATION)) + TOTAL_REQUESTS=0 + SUCCESSFUL_REQUESTS=0 + + while [ $SECONDS -lt $END_TIME ]; do + RESPONSE=$(curl --silent --location "http://localhost:$JUNO_PORT" \ + --header "Content-Type: application/json" \ + --data "$REQUEST_PAYLOAD") + + ((TOTAL_REQUESTS++)) + + # Check if response contains a result field + if echo "$RESPONSE" | jq -e '.result' > /dev/null 2>&1; then + ((SUCCESSFUL_REQUESTS++)) + else + echo "Error in response: $RESPONSE" + fi + done + + # Print request statistics + echo "Total requests sent: $TOTAL_REQUESTS" + echo "Successful requests: $SUCCESSFUL_REQUESTS" +fi # Wait for profiling and requests to complete wait echo "CPU profile saved to trace.out" -# Print request statistics -echo "Total requests sent: $TOTAL_REQUESTS" -echo "Successful requests: $SUCCESSFUL_REQUESTS" - # 5. Stop Juno echo "Stopping Juno..." tmux kill-session -t juno_session