acln0 / perf

tentative golang.org/x/sys/unix/linux/perf package
30 stars 6 forks source link

Should perf.Tracepoint work as part of a group? #9

Closed pwaller closed 5 years ago

pwaller commented 5 years ago

I had a group filled with hardware counters, then I added a Tracepoint for sys_enter_write to the group. I always got zero for my tracepoint counter, even though I was not expecting this.

Subsequently, I made a group only containing tracepoint counters, but then I get:

perf: empty event group

Here's a reproducer:

main.go:

package main

import (
    "fmt"
    "log"
    "os"

    "acln.ro/perf"
)

func main() {
    var g perf.Group
    g.CountFormat = perf.CountFormat{}
    g.Options.ExcludeKernel = true
    g.Options.ExcludeHypervisor = true

    tp := perf.Tracepoint("syscalls", "sys_enter_write")
    g.Add(tp)

    counts, err := g.Open(perf.CallingThread, perf.AnyCPU)
    if err != nil {
        log.Fatal(err)
    }

    c, err := counts.MeasureGroup(func() {
        os.Stdout.WriteString("Hi\n")
    })
    if err != nil {
        log.Fatal(err)
    }
    for _, v := range c.Values {
        fmt.Println(v)
    }
}
pwaller commented 5 years ago

A couple of weird things about the above:

  1. That it let me add Tracepoints to the group and silently gave me a zero count, even though it actually wasn't working as intended.
  2. That I get an "empty group" even though I have added something.

I'm unsure at this point if this is a bug in the perf package or in my understanding, or both. But probably the user interface can be improved at least.

acln0 commented 5 years ago

https://github.com/acln0/perf/blob/master/group.go#L70 should happen before the len(g.attrs) check, so a misconfigured group due to e.g. lack of permissions doesn't look like an empty group. Investigating the matter of the empty counters now.

pwaller commented 5 years ago

@acln0 nailed it and let me know - the trace points are not being counted because I have g.Options.ExcludeKernel = true set :man_facepalming:. Unsetting this I get the counts.