summaryrefslogtreecommitdiff
path: root/internal/profiling/flags.go
blob: 59a6d7891b7015eb3bae22f1b39572dfa041a13b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}