summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-16 19:13:31 +0300
committerPaul Buetow <paul@buetow.org>2025-06-16 19:13:31 +0300
commita3c29db4df8650b5c6d9ae987c23d88ab606dd45 (patch)
tree290f4ea5db92ce50288170d3b2e09c9b50476cea
parent754ac4bb68f9e145df07dd3c54a43f37654a5d50 (diff)
Organize PBO files in scripts directory and add .gitignore entries
- Modify pbo.sh to store all temporary files in scripts/ directory - Update path handling with proper SCRIPT_DIR and PROJECT_ROOT variables - Add comprehensive .gitignore entries for PBO temporary files: - scripts/pbo_*.prof (CPU and memory profiles) - scripts/pbo_report.txt (analysis report) - scripts/test_100mb.txt (test data file) - Update CLAUDE.md documentation to reflect new file organization - Keep project root directory clean by organizing all PBO artifacts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
-rw-r--r--.gitignore5
-rw-r--r--CLAUDE.md8
-rwxr-xr-xscripts/pbo.sh81
3 files changed, 62 insertions, 32 deletions
diff --git a/.gitignore b/.gitignore
index 44dc08e..89c6501 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,8 @@ known_hosts
id_rsa
id_rsa.pub
ssh_host_key
+
+# PBO (Profile-Based Optimization) temporary files
+scripts/pbo_*.prof
+scripts/pbo_report.txt
+scripts/test_100mb.txt
diff --git a/CLAUDE.md b/CLAUDE.md
index c48aa35..753b3bf 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -48,12 +48,14 @@ make lint
make pbo
# This target will:
-# - Create test file (100MB with 1M lines) if needed
+# - Create test file (100MB with 1M lines) in scripts/ if needed
# - Run baseline profiling (CPU and memory)
# - Run performance benchmarks
-# - Generate optimized profiles
-# - Create detailed comparison report (pbo_report.txt)
+# - Generate optimized profiles in scripts/ directory
+# - Create detailed comparison report (scripts/pbo_report.txt)
# - Show key optimizations implemented
+#
+# All PBO files are organized in scripts/ directory to keep project root clean
```
### Installation
diff --git a/scripts/pbo.sh b/scripts/pbo.sh
index 65eb6f2..909d28a 100755
--- a/scripts/pbo.sh
+++ b/scripts/pbo.sh
@@ -6,34 +6,53 @@
set -e
+# Get the directory where this script is located
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+# Get the project root directory (parent of scripts)
+PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
+
+# Change to project root to run commands
+cd "$PROJECT_ROOT"
+
+# Define paths for all PBO files in scripts directory
+PBO_DIR="$SCRIPT_DIR"
+TEST_FILE="$PBO_DIR/test_100mb.txt"
+BASELINE_CPU_PROF="$PBO_DIR/pbo_baseline_cpu.prof"
+BASELINE_MEM_PROF="$PBO_DIR/pbo_baseline_mem.prof"
+OPTIMIZED_CPU_PROF="$PBO_DIR/pbo_optimized_cpu.prof"
+OPTIMIZED_MEM_PROF="$PBO_DIR/pbo_optimized_mem.prof"
+REPORT_FILE="$PBO_DIR/pbo_report.txt"
+
echo "=== Starting Profile-Based Optimization (PBO) for dgrep ==="
+echo "Working directory: $PROJECT_ROOT"
+echo "PBO files location: $PBO_DIR"
# 1. Create test file if needed
echo "1. Creating test file if needed..."
-if [ ! -f test_100mb.txt ]; then
+if [ ! -f "$TEST_FILE" ]; then
echo "Creating 100MB test file with 1M lines..."
for i in $(seq 1 1000000); do
echo "$i: This is a test line with INFO level logging and some extra content to make it realistic"
- done > test_100mb.txt
+ done > "$TEST_FILE"
fi
# 2. Run baseline performance test (assumes current state is baseline)
echo "2. Running baseline performance test..."
echo " - Generating CPU profile (baseline)..."
-./dgrep --plain -regex "INFO" -files test_100mb.txt -cpuprofile pbo_baseline_cpu.prof -memprofile pbo_baseline_mem.prof > /dev/null
+./dgrep --plain -regex "INFO" -files "$TEST_FILE" -cpuprofile "$BASELINE_CPU_PROF" -memprofile "$BASELINE_MEM_PROF" > /dev/null
echo " - Analyzing baseline profiles..."
-echo " CPU Profile (baseline):" > pbo_report.txt
-go tool pprof -top pbo_baseline_cpu.prof | head -10 >> pbo_report.txt
-echo " Memory Profile (baseline):" >> pbo_report.txt
-go tool pprof -top pbo_baseline_mem.prof | head -10 >> pbo_report.txt
+echo " CPU Profile (baseline):" > "$REPORT_FILE"
+go tool pprof -top "$BASELINE_CPU_PROF" | head -10 >> "$REPORT_FILE"
+echo " Memory Profile (baseline):" >> "$REPORT_FILE"
+go tool pprof -top "$BASELINE_MEM_PROF" | head -10 >> "$REPORT_FILE"
# 3. Run performance benchmark
echo "3. Running performance benchmark (3 iterations)..."
-echo " Baseline timings:" >> pbo_report.txt
+echo " Baseline timings:" >> "$REPORT_FILE"
for i in 1 2 3; do
echo " Iteration $i:"
- (time ./dgrep --plain -regex "INFO" -files test_100mb.txt > /dev/null) 2>&1 | grep real >> pbo_report.txt
+ (time ./dgrep --plain -regex "INFO" -files "$TEST_FILE" > /dev/null) 2>&1 | grep real >> "$REPORT_FILE"
done
# 4. Note optimizations (already implemented in code)
@@ -45,40 +64,44 @@ echo " - Memory allocation improvements (buffer pooling)"
# 5. Run optimized performance test
echo "5. Running optimized performance test..."
echo " - Generating CPU profile (optimized)..."
-./dgrep --plain -regex "INFO" -files test_100mb.txt -cpuprofile pbo_optimized_cpu.prof -memprofile pbo_optimized_mem.prof > /dev/null
+./dgrep --plain -regex "INFO" -files "$TEST_FILE" -cpuprofile "$OPTIMIZED_CPU_PROF" -memprofile "$OPTIMIZED_MEM_PROF" > /dev/null
echo " - Analyzing optimized profiles..."
-echo " CPU Profile (optimized):" >> pbo_report.txt
-go tool pprof -top pbo_optimized_cpu.prof | head -10 >> pbo_report.txt
-echo " Memory Profile (optimized):" >> pbo_report.txt
-go tool pprof -top pbo_optimized_mem.prof | head -10 >> pbo_report.txt
+echo " CPU Profile (optimized):" >> "$REPORT_FILE"
+go tool pprof -top "$OPTIMIZED_CPU_PROF" | head -10 >> "$REPORT_FILE"
+echo " Memory Profile (optimized):" >> "$REPORT_FILE"
+go tool pprof -top "$OPTIMIZED_MEM_PROF" | head -10 >> "$REPORT_FILE"
# 6. Run optimized benchmark
echo "6. Running optimized benchmark (3 iterations)..."
-echo " Optimized timings:" >> pbo_report.txt
+echo " Optimized timings:" >> "$REPORT_FILE"
for i in 1 2 3; do
echo " Iteration $i:"
- (time ./dgrep --plain -regex "INFO" -files test_100mb.txt > /dev/null) 2>&1 | grep real >> pbo_report.txt
+ (time ./dgrep --plain -regex "INFO" -files "$TEST_FILE" > /dev/null) 2>&1 | grep real >> "$REPORT_FILE"
done
# 7. Generate comparison report
echo "7. Generating comparison report..."
-echo "=== PROFILE-BASED OPTIMIZATION REPORT ===" >> pbo_report.txt
-echo "Baseline memory usage:" >> pbo_report.txt
-go tool pprof -top pbo_baseline_mem.prof | grep "Showing nodes" >> pbo_report.txt || echo "N/A" >> pbo_report.txt
-echo "Optimized memory usage:" >> pbo_report.txt
-go tool pprof -top pbo_optimized_mem.prof | grep "Showing nodes" >> pbo_report.txt || echo "N/A" >> pbo_report.txt
-echo "Baseline CPU samples:" >> pbo_report.txt
-go tool pprof -top pbo_baseline_cpu.prof | grep "Total samples" >> pbo_report.txt || echo "N/A" >> pbo_report.txt
-echo "Optimized CPU samples:" >> pbo_report.txt
-go tool pprof -top pbo_optimized_cpu.prof | grep "Total samples" >> pbo_report.txt || echo "N/A" >> pbo_report.txt
+echo "=== PROFILE-BASED OPTIMIZATION REPORT ===" >> "$REPORT_FILE"
+echo "Baseline memory usage:" >> "$REPORT_FILE"
+go tool pprof -top "$BASELINE_MEM_PROF" | grep "Showing nodes" >> "$REPORT_FILE" || echo "N/A" >> "$REPORT_FILE"
+echo "Optimized memory usage:" >> "$REPORT_FILE"
+go tool pprof -top "$OPTIMIZED_MEM_PROF" | grep "Showing nodes" >> "$REPORT_FILE" || echo "N/A" >> "$REPORT_FILE"
+echo "Baseline CPU samples:" >> "$REPORT_FILE"
+go tool pprof -top "$BASELINE_CPU_PROF" | grep "Total samples" >> "$REPORT_FILE" || echo "N/A" >> "$REPORT_FILE"
+echo "Optimized CPU samples:" >> "$REPORT_FILE"
+go tool pprof -top "$OPTIMIZED_CPU_PROF" | grep "Total samples" >> "$REPORT_FILE" || echo "N/A" >> "$REPORT_FILE"
# 8. Summary
echo "=== PBO Complete! ==="
-echo "Results saved to: pbo_report.txt"
+echo "Results saved to: $REPORT_FILE"
echo "Profile files generated:"
-echo " - pbo_baseline_cpu.prof, pbo_baseline_mem.prof"
-echo " - pbo_optimized_cpu.prof, pbo_optimized_mem.prof"
+echo " - $BASELINE_CPU_PROF"
+echo " - $BASELINE_MEM_PROF"
+echo " - $OPTIMIZED_CPU_PROF"
+echo " - $OPTIMIZED_MEM_PROF"
+echo ""
+echo "Test file location: $TEST_FILE"
echo ""
echo "Key improvements implemented:"
echo " ✓ Timer allocation reduction (eliminated time.After() calls)"
@@ -87,4 +110,4 @@ echo " ✓ Memory allocation improvements (buffer pooling, pre-allocation)"
echo ""
# Show summary from report
-tail -20 pbo_report.txt \ No newline at end of file
+tail -20 "$REPORT_FILE" \ No newline at end of file