diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-13 22:18:17 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-13 22:18:17 +0300 |
| commit | 34d88ba4c82dac2646db27c74e1cafb0c97dbcf2 (patch) | |
| tree | f2897b39ad0fb1b23b3532e81da277959421a32d /internal/flags | |
| parent | 251894cf3375812564ecf28392179b395cdda9c7 (diff) | |
add TUIFastRefreshInterval flag to flags.Config
Add TUIFastRefreshInterval time.Duration to flags.Config struct with a
default of 250ms and register it as the -tui-fast-refresh CLI flag so
callers can tune or disable the high-frequency TUI refresh cadence for
the flamegraph and stream tabs.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/flags')
| -rw-r--r-- | internal/flags/flags.go | 25 | ||||
| -rw-r--r-- | internal/flags/flags_test.go | 35 |
2 files changed, 51 insertions, 9 deletions
diff --git a/internal/flags/flags.go b/internal/flags/flags.go index a46f6b3..e7171ce 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -54,6 +54,10 @@ type Config struct { // LiveInterval is the refresh interval for the synthetic live flamegraph // used when TestLiveFlames is active. LiveInterval time.Duration + // TUIFastRefreshInterval is the high-frequency refresh cadence for the TUI + // flamegraph and stream tabs. A value of 0 disables high-frequency refresh, + // falling back to the standard Bubble Tea tick rate. + TUIFastRefreshInterval time.Duration // TUIExportEnable allows the TUI to write CSV snapshot export files. TUIExportEnable bool // CollapsedFields lists the event fields used as flamegraph collapse keys. @@ -82,15 +86,16 @@ const DefaultResetTimer = 30 * time.Second // NewFlags returns a configuration instance initialized with project defaults. func NewFlags() Config { return Config{ - PidFilter: -1, - TidFilter: -1, - EventMapSize: appconfig.DefaultEventMapSize, - Duration: 900, - LiveInterval: 200 * time.Millisecond, - TUIExportEnable: true, - CollapsedFields: []string{"comm", "tracepoint", "path"}, - CountField: "count", - ResetTimer: DefaultResetTimer, + PidFilter: -1, + TidFilter: -1, + EventMapSize: appconfig.DefaultEventMapSize, + Duration: 900, + LiveInterval: 200 * time.Millisecond, + TUIFastRefreshInterval: 250 * time.Millisecond, + TUIExportEnable: true, + CollapsedFields: []string{"comm", "tracepoint", "path"}, + CountField: "count", + ResetTimer: DefaultResetTimer, } } @@ -170,6 +175,8 @@ func registerFlags(fs *flag.FlagSet, cfg *Config) (tpsAttach, tpsExclude, fields fs.BoolVar(&cfg.TestFlames, "testflames", false, "Run TUI with static synthetic flamegraph data for keyboard-navigation testing") fs.BoolVar(&cfg.TestLiveFlames, "testliveflames", false, "Run TUI with continuously-updating synthetic flamegraph data for live keyboard-navigation testing") fs.DurationVar(&cfg.LiveInterval, "live-interval", cfg.LiveInterval, "Synthetic live flamegraph refresh interval for --testliveflames") + fs.DurationVar(&cfg.TUIFastRefreshInterval, "tui-fast-refresh", cfg.TUIFastRefreshInterval, + "High-frequency refresh interval for TUI flamegraph and stream tabs (0 = disable high-frequency refresh)") fs.BoolVar(&cfg.TUIExportEnable, "tuiExport", cfg.TUIExportEnable, "Enable TUI CSV snapshot export files (separate from Parquet recording)") fs.DurationVar(&cfg.ResetTimer, "resetTimer", cfg.ResetTimer, "Auto-reset interval for aggregate dashboard state (flamegraph trie + stats engine); set to 0 to disable") diff --git a/internal/flags/flags_test.go b/internal/flags/flags_test.go index d4697d6..1feeafd 100644 --- a/internal/flags/flags_test.go +++ b/internal/flags/flags_test.go @@ -255,3 +255,38 @@ func TestParsePositiveMapSizeAccepted(t *testing.T) { t.Fatalf("EventMapSize = %d, want 8192", cfg.EventMapSize) } } + +func TestParseTUIFastRefreshDefault(t *testing.T) { + // Default should be 250ms — the high-frequency refresh cadence used by + // the flamegraph and stream tabs when no explicit flag is provided. + cfg, err := parseForTest(t) + if err != nil { + t.Fatalf("parse returned error: %v", err) + } + if cfg.TUIFastRefreshInterval != 250*time.Millisecond { + t.Fatalf("default TUIFastRefreshInterval = %v, want 250ms", cfg.TUIFastRefreshInterval) + } +} + +func TestParseTUIFastRefreshOverride(t *testing.T) { + // An explicit -tui-fast-refresh value must be respected and stored on cfg. + cfg, err := parseForTest(t, "-tui-fast-refresh", "100ms") + if err != nil { + t.Fatalf("parse returned error: %v", err) + } + if cfg.TUIFastRefreshInterval != 100*time.Millisecond { + t.Fatalf("TUIFastRefreshInterval = %v, want 100ms", cfg.TUIFastRefreshInterval) + } +} + +func TestParseTUIFastRefreshZeroDisables(t *testing.T) { + // A zero value is valid and means "disable high-frequency refresh", + // falling back to the default Bubble Tea tick rate. + cfg, err := parseForTest(t, "-tui-fast-refresh", "0") + if err != nil { + t.Fatalf("parse returned error: %v", err) + } + if cfg.TUIFastRefreshInterval != 0 { + t.Fatalf("TUIFastRefreshInterval = %v, want 0 (disabled)", cfg.TUIFastRefreshInterval) + } +} |
