Skip to content

Commit fc59e2d

Browse files
committed
refactor: remove legacy PrintFormat path and test helpers; clean up unused code
1 parent aaa63e9 commit fc59e2d

8 files changed

Lines changed: 24 additions & 1916 deletions

File tree

docs/architecture.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ GhostScope uses an **instruction-based protocol** for flexible trace event repre
307307
| **PrintStringIndex** | 0x01 | Print static string (indexed) |
308308
| **PrintVariableIndex** | 0x02 | Print simple variable with type info |
309309
| **PrintComplexVariable** | 0x03 | Print struct/array with access path |
310-
| **PrintFormat** | 0x04 | Formatted print with multiple arguments |
311310
| **PrintComplexFormat** | 0x05 | Formatted print with complex variables |
312311
| **Backtrace** | 0x10 | Stack backtrace with frame addresses |
313312
| **EndInstruction** | 0xFF | Marks end of instruction sequence |

docs/zh/architecture.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ GhostScope 使用**基于指令的协议**实现灵活的追踪事件表示:
307307
| **PrintStringIndex** | 0x01 | 打印静态字符串(索引化) |
308308
| **PrintVariableIndex** | 0x02 | 打印带类型信息的简单变量 |
309309
| **PrintComplexVariable** | 0x03 | 打印带访问路径的结构体/数组 |
310-
| **PrintFormat** | 0x04 | 带多个参数的格式化打印 |
311310
| **PrintComplexFormat** | 0x05 | 带复杂变量的格式化打印 |
312311
| **Backtrace** | 0x10 | 带栈帧地址的栈回溯 |
313312
| **EndInstruction** | 0xFF | 标记指令序列结束 |

ghostscope-compiler/src/ebpf/codegen.rs

Lines changed: 3 additions & 1277 deletions
Large diffs are not rendered by default.

ghostscope-protocol/src/format_printer.rs

Lines changed: 14 additions & 529 deletions
Large diffs are not rendered by default.

ghostscope-protocol/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ pub mod type_info;
1414
pub use type_kind::{consts, TypeKind};
1515

1616
pub use trace_event::{
17-
EndInstructionData, InstructionHeader, InstructionType, PrintFormatData, PrintStringIndexData,
18-
PrintVariableIndexData, TraceEventHeader, TraceEventMessage, VariableData, VariableStatus,
17+
EndInstructionData, InstructionHeader, InstructionType, PrintStringIndexData,
18+
PrintVariableIndexData, TraceEventHeader, TraceEventMessage, VariableStatus,
1919
};
2020

2121
pub use trace_context::TraceContext;
2222

23-
pub use format_printer::{FormatPrinter, ParsedVariable};
23+
pub use format_printer::FormatPrinter;
2424

2525
pub use streaming_parser::{
2626
EventSource, ParseState, ParsedInstruction, ParsedTraceEvent, StreamingTraceParser,

ghostscope-protocol/src/streaming_parser.rs

Lines changed: 3 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ pub enum ParsedInstruction {
2929
formatted_value: String,
3030
raw_data: Vec<u8>,
3131
},
32-
PrintFormat {
33-
formatted_output: String,
34-
},
3532
PrintComplexFormat {
3633
formatted_output: String,
3734
},
@@ -84,11 +81,7 @@ impl ParsedTraceEvent {
8481
i += 1;
8582
}
8683
}
87-
ParsedInstruction::PrintFormat { formatted_output } => {
88-
// Already formatted, just add it
89-
output.push(formatted_output.clone());
90-
i += 1;
91-
}
84+
9285
ParsedInstruction::EndInstruction { .. } => {
9386
// Skip EndInstruction - it's for protocol control, not user output
9487
i += 1;
@@ -460,63 +453,6 @@ impl StreamingTraceParser {
460453
}
461454
}
462455

