Skip to content

Commit f70693f

Browse files
committed
Fix map_operations_demo.ks syntax for tracepoint and kprobe.
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 64f847d commit f70693f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

examples/map_operations_demo.ks

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,21 @@ enum tc_action {
4646
TC_ACT_REDIRECT = 7,
4747
}
4848

49-
// Tracepoint context struct (from BTF)
49+
// Base trace entry struct
5050
struct trace_entry {
5151
entry_type: u16,
5252
flags: u8,
5353
preempt_count: u8,
5454
pid: i32,
5555
}
5656

57+
// Tracepoint context struct (from BTF) - sys_enter structure
58+
struct trace_event_raw_sys_enter {
59+
ent: trace_entry,
60+
id: i64,
61+
args: u64[6],
62+
}
63+
5764
// This example demonstrates comprehensive map operations with multi-program analysis
5865
// It shows various access patterns and concurrent access scenarios
5966

@@ -172,10 +179,11 @@ struct ArrayElement {
172179
}
173180

174181
// Program 3: Event streaming demonstrating ring buffer usage
175-
@tracepoint fn event_logger(ctx: *trace_entry) -> i32 {
182+
@tracepoint("syscalls/sys_enter_open")
183+
fn event_logger(ctx: *trace_event_raw_sys_enter) -> i32 {
176184
var event = Event {
177185
timestamp: 123456, // Fake timestamp
178-
event_type: ctx->entry_type,
186+
event_type: ctx.id, // Use syscall ID from sys_enter context
179187
data: [0], // Simplified data
180188
}
181189

@@ -195,7 +203,8 @@ struct ArrayElement {
195203
}
196204

197205
// Program 4: Sequential access pattern demonstration
198-
@kprobe fn data_processor(file: *file, buf: *u8, count: usize, pos: *i64) -> i32 {
206+
@kprobe("vfs_read")
207+
fn data_processor(file: *file, buf: *u8, count: usize, pos: *i64) -> i32 {
199208
// Sequential access pattern - will be detected and optimized
200209
for (i in 0..32) {
201210
var element = sequential_data[i]

0 commit comments

Comments
 (0)