Skip to content

Commit aaa63e9

Browse files
committed
feat: add ebpf_max_messages configuration
1 parent 46265f9 commit aaa63e9

10 files changed

Lines changed: 88 additions & 4 deletions

File tree

config.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ default_focus = "InteractiveCommand"
104104
# Default: [4, 3, 3]
105105
panel_ratios = [3, 3, 3]
106106

107+
# Maximum number of eBPF trace messages to keep in the output panel
108+
# Older messages are automatically discarded when this limit is reached
109+
# Recommended values:
110+
# - Low-frequency tracing: 1000-2000
111+
# - Medium-frequency tracing: 2000-5000 (default: 2000)
112+
# - High-frequency tracing: 5000-10000
113+
# Minimum value: 100
114+
# Note: Larger values consume more memory
115+
# Default: 2000
116+
ebpf_max_messages = 2000
117+
107118
# Command history configuration
108119
[ui.history]
109120
# Enable/disable command history file functionality

docs/configuration.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ default_focus = "InteractiveCommand"
241241
# Must be 3 positive (non-zero) integers
242242
panel_ratios = [4, 3, 3]
243243

244+
# Maximum number of eBPF trace messages to keep in the output panel
245+
# Older messages are automatically discarded when this limit is reached
246+
# Minimum value: 100
247+
# Recommended values:
248+
# - Low-frequency tracing: 1000-2000
249+
# - Medium-frequency tracing: 2000-5000 (default: 2000)
250+
# - High-frequency tracing: 5000-10000
251+
# Note: Larger values consume more memory
252+
ebpf_max_messages = 2000
253+
244254
[ui.history]
245255
# Enable command history
246256
enabled = true
@@ -422,6 +432,7 @@ export LLVM_SYS_170_PREFIX=/usr/lib/llvm-17
422432
- **Layout**: Horizontal (panels side by side)
423433
- **Panel Ratios**: 4:3:3 (Source:EbpfInfo:Command)
424434
- **Default Focus**: InteractiveCommand panel
435+
- **eBPF Max Messages**: 2000 messages
425436
- **History**: Enabled with 5000 entry limit
426437

427438
## File Output Naming
@@ -450,7 +461,9 @@ GhostScope validates configuration at startup:
450461
4. **Panel Ratios**: Ensures all 3 values are positive (non-zero) integers
451462
5. **Log Level**: Validates against allowed values (error, warn, info, debug, trace)
452463
6. **Layout Mode**: Validates against allowed values (Horizontal, Vertical - capitalized)
453-
7. **eBPF Configuration**:
464+
7. **UI Configuration**:
465+
- **ebpf_max_messages**: Must be at least 100
466+
8. **eBPF Configuration**:
454467
- **ringbuf_size**: Must be power of 2, range 4096-16777216 bytes
455468
- **perf_page_count**: Must be power of 2, range 8-1024 pages
456469
- **proc_module_offsets_max_entries**: Must be in range 64-65536
@@ -468,6 +481,7 @@ Invalid configuration will produce clear error messages with suggestions for fix
468481
- **"perf_page_count must be a power of 2"**: Use values like 32, 64, 128, 256, etc.
469482
- **"perf_page_count X is out of reasonable range"**: Must be between 8 and 1024 pages.
470483
- **"proc_module_offsets_max_entries X is out of reasonable range"**: Must be between 64 and 65536.
484+
- **"ebpf_max_messages X is too small"**: Must be at least 100. Increase the value in your config file.
471485

472486
## Best Practices
473487

docs/zh/configuration.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ default_focus = "InteractiveCommand"
240240
# 必须是 3 个正整数
241241
panel_ratios = [4, 3, 3]
242242

