diff --git a/build_static.sh b/build_static.sh index 5656ad4..5d1a326 100755 --- a/build_static.sh +++ b/build_static.sh @@ -77,6 +77,11 @@ case "$ARCH" in ;; esac +# Append _debug suffix to output name for debug builds so production binary is never overwritten +if [ "$DEBUG_BUILD" = true ]; then + OUTPUT_NAME="${OUTPUT_NAME}_debug" +fi + echo "Building for platform: $PLATFORM" echo "Output binary: $OUTPUT_NAME" echo "" diff --git a/deploy_lt_debug.sh b/deploy_lt_debug.sh new file mode 100755 index 0000000..158295b --- /dev/null +++ b/deploy_lt_debug.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# C-Relay Debug Binary Deployment Script +# Deploys build/c_relay_static_x86_64_debug to server for CPU profiling +# +# Usage: +# ./deploy_lt_debug.sh -- deploy debug binary and restart +# ./deploy_lt_debug.sh --profile -- deploy, then run perf and fetch results +# +# After deploying, profile with: +# sudo perf record -g -p $(pgrep c_relay) -- sleep 30 +# sudo perf report --stdio --sort=symbol --no-children -n 2>/dev/null | head -80 +# +# Restore production binary: +# ./deploy_lt.sh + +set -e + +LOCAL_DEBUG_BINARY="build/c_relay_static_x86_64_debug" +REMOTE_BINARY_PATH="/usr/local/bin/c_relay/c_relay" +REMOTE_PROD_BACKUP="/usr/local/bin/c_relay/c_relay.production" +SERVICE_NAME="c-relay" +REMOTE_HOST="ubuntu@laantungir.com" + +# Check debug binary exists +if [ ! -f "$LOCAL_DEBUG_BINARY" ]; then + echo "ERROR: Debug binary not found: $LOCAL_DEBUG_BINARY" + echo "" + echo "Build it first with:" + echo " ./build_static.sh --debug" + echo "" + exit 1 +fi + +echo "==========================================" +echo "C-Relay Debug Deployment" +echo "==========================================" +echo "Binary: $LOCAL_DEBUG_BINARY ($(du -h "$LOCAL_DEBUG_BINARY" | cut -f1))" +echo "Target: $REMOTE_HOST:$REMOTE_BINARY_PATH" +echo "" +echo "WARNING: Debug binary has symbols and is larger than production." +echo " It is safe to run but should not be left deployed long-term." +echo "" + +# Backup production binary (only if not already backed up) +echo "Backing up production binary..." +ssh "$REMOTE_HOST" " + if [ ! -f '$REMOTE_PROD_BACKUP' ]; then + sudo cp '$REMOTE_BINARY_PATH' '$REMOTE_PROD_BACKUP' + echo 'Production binary backed up to $REMOTE_PROD_BACKUP' + else + echo 'Production backup already exists, skipping' + fi +" + +# Upload debug binary +echo "Uploading debug binary..." +scp "$LOCAL_DEBUG_BINARY" "$REMOTE_HOST:/tmp/c_relay_debug.tmp" + +# Install debug binary +echo "Installing debug binary..." +ssh "$REMOTE_HOST" " + sudo mv '/tmp/c_relay_debug.tmp' '$REMOTE_BINARY_PATH' + sudo chown c-relay:c-relay '$REMOTE_BINARY_PATH' + sudo chmod +x '$REMOTE_BINARY_PATH' +" + +# Restart service +echo "Restarting c-relay service..." +ssh "$REMOTE_HOST" "sudo systemctl daemon-reload && sudo systemctl restart '$SERVICE_NAME'" + +echo "" +echo "✓ Debug binary deployed and service restarted" +echo "" + +# If --profile flag, run perf automatically +if [ "$1" = "--profile" ]; then + echo "==========================================" + echo "Running perf profile (30 seconds)..." + echo "==========================================" + echo "" + + # Wait for relay to start + sleep 3 + + ssh "$REMOTE_HOST" " + PID=\$(pgrep c_relay) + if [ -z \"\$PID\" ]; then + echo 'ERROR: c_relay not running' + exit 1 + fi + echo \"Profiling PID \$PID for 30 seconds...\" + sudo perf record -g -p \$PID -- sleep 30 + echo '' + echo '=== TOP FUNCTIONS BY CPU ===' + sudo perf report --stdio --sort=symbol --no-children -n 2>/dev/null | head -60 + " +else + echo "==========================================" + echo "Next Steps: Profile the relay" + echo "==========================================" + echo "" + echo "SSH to server and run:" + echo " sudo perf record -g -p \$(pgrep c_relay) -- sleep 30" + echo " sudo perf report --stdio --sort=symbol --no-children -n 2>/dev/null | head -60" + echo "" + echo "Or run with --profile to do it automatically:" + echo " ./deploy_lt_debug.sh --profile" +fi + +echo "" +echo "==========================================" +echo "Restore Production Binary When Done" +echo "==========================================" +echo "" +echo "Run this to restore the production binary:" +echo " ./deploy_lt.sh" +echo "" +echo "Or manually on the server:" +echo " sudo cp '$REMOTE_PROD_BACKUP' '$REMOTE_BINARY_PATH'" +echo " sudo systemctl restart $SERVICE_NAME" +echo "" diff --git a/src/main.h b/src/main.h index 475b8e0..4355b3b 100644 --- a/src/main.h +++ b/src/main.h @@ -13,8 +13,8 @@ // Using CRELAY_ prefix to avoid conflicts with nostr_core_lib VERSION macros #define CRELAY_VERSION_MAJOR 1 #define CRELAY_VERSION_MINOR 2 -#define CRELAY_VERSION_PATCH 7 -#define CRELAY_VERSION "v1.2.7" +#define CRELAY_VERSION_PATCH 8 +#define CRELAY_VERSION "v1.2.8" // Relay metadata (authoritative source for NIP-11 information) #define RELAY_NAME "C-Relay"