summaryrefslogtreecommitdiff
path: root/internal/flags
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-02 08:39:35 +0200
committerPaul Buetow <paul@buetow.org>2026-03-02 08:39:35 +0200
commitb3327d17f9f5c7080b05d6d5457cf25550d40ad9 (patch)
tree090e66047c14c9183058bd68a8d4afc12b48f399 /internal/flags
parent38620359537d77ab10acb888d266d3c6eb16fc9b (diff)
Add --open support for live flamegraph browser launch
Diffstat (limited to 'internal/flags')
-rw-r--r--internal/flags/flags.go4
-rw-r--r--internal/flags/flags_test.go28
2 files changed, 32 insertions, 0 deletions
diff --git a/internal/flags/flags.go b/internal/flags/flags.go
index bf348c7..c4ee7d2 100644
--- a/internal/flags/flags.go
+++ b/internal/flags/flags.go
@@ -65,6 +65,8 @@ type Flags struct {
FlamegraphEnable bool
LiveFlamegraph bool
LiveInterval time.Duration
+ OpenLiveBrowser bool
+ OpenCommand string
FlamegraphName string
TUIExportEnable bool
@@ -122,6 +124,8 @@ func parse() error {
flag.BoolVar(&singleton.FlamegraphEnable, "flamegraph", false, "Enable flamegraph builder")
flag.BoolVar(&singleton.LiveFlamegraph, "live", false, "Enable live flamegraph mode")
flag.DurationVar(&singleton.LiveInterval, "live-interval", 200*time.Millisecond, "Live flamegraph refresh interval")
+ flag.BoolVar(&singleton.OpenLiveBrowser, "open", false, "Auto-open live flamegraph URL in a browser (used with -live)")
+ flag.StringVar(&singleton.OpenCommand, "open-cmd", "", "Custom command to open live flamegraph URL; use {url} placeholder or URL is appended")
flag.StringVar(&singleton.FlamegraphName, "name", "default", "Name of the flamegraph, used to generate the SVG file")
flag.BoolVar(&singleton.TUIExportEnable, "tuiExport", true, "Enable writing TUI snapshot export files")
diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go
index a4feb5d..3fa74c6 100644
--- a/internal/flags/flags_test.go
+++ b/internal/flags/flags_test.go
@@ -69,6 +69,12 @@ func TestParseLiveFlagsAndInterval(t *testing.T) {
if got := int(pidFilter.Load()); got != 1234 {
t.Fatalf("global pid filter = %d, want 1234", got)
}
+ if cfg.OpenLiveBrowser {
+ t.Fatalf("expected open-live disabled by default")
+ }
+ if cfg.OpenCommand != "" {
+ t.Fatalf("expected empty open command by default")
+ }
}
func TestParseLiveDefaults(t *testing.T) {
@@ -83,6 +89,28 @@ func TestParseLiveDefaults(t *testing.T) {
if cfg.LiveInterval != 200*time.Millisecond {
t.Fatalf("default live interval = %v, want %v", cfg.LiveInterval, 200*time.Millisecond)
}
+ if cfg.OpenLiveBrowser {
+ t.Fatalf("expected open-live disabled by default")
+ }
+ if cfg.OpenCommand != "" {
+ t.Fatalf("expected empty open command by default")
+ }
+}
+
+func TestParseOpenFlags(t *testing.T) {
+ cfg, err := parseForTest(t, "-live", "-open", "-open-cmd", "chromium --new-window")
+ if err != nil {
+ t.Fatalf("parse returned error: %v", err)
+ }
+ if !cfg.LiveFlamegraph {
+ t.Fatalf("expected live mode enabled")
+ }
+ if !cfg.OpenLiveBrowser {
+ t.Fatalf("expected -open to enable live browser open")
+ }
+ if cfg.OpenCommand != "chromium --new-window" {
+ t.Fatalf("open command = %q, want %q", cfg.OpenCommand, "chromium --new-window")
+ }
}
func TestParseDefaultCollapsedFieldsOrder(t *testing.T) {