summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-26 22:40:27 +0300
committerPaul Buetow <paul@buetow.org>2025-06-26 22:40:27 +0300
commitafba86489b00a2f5ac4d39b2853c2c51c2931536 (patch)
tree934ab9c6805dbc17bf71cd4b30f827c10a58a192 /benchmarks
parent91e4743ce5ddab8f6359009bb45e243d4726bcdb (diff)
Remove bash scripts and update documentation to use dtail-tools
Following the successful refactoring to Go-based tooling, this commit: 1. Removes all obsolete bash scripts: - benchmarks/benchmark.sh - profiling/profile.sh - profiling/profile_benchmarks.sh - profiling/profile_dmap.sh - profiling/profile_quick.sh 2. Updates all documentation to use dtail-tools: - README.md: Updated benchmark commands to use dtail-tools - PROFILING.md: Updated profiling instructions to use dtail-tools 3. Updates Go code references: - profile_runner.go: Uses dtail-tools instead of profile.sh - profile_example.go: Uses dtail-tools for profile analysis The new dtail-tools provides all the functionality of the old bash scripts with better cross-platform compatibility, error handling, and maintainability. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/PROFILING.md76
-rw-r--r--benchmarks/README.md22
-rwxr-xr-xbenchmarks/benchmark.sh318
-rw-r--r--benchmarks/cmd/profile_example.go6
-rw-r--r--benchmarks/profile_runner.go23
5 files changed, 66 insertions, 379 deletions
diff --git a/benchmarks/PROFILING.md b/benchmarks/PROFILING.md
index 04ed933..7925fb3 100644
--- a/benchmarks/PROFILING.md
+++ b/benchmarks/PROFILING.md
@@ -35,23 +35,20 @@ Each command now supports profiling flags:
### 3. Analyze Profiles
-Use the included `profile.sh` script for quick analysis:
+Use dtail-tools for quick analysis:
```bash
-# Analyze CPU profile
-./profiling/profile.sh profiles/dcat_cpu_20240101_120000.prof
-
-# Show top 20 functions
-./profiling/profile.sh -top 20 profiles/dgrep_mem_20240101_120000.prof
-
-# Sort by cumulative time/allocations
-./profiling/profile.sh -cum profiles/dmap_cpu_20240101_120000.prof
-
# List all profiles
-./profiling/profile.sh -list profiles/
+./dtail-tools profile -mode list
+
+# Analyze a specific profile
+./dtail-tools profile -mode analyze profiles/dcat_cpu_20240101_120000.prof
# Open web browser with flame graph
-./profiling/profile.sh -web profiles/dcat_cpu_*.prof
+./dtail-tools profile -mode analyze profiles/dcat_cpu_*.prof -web
+
+# You can also use go tool pprof directly:
+go tool pprof profiles/dcat_cpu_20240101_120000.prof
```
## Profiling Options
@@ -84,26 +81,26 @@ All dtail commands support these profiling flags:
## Using with Benchmarks
-### Automated Profiling Script
+### Automated Profiling
-Run the included profiling script:
+Run profiling using dtail-tools:
```bash
-cd benchmarks
-./profile_benchmarks.sh
+# Quick profiling with small datasets
+./dtail-tools profile -mode quick
+
+# Full profiling suite
+./dtail-tools profile -mode full
+
+# Profile dmap specifically (with MapReduce format)
+./dtail-tools profile -mode dmap
```
-This script:
+This tool:
- Generates test data of various sizes
-- Profiles dcat and dgrep with different workloads
+- Profiles dcat, dgrep, and dmap with different workloads
- Stores profiles in the `profiles` directory
-- Provides analysis commands
-
-For dmap profiling (requires MapReduce format):
-```bash
-cd benchmarks
-./profile_dmap.sh
-```
+- Provides immediate analysis of results
### Using Make Targets
@@ -111,13 +108,20 @@ cd benchmarks
# Quick profiling with immediate results
make profile-quick
-# Profile individual commands
-make profile-dcat
-make profile-dgrep
-make profile-dmap # Uses MapReduce format
+# Full profiling suite
+make profile-all
+
+# Profile dmap specifically
+make profile-dmap
+
+# List available profiles
+make profile-list
+
+# Analyze a specific profile
+make profile-analyze PROFILE=profiles/dcat_cpu_*.prof
-# Full automated profiling
-make profile-auto
+# Open web interface for profile
+make profile-web PROFILE=profiles/dcat_cpu_*.prof
```
### Benchmark Integration
@@ -172,19 +176,19 @@ go tool pprof -svg profiles/dgrep_mem_*.prof > profile.svg
go tool pprof -text profiles/dmap_alloc_*.prof > report.txt
```
-### Using profile.sh
+### Using dtail-tools profile
-The `profile.sh` script provides quick summaries:
+The dtail-tools profile command provides quick summaries:
```bash
# List all profiles
-./profiling/profile.sh -list profiles/
+./dtail-tools profile -mode list
# Analyze specific profile
-./profiling/profile.sh profiles/dcat_cpu_20240101_120000.prof
+./dtail-tools profile -mode analyze profiles/dcat_cpu_20240101_120000.prof
# Get help
-./profiling/profile.sh -help
+./dtail-tools profile -h
```
## Optimization Workflow
diff --git a/benchmarks/README.md b/benchmarks/README.md
index dfb2627..3494086 100644
--- a/benchmarks/README.md
+++ b/benchmarks/README.md
@@ -40,13 +40,13 @@ make benchmark-baseline
make benchmark-baseline-quick
# Create a baseline with a descriptive tag (no prompt)
-./benchmarks/benchmark.sh baseline --tag "before-optimization"
+./dtail-tools benchmark -mode baseline -tag "before-optimization"
# Create a baseline interactively (will prompt if no tag provided)
-./benchmarks/benchmark.sh baseline
+make benchmark-baseline
# Create a comprehensive baseline (3x iterations)
-./benchmarks/benchmark.sh full-baseline --tag "v1.0-release"
+./dtail-tools benchmark -mode baseline -iterations 3x -tag "v1.0-release"
```
### Comparing Performance
@@ -55,10 +55,10 @@ make benchmark-baseline-quick
make benchmark-compare BASELINE=benchmarks/baselines/baseline_20240125_143022.txt
# Use the benchmark script for more options
-./benchmarks/benchmark.sh compare benchmarks/baselines/baseline_20240125_143022.txt
+./dtail-tools benchmark -mode compare -baseline benchmarks/baselines/baseline_20240125_143022.txt
# List available baselines
-./benchmarks/benchmark.sh list
+./dtail-tools benchmark -mode list
```
### Specific Tool Benchmarks
@@ -183,10 +183,10 @@ make benchmark-baseline-quick
> Enter a descriptive name for this baseline: initial-performance-check
# Tagged baseline with description (no prompt)
-./benchmarks/benchmark.sh baseline --tag "before-refactoring"
+./dtail-tools benchmark -mode baseline -tag "before-refactoring"
# Full baseline with multiple iterations
-./benchmarks/benchmark.sh full-baseline --memory --tag "release-v2.0"
+./dtail-tools benchmark -mode baseline -iterations 3x -memory -tag "release-v2.0"
```
Baseline files are named with the pattern:
@@ -200,19 +200,19 @@ Compare current performance against a baseline to detect regressions or improvem
make benchmark-compare BASELINE=benchmarks/baselines/baseline_20240125_143022.txt
# Using benchmark script (provides benchstat analysis if available)
-./benchmarks/benchmark.sh compare benchmarks/baselines/baseline_20240125_143022.txt
+./dtail-tools benchmark -mode compare -baseline benchmarks/baselines/baseline_20240125_143022.txt
```
### Managing Baselines
```bash
# List all baselines
-./benchmarks/benchmark.sh list
+./dtail-tools benchmark -mode list
# View a specific baseline
-./benchmarks/benchmark.sh show benchmarks/baselines/baseline_20240125_143022.txt
+cat benchmarks/baselines/baseline_20240125_143022.txt
# Clean old baselines (keeps last 10)
-./benchmarks/benchmark.sh clean
+./dtail-tools benchmark -mode clean
```
### Best Practices for Baselines
diff --git a/benchmarks/benchmark.sh b/benchmarks/benchmark.sh
deleted file mode 100755
index 1b4a71f..0000000
--- a/benchmarks/benchmark.sh
+++ /dev/null
@@ -1,318 +0,0 @@
-#!/bin/bash
-# Benchmark management script for DTail
-
-set -e
-
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-BASELINES_DIR="${SCRIPT_DIR}/baselines"
-TIMESTAMP=$(date +%Y%m%d_%H%M%S)
-
-# Colors for output
-RED='\033[0;31m'
-GREEN='\033[0;32m'
-YELLOW='\033[1;33m'
-NC='\033[0m' # No Color
-
-# Function to print usage
-usage() {
- cat << EOF
-DTail Benchmark Management Tool
-
-Usage: $0 [command] [options]
-
-Commands:
- baseline Create a new baseline snapshot
- compare [baseline] Compare current performance against a baseline
- list List available baselines
- show [baseline] Display a baseline file
- clean Remove old baselines (keeps last 10)
- full-baseline Create a comprehensive baseline (all benchmarks, 3x iterations)
-
-Options:
- -o, --output FILE Save benchmark output to custom file
- -t, --tag TAG Add a descriptive tag to baseline filename
- -q, --quick Run quick benchmarks only
- -m, --memory Include memory profiling
- -c, --cpu-profile Generate CPU profile
- -v, --verbose Show detailed output
-
-Examples:
- # Create a baseline before optimization
- $0 baseline --tag "before-optimization"
-
- # Compare current performance with baseline
- $0 compare benchmarks/baselines/baseline_20240125_143022_before-optimization.txt
-
- # Create full baseline with memory stats
- $0 full-baseline --memory --tag "v1.0-release"
-
-EOF
-}
-
-# Function to ensure baselines directory exists
-ensure_baselines_dir() {
- mkdir -p "$BASELINES_DIR"
-}
-
-# Function to create baseline
-create_baseline() {
- local tag=""
- local bench_args="-bench=."
- local output_file=""
- local memory_profile=""
-
- # Parse arguments
- while [[ $# -gt 0 ]]; do
- case $1 in
- -t|--tag)
- tag="_$2"
- shift 2
- ;;
- -q|--quick)
- bench_args="-bench=BenchmarkQuick"
- shift
- ;;
- -m|--memory)
- memory_profile="-benchmem"
- shift
- ;;
- -o|--output)
- output_file="$2"
- shift 2
- ;;
- *)
- shift
- ;;
- esac
- done
-
- # If no tag provided, ask for one
- if [ -z "$tag" ]; then
- echo -e "${YELLOW}Creating benchmark baseline...${NC}"
- read -p "Enter a descriptive name for this baseline (e.g. 'before-optimization', 'v1.0-release'): " tag_input
- if [ -z "$tag_input" ]; then
- echo -e "${RED}Error: Baseline name cannot be empty${NC}"
- exit 1
- fi
- # Clean the tag input
- tag="_$(echo "$tag_input" | tr ' ' '_' | tr -cd '[:alnum:]._-')"
- fi
-
- ensure_baselines_dir
-
- if [ -z "$output_file" ]; then
- output_file="${BASELINES_DIR}/baseline_${TIMESTAMP}${tag}.txt"
- fi
-
- echo -e "${GREEN}Creating baseline: ${output_file}${NC}"
- echo "Git commit: $(git rev-parse --short HEAD)" > "$output_file"
- echo "Date: $(date)" >> "$output_file"
- echo "Tag: ${tag#_}" >> "$output_file"
- echo "----------------------------------------" >> "$output_file"
-
- cd "$SCRIPT_DIR/.."
- make build
- go test $bench_args $memory_profile ./benchmarks -count=1 | tee -a "$output_file"
-
- echo -e "${GREEN}Baseline created: ${output_file}${NC}"
-}
-
-# Function to create full baseline
-create_full_baseline() {
- local tag=""
- local memory_profile=""
-
- # Parse arguments
- while [[ $# -gt 0 ]]; do
- case $1 in
- -t|--tag)
- tag="_$2"
- shift 2
- ;;
- -m|--memory)
- memory_profile="-benchmem"
- shift
- ;;
- *)
- shift
- ;;
- esac
- done
-
- # If no tag provided, ask for one
- if [ -z "$tag" ]; then
- echo -e "${YELLOW}Creating comprehensive benchmark baseline...${NC}"
- read -p "Enter a descriptive name for this baseline (e.g. 'before-optimization', 'v1.0-release'): " tag_input
- if [ -z "$tag_input" ]; then
- echo -e "${RED}Error: Baseline name cannot be empty${NC}"
- exit 1
- fi
- # Clean the tag input
- tag="_$(echo "$tag_input" | tr ' ' '_' | tr -cd '[:alnum:]._-')"
- fi
-
- ensure_baselines_dir
-
- local output_file="${BASELINES_DIR}/baseline_${TIMESTAMP}${tag}_full.txt"
-
- echo -e "${GREEN}Creating comprehensive baseline: ${output_file}${NC}"
- echo "Git commit: $(git rev-parse --short HEAD)" > "$output_file"
- echo "Date: $(date)" >> "$output_file"
- echo "Tag: ${tag#_} (full)" >> "$output_file"
- echo "----------------------------------------" >> "$output_file"
-
- cd "$SCRIPT_DIR/.."
- make build
-
- # Run with multiple iterations for stability
- go test -bench=. $memory_profile -benchtime=3x ./benchmarks -count=1 | tee -a "$output_file"
-
- echo -e "${GREEN}Full baseline created: ${output_file}${NC}"
-}
-
-# Function to compare with baseline
-compare_baseline() {
- local baseline_file="$1"
-
- if [ -z "$baseline_file" ]; then
- echo -e "${RED}Error: No baseline file specified${NC}"
- echo "Available baselines:"
- list_baselines
- exit 1
- fi
-
- if [ ! -f "$baseline_file" ]; then
- echo -e "${RED}Error: Baseline file not found: $baseline_file${NC}"
- exit 1
- fi
-
- ensure_baselines_dir
- local current_file="${BASELINES_DIR}/current_${TIMESTAMP}.txt"
-
- echo -e "${YELLOW}Running current benchmarks...${NC}"
- echo "Git commit: $(git rev-parse --short HEAD)" > "$current_file"
- echo "Date: $(date)" >> "$current_file"
- echo "----------------------------------------" >> "$current_file"
-
- cd "$SCRIPT_DIR/.."
- make build
- go test -bench=. -benchmem ./benchmarks -count=1 | tee -a "$current_file"
-
- echo -e "\n${YELLOW}=== Performance Comparison ===${NC}"
-
- # Use benchstat if available
- if command -v benchstat >/dev/null 2>&1; then
- benchstat "$baseline_file" "$current_file"
- else
- echo -e "${YELLOW}benchstat not found. Install with:${NC}"
- echo " go install golang.org/x/perf/cmd/benchstat@latest"
- echo -e "\n${YELLOW}Showing simple comparison:${NC}"
-
- # Extract benchmark results for comparison
- echo -e "\nBaseline ($(basename "$baseline_file")):"
- grep "^Benchmark" "$baseline_file" | head -10
-
- echo -e "\nCurrent:"
- grep "^Benchmark" "$current_file" | head -10
- fi
-
- # Save comparison report
- local report_file="${BASELINES_DIR}/comparison_${TIMESTAMP}.txt"
- {
- echo "Comparison Report"
- echo "================"
- echo "Baseline: $baseline_file"
- echo "Current: $current_file"
- echo "Date: $(date)"
- echo ""
- if command -v benchstat >/dev/null 2>&1; then
- benchstat "$baseline_file" "$current_file"
- else
- diff -u "$baseline_file" "$current_file" || true
- fi
- } > "$report_file"
-
- echo -e "\n${GREEN}Comparison report saved: $report_file${NC}"
-}
-
-# Function to list baselines
-list_baselines() {
- ensure_baselines_dir
-
- echo -e "${YELLOW}Available baselines:${NC}"
- if [ -d "$BASELINES_DIR" ]; then
- ls -la "$BASELINES_DIR"/*.txt 2>/dev/null | awk '{print $9, $6, $7, $8}' | column -t || echo "No baselines found"
- else
- echo "No baselines found"
- fi
-}
-
-# Function to show baseline content
-show_baseline() {
- local baseline_file="$1"
-
- if [ -z "$baseline_file" ]; then
- echo -e "${RED}Error: No baseline file specified${NC}"
- list_baselines
- exit 1
- fi
-
- if [ ! -f "$baseline_file" ]; then
- echo -e "${RED}Error: Baseline file not found: $baseline_file${NC}"
- exit 1
- fi
-
- less "$baseline_file"
-}
-
-# Function to clean old baselines
-clean_baselines() {
- ensure_baselines_dir
-
- echo -e "${YELLOW}Cleaning old baselines (keeping last 10)...${NC}"
-
- # Count files
- local file_count=$(ls -1 "$BASELINES_DIR"/*.txt 2>/dev/null | wc -l)
-
- if [ "$file_count" -gt 10 ]; then
- # Remove oldest files, keeping last 10
- ls -t "$BASELINES_DIR"/*.txt | tail -n +11 | xargs rm -v
- echo -e "${GREEN}Cleanup complete${NC}"
- else
- echo "No cleanup needed (only $file_count baselines found)"
- fi
-}
-
-# Main command handling
-case "${1:-}" in
- baseline)
- shift
- create_baseline "$@"
- ;;
- full-baseline)
- shift
- create_full_baseline "$@"
- ;;
- compare)
- shift
- compare_baseline "$@"
- ;;
- list)
- list_baselines
- ;;
- show)
- shift
- show_baseline "$@"
- ;;
- clean)
- clean_baselines
- ;;
- -h|--help|help)
- usage
- ;;
- *)
- echo -e "${RED}Error: Unknown command '${1:-}'${NC}"
- usage
- exit 1
- ;;
-esac \ No newline at end of file
diff --git a/benchmarks/cmd/profile_example.go b/benchmarks/cmd/profile_example.go
index f996565..01d4a66 100644
--- a/benchmarks/cmd/profile_example.go
+++ b/benchmarks/cmd/profile_example.go
@@ -219,9 +219,9 @@ func analyzeProfiles() {
fmt.Printf("\nAnalyzing %s CPU profile:\n", tool)
- // Run profile.sh
- cmd := exec.Command("../profiling/profile.sh",
- "-top", "5",
+ // Run dtail-tools profile analyze
+ cmd := exec.Command("../dtail-tools",
+ "profile", "-mode", "analyze",
latestProfile)
output, err := cmd.CombinedOutput()
diff --git a/benchmarks/profile_runner.go b/benchmarks/profile_runner.go
index 2da122b..e7934dd 100644
--- a/benchmarks/profile_runner.go
+++ b/benchmarks/profile_runner.go
@@ -157,34 +157,35 @@ func ProfileBenchmark(b *testing.B, name string, tool string, args ...string) {
b.Logf("Allocation profile: %s", result.AllocProfile)
}
- // Analyze profiles if profile.sh is available
- dprofilePath := filepath.Join("..", "profiling", "profile.sh")
- if _, err := os.Stat(dprofilePath); err == nil {
+ // Analyze profiles using dtail-tools
+ dtailToolsPath := filepath.Join("..", "dtail-tools")
+ if _, err := os.Stat(dtailToolsPath); err == nil {
if result.CPUProfile != "" {
- analyzeProfile(b, dprofilePath, result.CPUProfile, "CPU")
+ analyzeProfileWithTools(b, dtailToolsPath, result.CPUProfile, "CPU")
}
if result.MemProfile != "" {
- analyzeProfile(b, dprofilePath, result.MemProfile, "Memory")
+ analyzeProfileWithTools(b, dtailToolsPath, result.MemProfile, "Memory")
}
}
})
}
-// analyzeProfile runs profile.sh on a profile file
-func analyzeProfile(b *testing.B, dprofilePath, profilePath, profileType string) {
+// analyzeProfileWithTools runs dtail-tools profile analyze on a profile file
+func analyzeProfileWithTools(b *testing.B, dtailToolsPath, profilePath, profileType string) {
b.Logf("\n%s Profile Analysis:", profileType)
- cmd := exec.Command(dprofilePath, "-top", "5", profilePath)
+ cmd := exec.Command(dtailToolsPath, "profile", "-mode", "analyze", profilePath)
output, err := cmd.CombinedOutput()
if err != nil {
b.Logf("Failed to analyze profile: %v", err)
return
}
- // Print top functions
+ // Print analysis output
lines := strings.Split(string(output), "\n")
- for _, line := range lines {
- if strings.Contains(line, "%") || strings.Contains(line, "Top") {
+ // Print first 10 lines of analysis
+ for i, line := range lines {
+ if i < 10 && line != "" {
b.Log(line)
}
}