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

import (
	"fmt"
)

type Counter struct {
	Count          uint64
	Duration       uint64
	DurationToPrev uint64
	Bytes          uint64 // Bytes transferred (only set for read/write/transfer syscalls)
}

func (c Counter) add(other Counter) Counter {
	c.Count += other.Count
	c.Duration += other.Duration
	c.DurationToPrev += other.DurationToPrev
	c.Bytes += other.Bytes

	return c
}

func (c Counter) ValueByName(name string) uint64 {
	switch name {
	case "count":
		return c.Count
	case "duration":
		return c.Duration
	case "durationToPrev":
		return c.DurationToPrev
	case "bytes":
		return c.Bytes
	default:
		panic(fmt.Sprintln("No", name, "in count record"))
	}
}