summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/ior/main.go18
-rw-r--r--internal/eventloop.go1
-rw-r--r--internal/flamegraph/iordata_test.go28
-rw-r--r--internal/ior.go19
4 files changed, 52 insertions, 14 deletions
diff --git a/cmd/ior/main.go b/cmd/ior/main.go
index f085c60..0f243f7 100644
--- a/cmd/ior/main.go
+++ b/cmd/ior/main.go
@@ -1,15 +1,25 @@
package main
import (
+ "flag"
"ior/internal"
- "ior/internal/flags"
+ "log"
"runtime"
)
+// main is the entry point for the application. It checks if the OS is Linux,
+// parses command-line flags, and runs the internal logic of the application.
func main() {
if runtime.GOOS != "linux" {
- panic("Unsupported OS")
+ log.Fatal("Unsupported OS")
+ }
+
+ // Parse command-line flags
+ flag.Parse()
+
+ // Run the internal logic of the application
+ if err := internal.Run(); err != nil {
+ log.Fatalf("Failed to run: %v", err)
}
- flags.Parse()
- internal.Run()
}
+
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
}