summaryrefslogtreecommitdiff
path: root/internal/profiling/flags.go
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 /internal/profiling/flags.go
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 'internal/profiling/flags.go')
-rw-r--r--internal/profiling/flags.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/profiling/flags.go b/internal/profiling/flags.go
new file mode 100644
index 0000000..59a6d78
--- /dev/null
+++ b/internal/profiling/flags.go
@@ -0,0 +1,38 @@
+package profiling
+
+import "flag"
+
+// Flags holds command-line flags for profiling
+type Flags struct {
+ // Enable CPU profiling
+ CPUProfile bool
+ // Enable memory profiling
+ MemProfile bool
+ // Enable all profiling (CPU + memory)
+ Profile bool
+ // Directory to store profiles
+ ProfileDir string
+}
+
+// AddFlags adds profiling flags to the flag set
+func AddFlags(f *Flags) {
+ flag.BoolVar(&f.CPUProfile, "cpuprofile", false, "Enable CPU profiling")
+ flag.BoolVar(&f.MemProfile, "memprofile", false, "Enable memory profiling")
+ flag.BoolVar(&f.Profile, "profile", false, "Enable all profiling (CPU + memory)")
+ flag.StringVar(&f.ProfileDir, "profiledir", "profiles", "Directory to store profiles")
+}
+
+// ToConfig converts flags to profiler config
+func (f *Flags) ToConfig(commandName string) Config {
+ return Config{
+ CPUProfile: f.CPUProfile || f.Profile,
+ MemProfile: f.MemProfile || f.Profile,
+ ProfileDir: f.ProfileDir,
+ CommandName: commandName,
+ }
+}
+
+// Enabled returns true if any profiling is enabled
+func (f *Flags) Enabled() bool {
+ return f.CPUProfile || f.MemProfile || f.Profile
+} \ No newline at end of file