From 6664996ced62c77e0c62bc1619662cbed7fccff6 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 26 Jun 2025 13:49:38 +0300 Subject: feat: add profiling framework with command echoing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmd/dmap/main.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'cmd/dmap') diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go index a8a52a2..7500ea6 100644 --- a/cmd/dmap/main.go +++ b/cmd/dmap/main.go @@ -15,6 +15,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" @@ -24,6 +25,7 @@ import ( func main() { var displayVersion bool var pprof string + var profileFlags profiling.Flags args := config.Args{ Mode: omode.MapClient, @@ -50,6 +52,9 @@ func main() { flag.StringVar(&args.UserName, "user", userName, "Your system user name") flag.StringVar(&args.What, "files", "", "File(s) to read") flag.StringVar(&pprof, "pprof", "", "Start PProf server this address") + + // Add profiling flags + profiling.AddFlags(&profileFlags) flag.Parse() config.Setup(source.Client, &args, flag.Args()) @@ -63,6 +68,10 @@ func main() { wg.Add(1) dlog.Start(ctx, &wg, source.Client) + // Set up profiling + profiler := profiling.NewProfiler(profileFlags.ToConfig("dmap")) + defer profiler.Stop() + if pprof != "" { dlog.Client.Info("Starting PProf", pprof) go func() { @@ -70,12 +79,26 @@ func main() { }() } + // Log initial metrics if profiling is enabled + if profileFlags.Enabled() { + profiler.LogMetrics("startup") + } + client, err := clients.NewMaprClient(args, clients.DefaultMode) if err != nil { dlog.Client.FatalPanic(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() -- cgit v1.2.3