243+
# eBPF 输出面板保留的最大跟踪消息数量
244+
# 超过限制时,旧消息会自动丢弃
245+
# 最小值:100
246+
# 推荐值:
247+
# - 低频跟踪:1000-2000
248+
# - 中频跟踪:2000-5000(默认:2000)
249+
# - 高频跟踪:5000-10000
250+
# 注意:较大的值会消耗更多内存
251+
ebpf_max_messages = 2000
252+
243253
[ui.history]
244254
# 启用命令历史
245255
enabled = true
@@ -421,6 +431,7 @@ export LLVM_SYS_170_PREFIX=/usr/lib/llvm-17
421431
- **布局**:Horizontal(面板横向排列)
422432
- **面板比例**:4:3:3(Source:EbpfInfo:Command
423433
- **默认焦点**:InteractiveCommand 面板
434+
- **eBPF 最大消息数**:2000 条消息
424435
- **历史记录**:启用,5000 条条目限制
425436

426437
## 文件输出命名
@@ -449,7 +460,9 @@ GhostScope 在启动时验证配置:
449460
4. **面板比例**:确保所有 3 个值都是正(非零)整数
450461
5. **日志级别**:验证是否为允许的值(error, warn, info, debug, trace)
451462
6. **布局模式**:验证是否为允许的值(Horizontal, Vertical - 首字母大写)
452-
7. **eBPF 配置**
463+
7. **UI 配置**
464+
- **ebpf_max_messages**:必须至少为 100
465+
8. **eBPF 配置**
453466
- **ringbuf_size**:必须是 2 的幂,范围 4096-16777216 字节
454467
- **proc_module_offsets_max_entries**:必须在 64-65536 范围内
455468

@@ -464,6 +477,7 @@ GhostScope 在启动时验证配置:
464477
- **"ringbuf_size must be a power of 2"**:使用 2 的幂值,如 131072、262144、524288 等。
465478
- **"ringbuf_size X is out of reasonable range"**:必须在 4KB 到 16MB 之间。
466479
- **"proc_module_offsets_max_entries X is out of reasonable range"**:必须在 64 到 65536 之间。
480+
- **"ebpf_max_messages X is too small"**:必须至少为 100。在配置文件中增加该值。
467481

468482
## 最佳实践
469483

ghostscope-ui/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub async fn run_tui_mode(event_registry: EventRegistry, layout_mode: LayoutMode
2121
panel_ratios: [4, 3, 3], // Default ratios for backward compatibility
2222
default_focus: crate::action::PanelType::InteractiveCommand,
2323
history: HistoryConfig::default(),
24+
ebpf_max_messages: 2000, // Default
2425
};
2526
run_tui_mode_with_config(event_registry, ui_config).await
2627
}

