summaryrefslogtreecommitdiff
path: root/internal/tools/pgo/pgo.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-07-04 15:47:38 +0300
committerPaul Buetow <paul@buetow.org>2025-07-04 15:47:38 +0300
commitf18ef1d5d194a7759ffd60537b17948f0243c624 (patch)
tree94c7aeee15220f756a97ee5b00cd7d1346464b1f /internal/tools/pgo/pgo.go
parentd37f32deb6cd6a575cc169adf1a1c1fba44e53d9 (diff)
fix: add profiling support to dtail and improve PGO workflow
- Add profiling support to dtail command (was missing) - Import profiling package - Add profile flags and profiler initialization - Add metrics logging for startup/shutdown - Fix PGO profile generation for dtail - Create growing log file simulation for realistic profiling - Add regex filtering to generate more CPU work - Handle empty profiles gracefully - Improve PGO test data generation - Add growing_log file type for dtail testing - Generate varied log levels (INFO/WARN/ERROR/DEBUG) - Increase log generation rate for better profiling Note: dtail and dserver may generate minimal CPU profiles as they are primarily I/O-bound operations. PGO is most effective for CPU-intensive operations like dgrep pattern matching and dmap data processing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/tools/pgo/pgo.go')
-rw-r--r--internal/tools/pgo/pgo.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/internal/tools/pgo/pgo.go b/internal/tools/pgo/pgo.go
index 26aa8f1..36b73ce 100644
--- a/internal/tools/pgo/pgo.go
+++ b/internal/tools/pgo/pgo.go
@@ -213,14 +213,31 @@ func runSingleWorkload(cfg *Config, command, binary string, testFiles map[string
switch command {
case "dtail":
- // Run dtail without follow mode so it exits normally
+ // For dtail, we need to simulate a growing log file
+ // First, create an empty file
+ growingLog := testFiles["growing_log"]
+ if err := os.WriteFile(growingLog, []byte{}, 0644); err != nil {
+ return fmt.Errorf("creating growing log: %w", err)
+ }
+
+ // Start a background process to write to the file with various log levels
+ writerCmd := exec.Command("bash", "-c", fmt.Sprintf(
+ "for i in {1..200}; do level=$((i %% 4)); case $level in 0) lvl=INFO;; 1) lvl=WARN;; 2) lvl=ERROR;; 3) lvl=DEBUG;; esac; echo \"[2025-07-04 15:00:00] $lvl - Test log line number $i with some additional text to process\" >> %s; sleep 0.015; done",
+ growingLog))
+ if err := writerCmd.Start(); err != nil {
+ return fmt.Errorf("starting log writer: %w", err)
+ }
+ defer writerCmd.Process.Kill()
+
+ // Run dtail to follow the growing file with regex filtering
cmd = exec.Command(binary,
"-cfg", "none",
"-plain",
"-profile",
"-profiledir", iterProfileDir,
- "-lines", "1000",
- testFiles["log"])
+ "-regex", "ERROR|WARN", // Filter for errors and warnings
+ "-shutdownAfter", "3", // Exit after 3 seconds
+ growingLog)
case "dcat":
cmd = exec.Command(binary,
@@ -488,6 +505,10 @@ func generateTestData(cfg *Config) (map[string]string, error) {
}
files["csv"] = csvFile
+ // For dtail, also create a growing log file
+ growingLogFile := filepath.Join(cfg.ProfileDir, "growing.log")
+ files["growing_log"] = growingLogFile
+
return files, nil
}