agent/claude/perf/scripts/perf-request.sh
Snider c1ef2841d3
feat: /core:perf performance profiling helpers (#94)
This commit introduces a new `/core:perf` command with subcommands to profile performance for Go and PHP projects.

Implemented subcommands:
- `/core:perf test`: Profiles the test suite for Go and PHP projects, identifying slow tests and providing actionable suggestions.
- `/core:perf request <url>`: Profiles HTTP requests and provides suggestions for optimization.
- `/core:perf query <query>`: Analyzes slow database queries for MySQL, providing suggestions for indexing.
- `/core:perf memory [script_path]`: Analyzes memory usage for Go and PHP projects.

Changes made:
- Created a new `perf` plugin with the necessary directory structure and metadata.
- Registered the plugin in the marketplace.
- Implemented the `/core:perf` command and its subcommands.
- Added scripts for each subcommand with logic for both Go and PHP.
- Improved the scripts based on code review feedback, including:
    - Fixing incorrect Xdebug usage in the PHP test profiler.
    - Improving the PHP memory profiler with Xdebug.
    - Adding dependency checks for `xmlstarlet` and `bc`.
    - Improving error handling and dependency messages.
    - Adding cleanup for temporary files.
    - Documenting the MySQL dependency.
2026-02-02 07:24:35 +00:00

53 lines
1.7 KiB
Bash

#!/bin/bash
set -e
if [ -z "$1" ]; then
echo "Usage: $0 <url>"
exit 1
fi
URL=$1
echo "Profiling request to: $URL"
OUTPUT=$(curl -w "time_namelookup=%{time_namelookup}\ntime_connect=%{time_connect}\ntime_appconnect=%{time_appconnect}\ntime_pretransfer=%{time_pretransfer}\ntime_redirect=%{time_redirect}\ntime_starttransfer=%{time_starttransfer}\ntime_total=%{time_total}" -o /dev/null -s "$URL")
# Extract values
get_value() {
echo "$OUTPUT" | grep "$1" | cut -d'=' -f2
}
TIME_NAMELOOKUP=$(get_value time_namelookup)
TIME_CONNECT=$(get_value time_connect)
TIME_STARTTRANSFER=$(get_value time_starttransfer)
echo "--- Timing Metrics ---"
echo "DNS Lookup: ${TIME_NAMELOOKUP}s"
echo "Connect: ${TIME_CONNECT}s"
echo "Start Transfer: ${TIME_STARTTRANSFER}s"
echo "----------------------"
SUGGESTIONS=""
# Suggestion 1: High DNS lookup time
if (( $(echo "$TIME_NAMELOOKUP > 0.1" | bc -l) )); then
SUGGESTIONS+=" - DNS lookup took over 100ms. Consider using a faster DNS provider or checking your network configuration.\n"
fi
# Suggestion 2: High connect time
if (( $(echo "$TIME_CONNECT > 0.2" | bc -l) )); then
SUGGESTIONS+=" - Connection time is over 200ms. If this is a remote server, consider using a CDN. If it's local, check for network latency or server load.\n"
fi
# Suggestion 3: High start transfer time (Time To First Byte)
if (( $(echo "$TIME_STARTTRANSFER > 0.5" | bc -l) )); then
SUGGESTIONS+=" - Time To First Byte (TTFB) is over 500ms. This indicates a slow backend. Profile your application code to identify and optimize bottlenecks.\n"
fi
if [ -z "$SUGGESTIONS" ]; then
echo "No obvious performance issues found."
else
echo "Actionable Suggestions:"
echo -e "$SUGGESTIONS"
fi