Skip to content

Commit

Permalink
update error messages for hardware profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgesds committed Oct 24, 2021
1 parent 5a8f8c1 commit a56b59c
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions hardware_profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package perf

import (
"fmt"

"go.uber.org/multierr"
"golang.org/x/sys/unix"
)
Expand All @@ -20,70 +22,80 @@ func NewHardwareProfiler(pid, cpu int, opts ...int) (HardwareProfiler, error) {

cpuCycleProfiler, err := NewCPUCycleProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup CPU cycle profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_CPU_CYCLES] = cpuCycleProfiler
}

instrProfiler, err := NewInstrProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to CPU setup instruction profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_INSTRUCTIONS] = instrProfiler
}

cacheRefProfiler, err := NewCacheRefProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup cache ref profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_CACHE_REFERENCES] = cacheRefProfiler
}

cacheMissesProfiler, err := NewCacheMissesProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup cache misses profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_CACHE_MISSES] = cacheMissesProfiler
}

branchInstrProfiler, err := NewBranchInstrProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup branch instruction profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = branchInstrProfiler
}

branchMissesProfiler, err := NewBranchMissesProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup branch miss profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_BRANCH_MISSES] = branchMissesProfiler
}

busCyclesProfiler, err := NewBusCyclesProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup bus cycles profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_BUS_CYCLES] = busCyclesProfiler
}

stalledCyclesFrontProfiler, err := NewStalledCyclesFrontProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup stalled fronted cycles profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = stalledCyclesFrontProfiler
}

stalledCyclesBackProfiler, err := NewStalledCyclesBackProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup stalled backend cycles profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = stalledCyclesBackProfiler
}

refCPUCyclesProfiler, err := NewRefCPUCyclesProfiler(pid, cpu, opts...)
if err != nil {
e = multierr.Append(e, err)
e = multierr.Append(e,
fmt.Errorf("Failed to setup ref CPU cycles profiler: pid (%d) cpu (%d) %q", pid, cpu, err))
} else {
profilers[unix.PERF_COUNT_HW_REF_CPU_CYCLES] = refCPUCyclesProfiler
}
Expand Down

0 comments on commit a56b59c

Please sign in to comment.