463-
t if t == InstructionType::PrintFormat as u8 => {
464-
let (format_data, _) = PrintFormatData::read_from_prefix(inst_data)
465-
.map_err(|_| "Invalid PrintFormat data".to_string())?;
466-
467-
// Parse variable data
468-
let mut variables = Vec::new();
469-
let mut offset = std::mem::size_of::<PrintFormatData>();
470-
471-
for _ in 0..format_data.arg_count {
472-
// Header: var_name_index:u16 (2), type_encoding:u8 (1), data_len:u16 (2), type_index:u16 (2), status:u8 (1)
473-
if offset + 8 > inst_data.len() {
474-
return Err("Invalid PrintFormat variable header".to_string());
475-
}
476-
477-
// Read variable header fields in struct order
478-
let var_name_index =
479-
u16::from_le_bytes([inst_data[offset], inst_data[offset + 1]]);
480-
let type_encoding_byte = inst_data[offset + 2];
481-
let data_len =
482-
u16::from_le_bytes([inst_data[offset + 3], inst_data[offset + 4]]);
483-
let type_index =
484-
u16::from_le_bytes([inst_data[offset + 5], inst_data[offset + 6]]);
485-
let status = inst_data[offset + 7];
486-
487-
offset += 8;
488-
489-
if offset + data_len as usize > inst_data.len() {
490-
return Err("Invalid PrintFormat variable data".to_string());
491-
}
492-
493-
let var_data = inst_data[offset..offset + data_len as usize].to_vec();
494-
offset += data_len as usize;
495-
496-
// Convert type encoding byte to enum
497-
let type_encoding =
498-
TypeKind::from_u8(type_encoding_byte).unwrap_or(TypeKind::Unknown);
499-
500-
variables.push(crate::format_printer::ParsedVariable {
501-
var_name_index,
502-
type_encoding,
503-
// Preserve zero-based indices; 0 is a valid type_index
504-
type_index: Some(type_index),
505-
status,
506-
data: var_data,
507-
});
508-
}
509-
510-
// Use FormatPrinter to generate formatted output
511-
let formatted_output = crate::format_printer::FormatPrinter::format_print_data(
512-
format_data.format_string_index,
513-
&variables,
514-
trace_context,
515-
);
516-
517-
ParsedInstruction::PrintFormat { formatted_output }
518-
}
519-
520456
t if t == InstructionType::PrintComplexFormat as u8 => {
521457
let (format_data, _) = PrintComplexFormatData::read_from_prefix(inst_data)
522458
.map_err(|_| "Invalid PrintComplexFormat data".to_string())?;
@@ -690,7 +626,7 @@ impl ParsedInstruction {
690626
} => {
691627
format!("{name} ({type_encoding:?}): {formatted_value}")
692628
}
693-
ParsedInstruction::PrintFormat { formatted_output } => formatted_output.clone(),
629+
694630
ParsedInstruction::PrintComplexFormat { formatted_output } => formatted_output.clone(),
695631
ParsedInstruction::PrintComplexVariable {
696632
name: _,
@@ -725,7 +661,7 @@ impl ParsedInstruction {
725661
match self {
726662
ParsedInstruction::PrintString { .. } => "PrintString".to_string(),
727663
ParsedInstruction::PrintVariable { .. } => "PrintVariable".to_string(),
728-
ParsedInstruction::PrintFormat { .. } => "PrintFormat".to_string(),
664+
729665
ParsedInstruction::PrintComplexFormat { .. } => "PrintComplexFormat".to_string(),
730666
ParsedInstruction::PrintComplexVariable { .. } => "PrintComplexVariable".to_string(),
731667
ParsedInstruction::Backtrace { .. } => "Backtrace".to_string(),

ghostscope-protocol/src/trace_event.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub enum InstructionType {
2626
PrintStringIndex = 0x01, // print "string" (using string table index)
2727
PrintVariableIndex = 0x02, // print variable (using variable name index)
2828
PrintComplexVariable = 0x03, // print complex variable (with full type info)
29-
PrintFormat = 0x04, // print "format {} {}", var1, var2 (formatted print)
3029
PrintComplexFormat = 0x05, // print with complex variables in format args
3130
Backtrace = 0x10, // backtrace instruction
3231

@@ -88,18 +87,6 @@ pub struct PrintComplexVariableData {
8887
// Followed by access_path (UTF-8 string) then variable data
8988
}
9089

91-
/// Format print instruction data
92-
#[repr(C, packed)]
93-
#[derive(Debug, Clone, Copy, FromBytes, KnownLayout, Immutable, Unaligned)]
94-
pub struct PrintFormatData {
95-
pub format_string_index: u16, // Index into string table for format string
96-
pub arg_count: u8, // Number of arguments
97-
pub reserved: u8, // Padding for alignment
98-
// Followed by argument data in struct order (8 bytes header):
99-
// [var_name_index:u16, type_encoding:u8, data_len:u16, type_index:u16, status:u8, data:bytes] * arg_count
100-
// Note: In fast path (script variables/literals), status is always 0 (VariableStatus::Ok)
101-
}
102-
10390
/// Complex format print instruction data (with full type info)
10491
#[repr(C, packed)]
10592
#[derive(Debug, Clone, Copy, FromBytes, KnownLayout, Immutable, Unaligned)]
@@ -113,7 +100,7 @@ pub struct PrintComplexFormatData {
113100
}
114101

115102
// Note: historical PrintVariableError has been removed; per-variable errors
116-
// are carried via status in PrintVariableIndex/Format/ComplexFormat.
103+
// are carried via status in PrintVariableIndex/ComplexFormat.
117104

118105
/// Backtrace instruction data
119106
#[repr(C, packed)]
@@ -146,10 +133,6 @@ pub enum Instruction {
146133
type_index: u16, // Index into type table (new field)
147134
data: Vec<u8>,
148135
},
149-
PrintFormat {
150-
format_string_index: u16,
151-
variables: Vec<VariableData>,
152-
},
153136
Backtrace {
154137
depth: u8,
155138
flags: u8,
@@ -161,22 +144,12 @@ pub enum Instruction {
161144
},
162145
}
163146

164-
/// Variable data for PrintFormat instruction
165-
#[derive(Debug, Clone, Serialize, Deserialize)]
166-
pub struct VariableData {
167-
pub var_name_index: u16,
168-
pub type_encoding: TypeKind,
169-
pub type_index: u16, // Index into type table (new field)
170-
pub data: Vec<u8>,
171-
}
172-
173147
impl Instruction {
174148
/// Get the instruction type
175149
pub fn instruction_type(&self) -> InstructionType {
176150
match self {
177151
Instruction::PrintStringIndex { .. } => InstructionType::PrintStringIndex,
178152
Instruction::PrintVariableIndex { .. } => InstructionType::PrintVariableIndex,
179-
Instruction::PrintFormat { .. } => InstructionType::PrintFormat,
180153
Instruction::Backtrace { .. } => InstructionType::Backtrace,
181154
Instruction::EndInstruction { .. } => InstructionType::EndInstruction,
182155
}
@@ -191,12 +164,6 @@ mod tests {
191164
fn test_instruction_types() {
192165
let inst1 = Instruction::PrintStringIndex { string_index: 0 };
193166
assert_eq!(inst1.instruction_type(), InstructionType::PrintStringIndex);
194-
195-
let inst2 = Instruction::PrintFormat {
196-
format_string_index: 0,
197-
variables: vec![],
198-
};
199-
assert_eq!(inst2.instruction_type(), InstructionType::PrintFormat);
200167
}
201168

202169
#[test]

ghostscope-protocol/src/type_kind.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ pub mod consts {
166166
pub const PRINT_VARIABLE_INDEX_DATA_SIZE: usize =
167167
std::mem::size_of::<crate::trace_event::PrintVariableIndexData>();
168168

169-
/// Print format data size
170-
pub const PRINT_FORMAT_DATA_SIZE: usize =
171-
std::mem::size_of::<crate::trace_event::PrintFormatData>();
172-
173169
// TraceEventMessage field offsets
174170
pub const TRACE_EVENT_MESSAGE_TRACE_ID_OFFSET: usize = 0;
175171
pub const TRACE_EVENT_MESSAGE_TIMESTAMP_OFFSET: usize = 8;

0 commit comments

Comments
 (0)