summaryrefslogtreecommitdiff
path: root/cmd
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 /cmd
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 'cmd')
-rw-r--r--cmd/dtail/main.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go
index e18923a..3d363cb 100644
--- a/cmd/dtail/main.go
+++ b/cmd/dtail/main.go
@@ -17,6 +17,7 @@ import (
"github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
"github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/profiling"
"github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -32,6 +33,7 @@ func main() {
var grep string
var pprof string
var shutdownAfter int
+ var profileFlags profiling.Flags
userName := user.Name()
@@ -65,6 +67,9 @@ func main() {
flag.StringVar(&args.What, "files", "", "File(s) to read")
flag.StringVar(&grep, "grep", "", "Alias for -regex")
flag.StringVar(&pprof, "pprof", "", "Start PProf server this address")
+
+ // Add profiling flags
+ profiling.AddFlags(&profileFlags)
flag.Parse()
if grep != "" {
@@ -94,6 +99,10 @@ func main() {
wg.Add(1)
dlog.Start(ctx, &wg, source.Client)
+ // Set up profiling
+ profiler := profiling.NewProfiler(profileFlags.ToConfig("dtail"))
+ defer profiler.Stop()
+
if checkHealth {
fmt.Println("WARN: DTail health check has moved to separate binary dtailhealth" +
" - please adjust the monitoring scripts!")
@@ -108,6 +117,11 @@ func main() {
}()
}
+ // Log initial metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("startup")
+ }
+
var client clients.Client
var err error
args.Mode = omode.TailClient
@@ -124,6 +138,12 @@ func main() {
}
status := client.Start(ctx, signal.InterruptCh(ctx))
+
+ // Log final metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("shutdown")
+ }
+
cancel()
wg.Wait()