Skip to content

Commit 37fda0e

Browse files
committed
perf(event): Make event structure cache-friendly
Reorganize the fields in this structure to favor cache-optimal layout.
1 parent 7bdc3f4 commit 37fda0e

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

pkg/event/event.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555

5656
func (key MetadataKey) String() string { return string(key) }
5757

58-
// String turns kernel event's metadata into string.
58+
// String turns event's metadata into string.
5959
func (md Metadata) String() string {
6060
var sb strings.Builder
6161
for k, v := range md {
@@ -66,45 +66,49 @@ func (md Metadata) String() string {
6666

6767
// Event encapsulates event's state and provides a set of methods for
6868
// accessing and manipulating event parameters, process state, and other
69-
// metadata.
69+
// metadata. The fields in this structure are organized for cache-optimal
70+
// layout.
7071
type Event struct {
71-
// Seq is monotonically incremented kernel event sequence.
72+
// Seq is monotonically incremented event sequence.
7273
Seq uint64 `json:"seq"`
74+
// Timestamp represents the temporal occurrence of the event.
75+
Timestamp time.Time `json:"timestamp"`
7376
// PID is the identifier of the process that generated the event.
7477
PID uint32 `json:"pid"`
7578
// Tid is the thread identifier of the thread that generated the event.
7679
Tid uint32 `json:"tid"`
7780
// Evasions is the bitmask that stores detected evasion types on this event.
7881
Evasions uint32 `json:"-"`
79-
// Type is the internal representation of the event. This field should be ignored by serializers.
82+
// Type is the internal representation of the event. This field should be
83+
// ignored by serializers.
8084
Type Type `json:"-"`
8185
// CPU designates the processor logical core where the event was originated.
8286
CPU uint8 `json:"cpu"`
83-
// Name is the human friendly name of the kernel event.
87+
// WaitEnqueue indicates if this event should temporarily defer pushing to
88+
// the consumer output queue. This is usually required in event processors
89+
// to propagate certain events stored in processor's state when the related
90+
// event arrives.
91+
WaitEnqueue bool `json:"waitenqueue"`
92+
93+
// Name is the human friendly name of the event.
8494
Name string `json:"name"`
8595
// Category designates the category to which this event pertains.
8696
Category Category `json:"category"`
8797
// Description is the short explanation that describes the purpose of the event.
8898
Description string `json:"description"`
8999
// Host is the machine name that reported the generated event.
90100
Host string `json:"host"`
91-
// Timestamp represents the temporal occurrence of the event.
92-
Timestamp time.Time `json:"timestamp"`
93101
// Params stores the collection of event parameters.
94102
Params Params `json:"-"`
95103
// Metadata represents any tags that are meaningful to this event.
96104
Metadata Metadata `json:"metadata"`
97-
// mmux guards the metadata map
98-
mmux sync.RWMutex
99105
// PS represents process' metadata and its allocated resources such as handles, DLLs, etc.
100106
PS *pstypes.PS `json:"ps,omitempty"`
101107
// Callstack represents the call stack for the thread that generated the event.
102108
Callstack callstack.Callstack `json:"callstack"`
103-
// WaitEnqueue indicates if this event should temporarily defer pushing to
104-
// the consumer output queue. This is usually required in event processors
105-
// to propagate certain events stored in processor's state when the related
106-
// event arrives.
107-
WaitEnqueue bool `json:"waitenqueue"`
109+
110+
// mmux guards the metadata map
111+
mmux sync.RWMutex
108112
}
109113

110114
// String returns event's string representation.

0 commit comments

Comments
 (0)