ghostscope-ui/src/model/app_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl AppState {
203203
loading_state: LoadingState::Initializing, // Start with loading, wait for runtime response
204204
loading_ui: LoadingUI::new(),
205205
source_panel: SourcePanelState::new(),
206-
ebpf_panel: EbpfPanelState::new(),
206+
ebpf_panel: EbpfPanelState::new_with_max_messages(ui_config.ebpf_max_messages),
207207
command_panel: CommandPanelState::new_with_config(&ui_config.history),
208208
command_renderer: OptimizedRenderer::new(),
209209
command_input_handler: OptimizedInputHandler::new(),

ghostscope-ui/src/model/panel_state.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ pub enum DisplayMode {
130130

131131
impl EbpfPanelState {
132132
pub fn new() -> Self {
133+
Self::new_with_max_messages(2000)
134+
}
135+
136+
pub fn new_with_max_messages(max_messages: usize) -> Self {
133137
Self {
134138
trace_events: VecDeque::new(),
135139
scroll_offset: 0,
136-
max_messages: 2000, // TODO: Make this configurable in the future
140+
max_messages,
137141
auto_scroll: true,
138142
cursor_trace_index: 0,
139143
show_cursor: false,

ghostscope-ui/src/model/ui_state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct UiConfig {
3131
pub panel_ratios: [u16; 3], // [Source, EbpfInfo, InteractiveCommand]
3232
pub default_focus: crate::action::PanelType,
3333
pub history: HistoryConfig,
34+
pub ebpf_max_messages: usize,
3435
}
3536

3637
/// UI-specific state management
@@ -57,6 +58,7 @@ impl UIState {
5758
panel_ratios: [4, 3, 3], // Default ratios
5859
default_focus: crate::action::PanelType::InteractiveCommand,
5960
history: HistoryConfig::default(),
61+
ebpf_max_messages: 2000, // Default value
6062
})
6163
}
6264
}

ghostscope/src/config/merged.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct MergedConfig {
3131
pub panel_ratios: [u16; 3],
3232
pub history_enabled: bool,
3333
pub history_max_entries: usize,
34+
pub ebpf_max_messages: usize,
3435

3536
// DWARF configuration
3637
#[allow(dead_code)]
@@ -157,6 +158,7 @@ impl MergedConfig {
157158
panel_ratios: config.ui.panel_ratios, // UI config from file
158159
history_enabled: config.ui.history.enabled,
159160
history_max_entries: config.ui.history.max_entries,
161+
ebpf_max_messages: config.ui.ebpf_max_messages,
160162
dwarf_search_paths: config.dwarf.search_paths,
161163
ebpf_config: {
162164
// Command line --force-perf-event-array overrides config file
@@ -216,6 +218,7 @@ impl MergedConfig {
216218
enabled: self.history_enabled,
217219
max_entries: self.history_max_entries,
218220
},
221+
ebpf_max_messages: self.ebpf_max_messages,
219222
}
220223
}
221224

ghostscope/src/config/settings.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ pub struct UiConfigToml {
195195
/// Command history configuration
196196
#[serde(default)]
197197
pub history: HistoryConfigToml,
198+
/// Maximum number of eBPF trace messages to keep in the output panel
199+
#[serde(default = "default_ebpf_max_messages")]
200+
pub ebpf_max_messages: usize,
198201
}
199202

200203
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -288,6 +291,10 @@ fn default_history_max_entries() -> usize {
288291
5000
289292
}
290293

294+
fn default_ebpf_max_messages() -> usize {
295+
2000
296+
}
297+
291298
// Default implementations for each config section
292299
impl Default for GeneralConfig {
293300
fn default() -> Self {
@@ -414,7 +421,31 @@ impl Default for UiConfigToml {
414421
default_focus: PanelType::default(),
415422
panel_ratios: default_panel_ratios(),
416423
history: HistoryConfigToml::default(),
424+
ebpf_max_messages: default_ebpf_max_messages(),
425+
}
426+
}
427+
}
428+
429+
impl UiConfigToml {
430+
/// Validate UI configuration values
431+
pub fn validate(&self, file_path: &str) -> Result<()> {
432+
// Validate ebpf_max_messages is reasonable (at least 100)
433+
if self.ebpf_max_messages < 100 {
434+
return Err(anyhow::anyhow!(
435+
"❌ Invalid UI configuration in '{}':\n\n\
436+
ebpf_max_messages {} is too small\n\n\
437+
💡 Minimum value: 100\n\
438+
Recommended values:\n\
439+
- Low-frequency tracing: 1000-2000\n\
440+
- Medium-frequency tracing: 2000-5000 (default: 2000)\n\
441+
- High-frequency tracing: 5000-10000\n\
442+
Note: Larger values consume more memory",
443+
file_path,
444+
self.ebpf_max_messages
445+
));
417446
}
447+
448+
Ok(())
418449
}
419450
}
420451

@@ -477,6 +508,9 @@ impl Config {
477508
// Validate eBPF configuration
478509
config.ebpf.validate(&path.display().to_string())?;
479510

511+
// Validate UI configuration
512+
config.ui.validate(&path.display().to_string())?;
513+
480514
Ok(config)
481515
}
482516

ghostscope/src/runtime/coordinator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub async fn run_tui_coordinator(parsed_args: ParsedArgs) -> Result<()> {
5656
default_focus: ghostscope_ui::PanelType::InteractiveCommand, // Default
5757
panel_ratios: [4, 3, 3], // Default
5858
history: ghostscope_ui::HistoryConfig::default(),
59+
ebpf_max_messages: 2000, // Default
5960
};
6061

6162
// Create a default MergedConfig from ParsedArgs for compatibility

0 commit comments

Comments
 (0)