summaryrefslogtreecommitdiff
path: root/internal/flamegraph/recorder.go
blob: 432e50956b93ec785261f2712787af94662ae236 (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
package flamegraph

import "ior/internal/event"

// Recorder aggregates event pairs and writes them to the legacy .ior.zst format.
// Integration tests still use this artifact to assert trace output end-to-end.
type Recorder struct {
	name string
	data iorData
}

// NewRecorder creates a recorder for one trace run.
func NewRecorder(name string) *Recorder {
	return &Recorder{
		name: name,
		data: newIorData(),
	}
}

// AddPair folds one traced syscall pair into the aggregated output.
func (r *Recorder) AddPair(pair *event.Pair) {
	if r == nil || pair == nil {
		return
	}
	r.data.addEventPair(pair)
}

// Write persists the aggregated trace output to a .ior.zst file.
func (r *Recorder) Write() error {
	if r == nil {
		return nil
	}
	return r.data.serializeToFile(r.name)
}