From 32136b8cb18944157ff1f361bc0755f6b627fd47 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 21 Feb 2026 10:25:39 +0200 Subject: Align Go project structure and add Mage targets Amp-Thread-ID: https://ampcode.com/threads/T-019c7f3b-1326-767b-94d5-366b91eaf712 Co-authored-by: Amp --- internal/flags/flags.go | 47 ++++++++++++++++++++++++----------------------- internal/flags/version.go | 18 +++++++++++------- 2 files changed, 35 insertions(+), 30 deletions(-) (limited to 'internal') diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 512697c..de0e74f 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -17,25 +17,25 @@ var ( once sync.Once ) -var validCollapsedFields = []string{ - "path", - "comm", - "tracepoint", - "pid", - "tid", - "flags", -} +const flamegraphToolDefault = "$HOME/git/FlameGraph/flamegraph.pl" -var validCollapsedCounts = []string{ - "count", - "duration", - "durationToPrev", - "bytes", -} +var ( + validCollapsedFields = []string{ + "path", + "comm", + "tracepoint", + "pid", + "tid", + "flags", + } -func Get() Flags { - return singleton -} + validCollapsedCounts = []string{ + "count", + "duration", + "durationToPrev", + "bytes", + } +) type Flags struct { PidFilter int @@ -63,6 +63,10 @@ type Flags struct { FlamegraphTool string } +func Get() Flags { + return singleton +} + func Parse() { once.Do(func() { parse() @@ -70,8 +74,6 @@ func Parse() { } func parse() { - version := flag.Bool("version", false, "Print version") - flag.IntVar(&singleton.PidFilter, "pid", -1, "Filter for processes ID") flag.IntVar(&singleton.TidFilter, "tid", -1, "Filter for thread ID") flag.IntVar(&singleton.EventMapSize, "mapSize", 4096*16, "BPF FD event ring buffer map size") @@ -96,12 +98,11 @@ func parse() { // https://github.com/brendangregg/FlameGraph flag.StringVar(&singleton.FlamegraphTool, "flamegraphTool", - os.Getenv("HOME")+"/git/FlameGraph/flamegraph.pl", "Path to the flamegraph tool (e.g. flamegraph.pl or inferno-flamegraph)") + "", "Path to the flamegraph tool (e.g. flamegraph.pl or inferno-flamegraph)") flag.Parse() - if *version { - PrintVersion() - os.Exit(0) + if singleton.FlamegraphTool == "" { + singleton.FlamegraphTool = flamegraphToolDefault } singleton.TracepointsToAttach = extractTracepointFlags(*tracepointsToAttach) diff --git a/internal/flags/version.go b/internal/flags/version.go index 1cb2dfd..7e6c50e 100644 --- a/internal/flags/version.go +++ b/internal/flags/version.go @@ -1,13 +1,17 @@ package flags -const version = `v0.0.0` +import "fmt" -const asciiBanner = ` ___   _____    ___ _     _    -|_ _| / / _ \  | _ (_)___| |_  - | | / / (_) | |   / / _ \  _| -|___/_/ \___/  |_|_\_\___/\__| NG - ` + version +// Version is the current application version. +const Version = "v0.0.0" +const asciiBannerTemplate = ` ___ _____ ___ _ _ +|_ _| / / _ \ | _ (_)___| |_ + | | / / (_) | | / / _ \ _| +|___/_/ \___/ |_|_\_\___/\__| NG + %s` + +// PrintVersion prints the banner with the current version. func PrintVersion() { - println(asciiBanner) + fmt.Printf(asciiBannerTemplate+"\n", Version) } -- cgit v1.2.3