summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/eventloop.go4
-rw-r--r--internal/flags/flags.go4
-rw-r--r--internal/flags/flags_test.go11
-rw-r--r--internal/flamegraph/liveserver.go30
-rw-r--r--internal/flamegraph/liveserver_open_test.go54
-rw-r--r--internal/ior.go1
6 files changed, 22 insertions, 82 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index 50494dc..0f593fd 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -26,7 +26,6 @@ type eventLoopConfig struct {
pathFilter string
liveFlamegraph bool
liveInterval time.Duration
- liveOpen bool
liveOpenCommand string
collapsedFields []string
countField string
@@ -285,8 +284,7 @@ func (e *eventLoop) run(ctx context.Context, rawCh <-chan []byte) {
fmt.Println("Starting live flamegraph server")
go func() {
liveOptions := flamegraph.LiveServerOptions{
- AutoOpenBrowser: e.cfg.liveOpen,
- OpenCommand: e.cfg.liveOpenCommand,
+ OpenCommand: e.cfg.liveOpenCommand,
}
if err := flamegraph.ServeLiveWithOptions(ctx, e.liveTrie, e.cfg.liveInterval, liveOptions); err != nil && ctx.Err() == nil {
fmt.Println("Live flamegraph server error:", err)
diff --git a/internal/flags/flags.go b/internal/flags/flags.go
index c4ee7d2..a732c3a 100644
--- a/internal/flags/flags.go
+++ b/internal/flags/flags.go
@@ -65,7 +65,6 @@ type Flags struct {
FlamegraphEnable bool
LiveFlamegraph bool
LiveInterval time.Duration
- OpenLiveBrowser bool
OpenCommand string
FlamegraphName string
TUIExportEnable bool
@@ -124,8 +123,7 @@ 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.OpenCommand, "open", "", "Command to open live flamegraph URL (used with -live); 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 3fa74c6..32af4bd 100644
--- a/internal/flags/flags_test.go
+++ b/internal/flags/flags_test.go
@@ -69,9 +69,6 @@ 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")
}
@@ -89,25 +86,19 @@ 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")
+ cfg, err := parseForTest(t, "-live", "-open", "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")
}
diff --git a/internal/flamegraph/liveserver.go b/internal/flamegraph/liveserver.go
index dda1af1..de65ee3 100644
--- a/internal/flamegraph/liveserver.go
+++ b/internal/flamegraph/liveserver.go
@@ -7,7 +7,6 @@ import (
"fmt"
"net/http"
"os/exec"
- "runtime"
"strings"
"time"
)
@@ -19,8 +18,7 @@ var liveServerTimeouts = serverTimeouts{
}
type LiveServerOptions struct {
- AutoOpenBrowser bool
- OpenCommand string
+ OpenCommand string
}
var openBrowserURLFn = openBrowserURL
@@ -47,14 +45,14 @@ func ServeLiveWithOptions(ctx context.Context, lt *LiveTrie, interval time.Durat
}
func maybeOpenLiveBrowser(url string, options LiveServerOptions) error {
- if !options.AutoOpenBrowser {
+ if strings.TrimSpace(options.OpenCommand) == "" {
return nil
}
return openBrowserURLFn(url, options.OpenCommand)
}
func openBrowserURL(url, openCommand string) error {
- parts, err := browserOpenCommandParts(runtime.GOOS, openCommand, url)
+ parts, err := browserOpenCommandParts(openCommand, url)
if err != nil {
return err
}
@@ -66,13 +64,8 @@ func openBrowserURL(url, openCommand string) error {
return nil
}
-func browserOpenCommandParts(goos, openCommand, url string) ([]string, error) {
- var parts []string
- if trimmed := strings.TrimSpace(openCommand); trimmed != "" {
- parts = strings.Fields(trimmed)
- } else {
- parts = defaultBrowserCommand(goos)
- }
+func browserOpenCommandParts(openCommand, url string) ([]string, error) {
+ parts := strings.Fields(strings.TrimSpace(openCommand))
if len(parts) == 0 {
return nil, errors.New("empty browser open command")
}
@@ -90,19 +83,6 @@ func browserOpenCommandParts(goos, openCommand, url string) ([]string, error) {
return parts, nil
}
-func defaultBrowserCommand(goos string) []string {
- switch goos {
- case "darwin":
- return []string{"open", "-a", "Firefox"}
- case "linux":
- return []string{"firefox"}
- case "windows":
- return []string{"cmd", "/c", "start"}
- default:
- return []string{"firefox"}
- }
-}
-
func handleLivePage() http.HandlerFunc {
return func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
diff --git a/internal/flamegraph/liveserver_open_test.go b/internal/flamegraph/liveserver_open_test.go
index 9d280b9..0a42a61 100644
--- a/internal/flamegraph/liveserver_open_test.go
+++ b/internal/flamegraph/liveserver_open_test.go
@@ -5,40 +5,15 @@ import (
"testing"
)
-func TestBrowserOpenCommandPartsUsesLinuxDefault(t *testing.T) {
- got, err := browserOpenCommandParts("linux", "", "http://localhost:1234/")
- if err != nil {
- t.Fatalf("browserOpenCommandParts returned error: %v", err)
- }
- want := []string{"firefox", "http://localhost:1234/"}
- if len(got) != len(want) {
- t.Fatalf("len(parts) = %d, want %d", len(got), len(want))
- }
- for i := range want {
- if got[i] != want[i] {
- t.Fatalf("parts[%d] = %q, want %q", i, got[i], want[i])
- }
- }
-}
-
-func TestBrowserOpenCommandPartsUsesDarwinDefault(t *testing.T) {
- got, err := browserOpenCommandParts("darwin", "", "http://localhost:1234/")
- if err != nil {
- t.Fatalf("browserOpenCommandParts returned error: %v", err)
- }
- want := []string{"open", "-a", "Firefox", "http://localhost:1234/"}
- if len(got) != len(want) {
- t.Fatalf("len(parts) = %d, want %d", len(got), len(want))
- }
- for i := range want {
- if got[i] != want[i] {
- t.Fatalf("parts[%d] = %q, want %q", i, got[i], want[i])
- }
+func TestBrowserOpenCommandPartsRequiresCommand(t *testing.T) {
+ _, err := browserOpenCommandParts("", "http://localhost:1234/")
+ if err == nil {
+ t.Fatalf("expected error for empty open command")
}
}
-func TestBrowserOpenCommandPartsOverrideAppendsURL(t *testing.T) {
- got, err := browserOpenCommandParts("linux", "chromium --new-window", "http://localhost:1234/")
+func TestBrowserOpenCommandPartsAppendsURLWhenMissing(t *testing.T) {
+ got, err := browserOpenCommandParts("chromium --new-window", "http://localhost:1234/")
if err != nil {
t.Fatalf("browserOpenCommandParts returned error: %v", err)
}
@@ -53,8 +28,8 @@ func TestBrowserOpenCommandPartsOverrideAppendsURL(t *testing.T) {
}
}
-func TestBrowserOpenCommandPartsOverrideReplacesPlaceholder(t *testing.T) {
- got, err := browserOpenCommandParts("linux", "open-browser --target={url}", "http://localhost:1234/")
+func TestBrowserOpenCommandPartsReplacesURLPlaceholder(t *testing.T) {
+ got, err := browserOpenCommandParts("open-browser --target={url}", "http://localhost:1234/")
if err != nil {
t.Fatalf("browserOpenCommandParts returned error: %v", err)
}
@@ -69,7 +44,7 @@ func TestBrowserOpenCommandPartsOverrideReplacesPlaceholder(t *testing.T) {
}
}
-func TestMaybeOpenLiveBrowserDisabledSkipsOpen(t *testing.T) {
+func TestMaybeOpenLiveBrowserWithoutCommandSkipsOpen(t *testing.T) {
called := false
orig := openBrowserURLFn
openBrowserURLFn = func(url, openCommand string) error {
@@ -78,16 +53,16 @@ func TestMaybeOpenLiveBrowserDisabledSkipsOpen(t *testing.T) {
}
t.Cleanup(func() { openBrowserURLFn = orig })
- err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{AutoOpenBrowser: false})
+ err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{})
if err != nil {
t.Fatalf("maybeOpenLiveBrowser returned error: %v", err)
}
if called {
- t.Fatalf("expected browser opener not to be called when disabled")
+ t.Fatalf("expected browser opener not to be called without open command")
}
}
-func TestMaybeOpenLiveBrowserEnabledCallsOpen(t *testing.T) {
+func TestMaybeOpenLiveBrowserWithCommandCallsOpen(t *testing.T) {
called := false
orig := openBrowserURLFn
openBrowserURLFn = func(url, openCommand string) error {
@@ -103,8 +78,7 @@ func TestMaybeOpenLiveBrowserEnabledCallsOpen(t *testing.T) {
t.Cleanup(func() { openBrowserURLFn = orig })
err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{
- AutoOpenBrowser: true,
- OpenCommand: "chromium",
+ OpenCommand: "chromium",
})
if err != nil {
t.Fatalf("maybeOpenLiveBrowser returned error: %v", err)
@@ -122,7 +96,7 @@ func TestMaybeOpenLiveBrowserPropagatesOpenError(t *testing.T) {
t.Cleanup(func() { openBrowserURLFn = orig })
err := maybeOpenLiveBrowser("http://localhost:1234/", LiveServerOptions{
- AutoOpenBrowser: true,
+ OpenCommand: "chromium",
})
if err == nil || err.Error() != "launch failed" {
t.Fatalf("expected launch failed error, got %v", err)
diff --git a/internal/ior.go b/internal/ior.go
index b109b2e..b198d78 100644
--- a/internal/ior.go
+++ b/internal/ior.go
@@ -229,7 +229,6 @@ func newEventLoopConfig(cfg flags.Flags) eventLoopConfig {
pathFilter: cfg.PathFilter,
liveFlamegraph: cfg.LiveFlamegraph,
liveInterval: cfg.LiveInterval,
- liveOpen: cfg.OpenLiveBrowser,
liveOpenCommand: cfg.OpenCommand,
collapsedFields: fields,
countField: cfg.CountField,