Skip to content

Commit 8a4133b

Browse files
committed
refactor(event): Decode params with cursor
Parameter descriptors encode the wire format of every event's parameter. That information is used to drive the cursor-based decoder removing the need for manually populating the parameters. The cursor can also extract the paramter from the event record, such as the real parent process id or it can handle derive or interpreted parameters,
1 parent aed6c32 commit 8a4133b

17 files changed

Lines changed: 2926 additions & 757 deletions

‎pkg/event/metainfo.go‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818

1919
package event
2020

21-
import "slices"
21+
import (
22+
"slices"
23+
24+
"github.com/rabbitstack/fibratus/pkg/event/params"
25+
)
2226

2327
// Flags represents the event flags
2428
type Flags uint8
@@ -39,8 +43,18 @@ type Info struct {
3943
Description string
4044
// Flags describes additional properties of the event.
4145
Flags Flags
46+
// Params is the schema of the event parameters. It describes every parameter
47+
// that the event can carry, including those that are appended later in the
48+
// event lifecycle. The position of the parameter descriptor is the index of
49+
// the parameter in the event's Params slice. The schema is shared by all
50+
// instances of the event type and must not be mutated.
51+
Params []params.ParamInfo
4252
}
4353

54+
// ParamCount returns the number of parameters described by the event schema.
55+
// It determines the number of slots allocated for the event parameters.
56+
func (i Info) ParamCount() int { return len(i.Params) }
57+
4458
// All returns all event types.
4559
func AllTypes() []Type {
4660
types := make([]Type, 0)

‎pkg/event/metainfo_linux.go‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,32 @@ package event
2424
import (
2525
"cmp"
2626
"slices"
27+
28+
"github.com/rabbitstack/fibratus/pkg/event/params"
2729
)
2830

2931
var table = [MaxEvent]Info{
30-
Execve: {Name: "execve", Category: Process, Source: RawSyscallTracepoint, Description: "Executes a program"},
31-
Exit: {Name: "exit", Category: Process, Source: RawSyscallTracepoint, Description: "Exit all threads in a process"},
32-
Openat: {Name: "openat", Category: File, Source: RawSyscallTracepoint, Description: "Opens or creates a file"},
33-
Unlink: {Name: "unlink", Category: File, Source: RawSyscallTracepoint, Description: "Removes a directory entry"},
34-
Rename: {Name: "rename", Category: File, Source: RawSyscallTracepoint, Description: "Renames a file or directory"},
35-
Connect: {Name: "connect", Category: Network, Source: RawSyscallTracepoint, Description: "Initiates a socket connection"},
36-
Accept: {Name: "accept", Category: Network, Source: RawSyscallTracepoint, Description: "Accepts a socket connection"},
37-
Mmap: {Name: "mmap", Category: Memory, Source: RawSyscallTracepoint, Description: "Maps files or devices into memory"},
38-
ProcessVMRead: {Name: "process_vm_read", Category: Memory, Source: RawSyscallTracepoint, Description: "Reads memory from another process"},
39-
ProcessVMWrite: {Name: "process_vm_write", Category: Memory, Source: RawSyscallTracepoint, Description: "Writes memory into another process"},
40-
Kill: {Name: "kill", Category: Process, Source: RawSyscallTracepoint, Description: "Sends a signal to a process"},
41-
Ptrace: {Name: "ptrace", Category: Process, Source: RawSyscallTracepoint, Description: "Traces or controls another process"},
42-
Prctl: {Name: "prctl", Category: Process, Source: RawSyscallTracepoint, Description: "Performs a process-control operation"},
32+
Execve: {Name: "execve", Category: Process, Source: RawSyscallTracepoint, Description: "Executes a program", Params: params.ExecveDescriptor},
33+
Exit: {Name: "exit", Category: Process, Source: RawSyscallTracepoint, Description: "Exit all threads in a process", Params: params.ExitDescriptor},
34+
Clone: {Name: "clone", Category: Process, Source: RawSyscallTracepoint, Description: "Creates a child process", Params: params.CloneDescriptor},
35+
Openat: {Name: "openat", Category: File, Source: RawSyscallTracepoint, Description: "Opens or creates a file", Params: params.OpenatDescriptor},
36+
Unlink: {Name: "unlink", Category: File, Source: RawSyscallTracepoint, Description: "Removes a directory entry", Params: params.UnlinkDescriptor},
37+
Rename: {Name: "rename", Category: File, Source: RawSyscallTracepoint, Description: "Renames a file or directory", Params: params.RenameDescriptor},
38+
Connect: {Name: "connect", Category: Network, Source: RawSyscallTracepoint, Description: "Initiates a socket connection", Params: params.SocketDescriptor},
39+
Accept: {Name: "accept", Category: Network, Source: RawSyscallTracepoint, Description: "Accepts a socket connection", Params: params.SocketDescriptor},
40+
Mmap: {Name: "mmap", Category: Memory, Source: RawSyscallTracepoint, Description: "Maps files or devices into memory", Params: params.MmapDescriptor},
41+
ProcessVMRead: {Name: "process_vm_read", Category: Memory, Source: RawSyscallTracepoint, Description: "Reads memory from another process", Params: params.ProcessVMReadDescriptor},
42+
ProcessVMWrite: {Name: "process_vm_write", Category: Memory, Source: RawSyscallTracepoint, Description: "Writes memory into another process", Params: params.ProcessVMWriteDescriptor},
43+
Kill: {Name: "kill", Category: Process, Source: RawSyscallTracepoint, Description: "Sends a signal to a process", Params: params.KillDescriptor},
44+
Ptrace: {Name: "ptrace", Category: Process, Source: RawSyscallTracepoint, Description: "Traces or controls another process", Params: params.PtraceDescriptor},
45+
Prctl: {Name: "prctl", Category: Process, Source: RawSyscallTracepoint, Description: "Performs a process-control operation", Params: params.PrctlDescriptor},
4346
}
4447

4548
// GetTypesInfo returns event types metadata.
4649
func GetTypesInfo() []Info {
47-
t := table[:]
50+
// work on a copy, otherwise the in-place deletion and sorting
51+
// would corrupt the table which is indexed by the event type
52+
t := slices.Clone(table[:])
4853
t = slices.DeleteFunc(t, func(info Info) bool {
4954
return info.Name == ""
5055
})

0 commit comments

Comments
 (0)