summaryrefslogtreecommitdiff
path: root/cmd/dgrep
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-26 13:49:38 +0300
committerPaul Buetow <paul@buetow.org>2025-06-26 13:49:38 +0300
commit6664996ced62c77e0c62bc1619662cbed7fccff6 (patch)
treeb995d8aa34aa68ec8f97c4be417ac96e6c6abf48 /cmd/dgrep
parent72828b8c5f575cfc7c7c27c5a5d3b7fd9225b625 (diff)
feat: add profiling framework with command echoing
Created a comprehensive profiling framework for dtail commands (dcat, dgrep, dmap) to analyze CPU usage and memory allocations. The framework now prints all executed commands to stdout for full transparency. Key features: - Integrated Go profiling (CPU, memory, allocations) into all three commands - Created profile.sh bash script for analyzing pprof profiles - Added multiple Makefile targets for different profiling scenarios - Automated profiling scripts with command echoing - Support for different data sizes (quick, normal, full) - Special handling for dmap MapReduce format All profiling commands are now echoed to stdout before execution, making it easy to understand what the framework is doing and reproduce commands manually. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'cmd/dgrep')
-rw-r--r--cmd/dgrep/main.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 19f818b..14cfb0c 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -14,6 +14,7 @@ import (
"github.com/mimecast/dtail/internal/config"
"github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
+ "github.com/mimecast/dtail/internal/profiling"
"github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
@@ -25,6 +26,7 @@ func main() {
var displayVersion bool
var grep string
var pprof string
+ var profileFlags profiling.Flags
userName := user.Name()
flag.BoolVar(&args.NoColor, "noColor", false, "Disable ANSII terminal colors")
@@ -51,6 +53,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()
config.Setup(source.Client, &args, flag.Args())
@@ -64,6 +69,10 @@ func main() {
wg.Add(1)
dlog.Start(ctx, &wg, source.Client)
+ // Set up profiling
+ profiler := profiling.NewProfiler(profileFlags.ToConfig("dgrep"))
+ defer profiler.Stop()
+
if grep != "" {
args.RegexStr = grep
}
@@ -75,12 +84,26 @@ func main() {
}()
}
+ // Log initial metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("startup")
+ }
+
client, err := clients.NewGrepClient(args)
if err != nil {
panic(err)
}
status := client.Start(ctx, signal.InterruptCh(ctx))
+
+ // Log final metrics if profiling is enabled
+ if profileFlags.Enabled() {
+ profiler.LogMetrics("shutdown")
+ }
+
+ // Stop profiler before exit
+ profiler.Stop()
+
cancel()
wg.Wait()