Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt perf package to our needs #1

Merged
merged 6 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add additional functions to Event
- OpenWithFlags() constructor, similar to Open() but allows to pass
  flags to perf_event_open(2).
- HasRecord() to be able to read a sample without blocking.
  • Loading branch information
adriansr committed Aug 22, 2019
commit 85d060a07b0800a8b0a432d953baa05363b63b48
6 changes: 6 additions & 0 deletions perf.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ func Open(a *Attr, pid, cpu int, group *Event) (*Event, error) {
return open(a, pid, cpu, group, 0)
}

// OpenWithFlags is like Open but allows to specify additional flags to be
// passed to perf_event_open(2).
func OpenWithFlags(a *Attr, pid, cpu int, group *Event, flags int) (*Event, error) {
return open(a, pid, cpu, group, flags)
}

// OpenCGroup is like Open, but activates per-container system-wide
// monitoring. If cgroupfs is mounted on /dev/cgroup, and the group to
// monitor is called "test", then cgroupfd must be a file descriptor opened
Expand Down
5 changes: 5 additions & 0 deletions record.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ again:
}
}

// HasRecord returns if there is a record available to be read from the ring.
func (ev *Event) HasRecord() bool {
return atomic.LoadUint64(&ev.meta.Data_head) != atomic.LoadUint64(&ev.meta.Data_tail)
}

// resetRing advances the read pointer to the write pointer to discard all the
// data in the ring. This is done when bogus data is read from the ring.
func (ev *Event) resetRing() {
Expand Down