summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/ioriotng.go36
-rw-r--r--internal/types/types.go34
2 files changed, 37 insertions, 33 deletions
diff --git a/internal/ioriotng.go b/internal/ioriotng.go
index 94c8030..b189590 100644
--- a/internal/ioriotng.go
+++ b/internal/ioriotng.go
@@ -14,6 +14,7 @@ import (
"ioriotng/internal/debugfs"
"ioriotng/internal/flags"
"ioriotng/internal/tracepoints"
+ "ioriotng/internal/types"
bpf "github.com/aquasecurity/libbpfgo"
)
@@ -22,37 +23,6 @@ type BpfMapper interface {
String() string
}
-type openEvent struct {
- FD int32
- OpID int32
- TID uint32
- EnterTime uint64
- ExitTime uint64
- Filename [256]byte // TODO, use same value as in ioriot.bpf.h
- Comm [16]byte
-}
-
-func (e openEvent) String() string {
- filename := e.Filename[:]
- comm := e.Comm[:]
- duration := (e.ExitTime - e.EnterTime) / 1000000000000.0
- return fmt.Sprintf("%vms opId:%d tid:%d fd:%d filename:%s, comm:%s",
- duration, e.OpID, e.TID, e.FD, string(filename), string(comm))
-}
-
-type fdEvent struct {
- FD int32
- OpID int32
- TID uint32
- EnterTime uint64
- ExitTime uint64
-}
-
-func (e fdEvent) String() string {
- duration := (e.ExitTime - e.EnterTime) / 1000000000000.0
- return fmt.Sprintf("%vms opId:%d tid:%v fd:%v", duration, e.OpID, e.TID, e.FD)
-}
-
func resizeMap(module *bpf.Module, name string, size uint32) error {
m, err := module.GetMap("open_event_map")
if err != nil {
@@ -107,13 +77,13 @@ func Run(flags flags.Flags) {
go func() {
defer wg.Done()
- for ev := range listenToEvents[fdEvent](ctx, bpfModule, "fd_event_map") {
+ for ev := range listenToEvents[types.FdEvent](ctx, bpfModule, "fd_event_map") {
log.Println(ev)
}
}()
go func() {
defer wg.Done()
- for ev := range listenToEvents[openEvent](ctx, bpfModule, "open_event_map") {
+ for ev := range listenToEvents[types.OpenEvent](ctx, bpfModule, "open_event_map") {
log.Println(ev)
}
}()
diff --git a/internal/types/types.go b/internal/types/types.go
new file mode 100644
index 0000000..890891b
--- /dev/null
+++ b/internal/types/types.go
@@ -0,0 +1,34 @@
+package types
+
+import "fmt"
+
+type OpenEvent struct {
+ FD int32
+ OpID int32
+ TID uint32
+ EnterTime uint64
+ ExitTime uint64
+ Filename [256]byte // TODO, use same value as in ioriot.bpf.h
+ Comm [16]byte
+}
+
+func (e OpenEvent) String() string {
+ filename := e.Filename[:]
+ comm := e.Comm[:]
+ duration := (e.ExitTime - e.EnterTime) / 1000000000000.0
+ return fmt.Sprintf("%vms opId:%d tid:%d fd:%d filename:%s, comm:%s",
+ duration, e.OpID, e.TID, e.FD, string(filename), string(comm))
+}
+
+type FdEvent struct {
+ FD int32
+ OpID int32
+ TID uint32
+ EnterTime uint64
+ ExitTime uint64
+}
+
+func (e FdEvent) String() string {
+ duration := (e.ExitTime - e.EnterTime) / 1000000000000.0
+ return fmt.Sprintf("%vms opId:%d tid:%v fd:%v", duration, e.OpID, e.TID, e.FD)
+}