Skip to content

Commit

Permalink
profiler: Expose missing profile stacks count as a prometheus metric
Browse files Browse the repository at this point in the history
Signed-off-by: Sumera Priyadarsini <sylphrenadin@gmail.com>
  • Loading branch information
Sylfrena committed Feb 16, 2022
1 parent afbffb3 commit 54d8842
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cmd/parca-agent/main.go
Expand Up @@ -367,7 +367,7 @@ func main() {
ctx, cancel := context.WithCancel(ctx)
g.Add(func() error {
level.Debug(logger).Log("msg", "starting target manager")
return tm.Run(ctx, m.SyncCh())
return tm.Run(ctx, m.SyncCh(), reg)
}, func(error) {
cancel()
})
Expand Down
15 changes: 13 additions & 2 deletions pkg/profiler/profiler.go
Expand Up @@ -44,6 +44,10 @@ import (
"github.com/parca-dev/parca-agent/pkg/maps"
"github.com/parca-dev/parca-agent/pkg/perf"
)
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

//go:embed parca-agent.bpf.o
var bpfObj []byte
Expand All @@ -66,6 +70,7 @@ type CgroupProfiler struct {

mtx *sync.RWMutex
lastProfileTakenAt time.Time
missingStacks prometheus.Counter
lastError error

perfCache *perf.PerfCache
Expand All @@ -78,6 +83,7 @@ func NewCgroupProfiler(
debugInfoClient debuginfo.Client,
target model.LabelSet,
profilingDuration time.Duration,
reg prometheus.Registerer,
tmp string,
) *CgroupProfiler {
return &CgroupProfiler{
Expand All @@ -94,6 +100,11 @@ func NewCgroupProfiler(
tmp,
),
mtx: &sync.RWMutex{},
missingStacks: promauto.With(reg).NewCounter(
prometheus.CounterOpts{
Name: "parca_agent_profiler_missing_stacks",
Help: "Number of missing profile stacks",
}),
}
}

Expand Down Expand Up @@ -300,7 +311,7 @@ func (p *CgroupProfiler) profileLoop(ctx context.Context, now time.Time, counts,

stackBytes, err := stackTraces.GetValue(unsafe.Pointer(&userStackID))
if err != nil {
//profile.MissingStacks++
p.missingStacks.Inc()
continue
}

Expand All @@ -314,7 +325,7 @@ func (p *CgroupProfiler) profileLoop(ctx context.Context, now time.Time, counts,
if kernelStackID >= 0 {
stackBytes, err = stackTraces.GetValue(unsafe.Pointer(&kernelStackID))
if err != nil {
//profile.MissingStacks++
p.missingStacks.Inc()
continue
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/target/manager.go
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
profilestorepb "github.com/parca-dev/parca/gen/proto/go/parca/profilestore/v1alpha1"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"

"github.com/parca-dev/parca-agent/pkg/debuginfo"
Expand Down Expand Up @@ -62,21 +63,21 @@ func NewManager(
return m
}

func (m *Manager) Run(ctx context.Context, update <-chan map[string][]*Group) error {
func (m *Manager) Run(ctx context.Context, update <-chan map[string][]*Group, reg prometheus.Registerer) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case targetSets := <-update:
err := m.reconcileTargets(ctx, targetSets)
err := m.reconcileTargets(ctx, targetSets, reg)
if err != nil {
return err
}
}
}
}

func (m *Manager) reconcileTargets(ctx context.Context, targetSets map[string][]*Group) error {
func (m *Manager) reconcileTargets(ctx context.Context, targetSets map[string][]*Group, reg prometheus.Registerer) error {
m.mtx.Lock()
defer m.mtx.Unlock()

Expand All @@ -90,7 +91,7 @@ func (m *Manager) reconcileTargets(ctx context.Context, targetSets map[string][]
m.profilerPools[name] = pp
}

pp.Sync(targetSet)
pp.Sync(targetSet, reg)
}
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/target/profiler_pool.go
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/go-kit/log/level"
"github.com/parca-dev/parca-agent/pkg/profiler"
profilestorepb "github.com/parca-dev/parca/gen/proto/go/parca/profilestore/v1alpha1"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"

Expand Down Expand Up @@ -92,7 +93,7 @@ func (pp *ProfilerPool) Profilers() []Profiler {
return res
}

func (pp *ProfilerPool) Sync(tg []*Group) {
func (pp *ProfilerPool) Sync(tg []*Group, reg prometheus.Registerer) {
pp.mtx.Lock()
defer pp.mtx.Unlock()

Expand Down Expand Up @@ -132,6 +133,7 @@ func (pp *ProfilerPool) Sync(tg []*Group) {
pp.debugInfoClient,
newTarget.labelSet,
pp.profilingDuration,
reg,
pp.tmp,
)

Expand Down

0 comments on commit 54d8842

Please sign in to comment.