summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/eventloop.go1
-rw-r--r--internal/flamegraph/iordata_test.go28
-rw-r--r--internal/ior.go19
3 files changed, 38 insertions, 10 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index 3b6ec47..94edb3b 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -317,7 +317,6 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) {
// TODO: name_to_handle_at
// TODO: mmap, msync...
// TODO: getcwd?
- // TODO: syslog(2) for auditd debugging
// TODO: sync_file_range
// TODO: https://man7.org/linux/man-pages/man2/io_uring_enter.2.html (already captured but without FDs)
diff --git a/internal/flamegraph/iordata_test.go b/internal/flamegraph/iordata_test.go
new file mode 100644
index 0000000..79fb75c
--- /dev/null
+++ b/internal/flamegraph/iordata_test.go
@@ -0,0 +1,28 @@
+package flamegraph
+
+import "testing"
+
+func TestAddPath(t *testing.T) {
+ iod := newIorData()
+ path := pathType("testPath")
+ traceId := traceIdType(1)
+ comm := commType("testComm")
+ pid := pidType(1234)
+ tid := tidType(5678)
+ flags := flagsType("O_RDWR")
+ cnt1 := counter{count: 1, duration: 1000, durationToPrev: 100}
+
+ iod.addPath(path, traceId, comm, pid, tid, flags, cnt1)
+
+ if iod.paths[path][traceId][comm][pid][tid][flags] != cnt1 {
+ t.Errorf("Expected counter %v, got %v", cnt1, iod.paths[path][traceId][comm][pid][tid][flags])
+ }
+ cnt2 := counter{count: 2, duration: 2000, durationToPrev: 200}
+
+ iod.addPath(path, traceId, comm, pid, tid, flags, cnt2)
+
+ resultCnt := cnt1.add(cnt2)
+ if iod.paths[path][traceId][comm][pid][tid][flags] != resultCnt {
+ t.Errorf("Expected counter %v, got %v", resultCnt, iod.paths[path][traceId][comm][pid][tid][flags])
+ }
+}
diff --git a/internal/ior.go b/internal/ior.go
index 3d6fd1e..c2f2f02 100644
--- a/internal/ior.go
+++ b/internal/ior.go
@@ -43,34 +43,34 @@ func attachTracepoints(bpfModule *bpf.Module) error {
return nil
}
-func Run() {
+func Run() error {
bpfModule, err := bpf.NewModuleFromFile("ior.bpf.o")
if err != nil {
- panic(err)
+ return err
}
defer bpfModule.Close()
if err := flags.Get().ResizeBPFMaps(bpfModule); err != nil {
- panic(err)
+ return err
}
if err := flags.Get().SetBPF(bpfModule); err != nil {
- panic(err)
+ return err
}
if err := bpfModule.BPFLoadObject(); err != nil {
- panic(err)
+ return err
}
if err := attachTracepoints(bpfModule); err != nil {
- panic(err)
+ return err
}
// 4096 channel size, minimises event drops
ch := make(chan []byte, 4096)
rb, err := bpfModule.InitRingBuf("event_map", ch)
if err != nil {
- panic(err)
+ return err
}
rb.Poll(300)
@@ -78,10 +78,10 @@ func Run() {
var cpuProfile, memProfile *os.File
if flags.Get().PprofEnable {
if cpuProfile, err = os.Create("ior.cpuprofile"); err != nil {
- panic(err)
+ return err
}
if memProfile, err = os.Create("ior.memprofile"); err != nil {
- panic(err)
+ return err
}
pprof.StartCPUProfile(cpuProfile)
} else {
@@ -118,4 +118,5 @@ func Run() {
totalDuration := time.Since(startTime)
<-pprofDone
fmt.Println("Good bye... (unloading BPF tracepoints will take a few seconds...) after", totalDuration)
+ return nil
}