summaryrefslogtreecommitdiff
path: root/internal/tui/eventstream/streamevent.go
blob: 9238a848c64f4a62f0d12c639c0d0e65a2bebc26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package eventstream

import (
	"time"

	"ior/internal/event"
	"ior/internal/types"
)

type StreamEvent struct {
	Seq        uint64
	TimeNs     uint64
	Syscall    string
	Comm       string
	PID        uint32
	TID        uint32
	FileName   string
	DurationNs uint64
	GapNs      uint64
	Bytes      uint64
	RetVal     int64
	IsError    bool
	FD         int32
}

func (e StreamEvent) SyscallValue() string {
	return e.Syscall
}

func (e StreamEvent) CommValue() string {
	return e.Comm
}

func (e StreamEvent) FileValue() string {
	return e.FileName
}

func (e StreamEvent) PIDValue() uint32 {
	return e.PID
}

func (e StreamEvent) TIDValue() uint32 {
	return e.TID
}

func (e StreamEvent) FDValue() int32 {
	return e.FD
}

func (e StreamEvent) LatencyValue() uint64 {
	return e.DurationNs
}

func (e StreamEvent) GapValue() uint64 {
	return e.GapNs
}

func (e StreamEvent) BytesValue() uint64 {
	return e.Bytes
}

func (e StreamEvent) ReturnValue() int64 {
	return e.RetVal
}

func (e StreamEvent) ErrorValue() bool {
	return e.IsError
}

// UnknownFD marks events that are not associated with a file descriptor.
const UnknownFD int32 = -1

func NewStreamEvent(seq uint64, pair *event.Pair) StreamEvent {
	e := StreamEvent{
		Seq:        seq,
		TimeNs:     pair.EnterEv.GetTime(),
		Syscall:    pair.EnterEv.GetTraceId().Name(),
		Comm:       pair.Comm,
		PID:        pair.EnterEv.GetPid(),
		TID:        pair.EnterEv.GetTid(),
		FileName:   pair.FileName(),
		DurationNs: pair.Duration,
		GapNs:      pair.DurationToPrev,
		Bytes:      pair.Bytes,
		FD:         UnknownFD,
	}
	if fd, ok := pair.FileDescriptor(); ok {
		e.FD = fd
	}

	if retEv, ok := pair.ExitEv.(*types.RetEvent); ok {
		e.RetVal = retEv.Ret
		e.IsError = retEv.Ret < 0
	}

	return e
}

// NewWarningEvent creates a synthetic stream row for non-fatal runtime warnings.
func NewWarningEvent(message string) StreamEvent {
	now := uint64(time.Now().UnixNano())
	return StreamEvent{
		Seq:      now,
		TimeNs:   now,
		Syscall:  "warning",
		Comm:     "ior",
		FileName: message,
		FD:       UnknownFD,
		RetVal:   -1,
		IsError:  true,
	}
}