summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/eventfilter.go38
-rw-r--r--internal/eventloop.go32
-rw-r--r--internal/ior.go5
3 files changed, 53 insertions, 22 deletions
diff --git a/internal/eventfilter.go b/internal/eventfilter.go
index bb5cc0a..6975836 100644
--- a/internal/eventfilter.go
+++ b/internal/eventfilter.go
@@ -1,11 +1,9 @@
package internal
import (
- "bytes"
"fmt"
"ior/internal/flags"
"ior/internal/generated/types"
- "strings"
)
type eventFilter struct {
@@ -42,35 +40,35 @@ func newEventFilter(flags flags.Flags) *eventFilter {
}
func (ef *eventFilter) eventPair(ev *eventPair) bool {
- if ef.commFilterEnable && !strings.Contains(ev.comm, ef.commFilter) {
- return false
- }
- if ef.pathFilterEnable && !strings.Contains(ev.file.Name(), ef.pathFilter) {
- return false
- }
+ // if ef.commFilterEnable && !strings.Contains(ev.comm, ef.commFilter) {
+ // return false
+ // }
+ // if ef.pathFilterEnable && !strings.Contains(ev.file.Name(), ef.pathFilter) {
+ // return false
+ // }
return true
}
func (ef *eventFilter) openEvent(ev *types.OpenEvent) (*types.OpenEvent, bool) {
- if ef.commFilterEnable && !bytes.Contains(ev.Comm[:], ef.commFilterBytes[:]) {
- return ev, false
- }
- if ef.pathFilterEnable && !bytes.Contains(ev.Filename[:], ef.pathFilterBytes[:]) {
- return ev, false
- }
+ // if ef.commFilterEnable && !bytes.Contains(ev.Comm[:], ef.commFilterBytes[:]) {
+ // return ev, false
+ // }
+ // if ef.pathFilterEnable && !bytes.Contains(ev.Filename[:], ef.pathFilterBytes[:]) {
+ // return ev, false
+ // }
return ev, true
}
func (ef *eventFilter) pathEvent(ev *types.PathEvent) (*types.PathEvent, bool) {
- if ef.pathFilterEnable {
- return ev, bytes.Contains(ev.Pathname[:], ef.pathFilterBytes[:])
- }
+ // if ef.pathFilterEnable {
+ // return ev, bytes.Contains(ev.Pathname[:], ef.pathFilterBytes[:])
+ // }
return ev, true
}
func (ef *eventFilter) nameEvent(ev *types.NameEvent) (*types.NameEvent, bool) {
- if ef.pathFilterEnable {
- return ev, bytes.Contains(ev.Oldname[:], ef.pathFilterBytes[:]) || bytes.Contains(ev.Newname[:], ef.pathFilterBytes[:])
- }
+ // if ef.pathFilterEnable {
+ // return ev, bytes.Contains(ev.Oldname[:], ef.pathFilterBytes[:]) || bytes.Contains(ev.Newname[:], ef.pathFilterBytes[:])
+ // }
return ev, true
}
diff --git a/internal/eventloop.go b/internal/eventloop.go
index 4f0f7ca..f94ed6d 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -6,11 +6,14 @@ import (
"fmt"
"os"
"path/filepath"
+ "time"
"ior/internal/flags"
. "ior/internal/generated/types"
+ "ior/internal/tree"
)
+// TODO: Move in its own package?
type eventLoop struct {
flags flags.Flags
filter *eventFilter
@@ -18,6 +21,14 @@ type eventLoop struct {
files map[int32]file // Track all open files by file descriptor.
comms map[uint32]string // Program or thread name of the current Tid.
prevPairs map[uint32]*eventPair // Previous event (to calculate time differences between two events)
+ tree tree.Tree // Storing all paths in a tree structure for analysis
+
+ // Statistics
+ numTracepoints uint
+ numTracepointMismatches uint
+ numSyscalls uint
+ numSyscallsAfterFilter uint
+ startTime time.Time
}
func newEventLoop(flags flags.Flags) *eventLoop {
@@ -28,10 +39,25 @@ func newEventLoop(flags flags.Flags) *eventLoop {
files: make(map[int32]file),
comms: make(map[uint32]string),
prevPairs: make(map[uint32]*eventPair),
+ tree: tree.New(), // TODO: Implement
}
}
+// TODO: Could use the table from the gos project to display the stats here
+func (e *eventLoop) stats() string {
+ duration := time.Since(e.startTime)
+
+ return "Statistics:\n" +
+ fmt.Sprintf("\tduration:%v\n", duration) +
+ fmt.Sprintf("\ttracepoints:%v (%.2f/s) with %d mismatches (%.2f%%)\n", e.numTracepoints, float64(e.numTracepoints)/duration.Seconds(), e.numTracepointMismatches, (float64(e.numTracepointMismatches)/float64(e.numTracepoints))*100) +
+ fmt.Sprintf("\tsyscalls:%d (%.2f/s)\n",
+ e.numSyscalls, float64(e.numSyscalls)/duration.Seconds()) +
+ fmt.Sprintf("\tsyscalls after filter:%d (%.2f/s)\n",
+ e.numSyscallsAfterFilter, float64(e.numSyscallsAfterFilter)/duration.Seconds())
+}
+
func (e *eventLoop) run(rawCh <-chan []byte) {
+ e.startTime = time.Now()
if e.flags.PprofEnable {
fmt.Println("Profiling, press Ctrl+C to stop")
fmt.Println(eventStreamHeader)
@@ -45,8 +71,8 @@ func (e *eventLoop) run(rawCh <-chan []byte) {
ev.prevPair.recycle()
continue
}
+ e.numSyscallsAfterFilter++
}
- fmt.Println("Good bye")
}
func (e *eventLoop) events(rawCh <-chan []byte) <-chan *eventPair {
@@ -55,6 +81,7 @@ func (e *eventLoop) events(rawCh <-chan []byte) <-chan *eventPair {
go func() {
defer close(ch)
for raw := range rawCh {
+ e.numTracepoints++
switch EventType(raw[0]) {
case ENTER_OPEN_EVENT:
if ev, ok := e.filter.openEvent(NewOpenEvent(raw)); ok {
@@ -119,6 +146,9 @@ func (e *eventLoop) syscallExit(exitEv event, ch chan<- *eventPair) {
// enterEv:SYS_ENTER_OPEN => exitEv:SYS_EXIT_OPEN
if ev.enterEv.GetTraceId()-1 != ev.exitEv.GetTraceId() {
ev.tracepointMismatch = true
+ e.numTracepointMismatches++
+ } else {
+ e.numSyscalls++
}
switch v := ev.enterEv.(type) {
diff --git a/internal/ior.go b/internal/ior.go
index 2fbbb58..1f62eea 100644
--- a/internal/ior.go
+++ b/internal/ior.go
@@ -76,10 +76,13 @@ func Run(flags flags.Flags) {
pprof.StartCPUProfile(cpuProfile)
}
+ loop := newEventLoop(flags)
+
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
+ fmt.Println(loop.stats())
fmt.Println("Good bye...")
if flags.PprofEnable {
fmt.Println("Stoppig profiling, writing ior.cpuprofile and ior.memprofile")
@@ -89,5 +92,5 @@ func Run(flags flags.Flags) {
os.Exit(0)
}()
- newEventLoop(flags).run(ch)
+ loop.run(ch)
}