Skip to content

Commit 685e06e

Browse files
authored
Merge pull request #88 from parca-dev/oom-log
oom log
2 parents ef3a1ef + 56b7fb5 commit 685e06e

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/klauspost/compress v1.18.0
1616
github.com/mdlayher/kobject v0.0.0-20200520190114-19ca17470d7d
1717
github.com/minio/sha256-simd v1.0.1
18-
github.com/parca-dev/oomprof v0.1.5-0.20250811212952-b45abb82a5fd
18+
github.com/parca-dev/oomprof v0.1.5-0.20250812163638-9a36e2d4a690
1919
github.com/peterbourgon/ff/v3 v3.4.0
2020
github.com/sirupsen/logrus v1.9.3
2121
github.com/stretchr/testify v1.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQ
169169
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
170170
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
171171
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
172-
github.com/parca-dev/oomprof v0.1.5-0.20250811212952-b45abb82a5fd h1:uHo+bScocZbyqOnH7FeynMvaK/Exk+QQGFn5dfI4TRU=
173-
github.com/parca-dev/oomprof v0.1.5-0.20250811212952-b45abb82a5fd/go.mod h1:+vw0+rZYq/rTVouF6G+/+Uol758EOkUINi8/8RXPvX0=
172+
github.com/parca-dev/oomprof v0.1.5-0.20250812163638-9a36e2d4a690 h1:LKaTgZjbkz7wxHYU5VMKZ655Cp3IfG9a4ttPWRtflvU=
173+
github.com/parca-dev/oomprof v0.1.5-0.20250812163638-9a36e2d4a690/go.mod h1:+vw0+rZYq/rTVouF6G+/+Uol758EOkUINi8/8RXPvX0=
174174
github.com/peterbourgon/ff/v3 v3.4.0 h1:QBvM/rizZM1cB0p0lGMdmR7HxZeI/ZrBWB4DqLkMUBc=
175175
github.com/peterbourgon/ff/v3 v3.4.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
176176
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

interpreter/oomwatcher/log.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2024 The Parca Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
12+
package oomwatcher // import "go.opentelemetry.io/ebpf-profiler/interpreter/oomwatcher"
13+
14+
import (
15+
"os"
16+
17+
"github.com/sirupsen/logrus"
18+
)
19+
20+
// Set this to true when debug env var is set.
21+
var development bool
22+
23+
func init() {
24+
_, dbgEnv := os.LookupEnv("OOM_DEBUG")
25+
development = dbgEnv
26+
}
27+
28+
// logf logs debugging as higher level so they stick out w/o
29+
// enabling debug firehose if LUA_DEBUG env var is set.
30+
func logf(format string, args ...interface{}) {
31+
if development {
32+
logrus.Infof(format, args...)
33+
} else {
34+
logrus.Debugf(format, args...)
35+
}
36+
}

interpreter/oomwatcher/oomwatcher.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"fmt"
88
"strings"
99

10-
log "github.com/sirupsen/logrus"
11-
1210
"github.com/parca-dev/oomprof/oomprof"
1311
"go.opentelemetry.io/ebpf-profiler/interpreter"
1412
"go.opentelemetry.io/ebpf-profiler/libpf"
@@ -35,20 +33,20 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
3533
if err != nil {
3634
// oomprof not initialized, OOM prof must be initialized early by the otel container
3735
// project so it can be wired up to a TraceReporter instance.
38-
log.Debugf("OOM watcher: oomprof not initialized, disabling OOM watching: %v", err)
36+
logf("oom: oomprof not initialized, disabling OOM watching: %v", err)
3937
return nil, nil
4038
}
4139

4240
file, err := info.GetELF()
4341
if err != nil {
44-
log.Debugf("OOM watcher: elf err, disabling OOM watching: %v", err)
42+
logf("oom: elf err, disabling OOM watching: %v", err)
4543
return nil, err
4644
}
4745

4846
// Check if this is a Go binary
4947
if !file.IsGolang() {
5048
if strings.Contains(info.FileName(), "oomprof") {
51-
log.Debugf("OOM watcher: not go, disabling OOM watching: %s", info.FileName())
49+
logf("oom: not go, disabling OOM watching: %s", info.FileName())
5250
}
5351
return nil, nil
5452
}
@@ -66,12 +64,12 @@ func Loader(_ interpreter.EbpfHandler, info *interpreter.LoaderInfo) (interprete
6664
}
6765

6866
if sym != nil {
69-
log.Debugf("OOM watcher: found mbuckets symbol (%v) in %s", sym, info.FileName())
67+
logf("oom: found mbuckets symbol (%v) in %s", sym, info.FileName())
7068
return &oomWatcherData{
7169
state: state,
7270
}, nil
7371
}
74-
log.Debugf("OOM watcher: no mbuckets symbol found %s", info.FileName())
72+
logf("oom: no mbuckets symbol found %s", info.FileName())
7573

7674
return nil, nil
7775
}
@@ -86,7 +84,7 @@ func (d *oomWatcherData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
8684

8785
// Only watch PIDs for Go processes with mbucket symbol
8886
if d.state != nil {
89-
log.Debugf("OOM watcher: watching PID %d", pid)
87+
logf("oom: watching PID %d", pid)
9088
if err := d.state.WatchPid(uint32(pid)); err != nil {
9189
if err == oomprof.ErrSelfWatch {
9290
return nil, nil
@@ -100,7 +98,7 @@ func (d *oomWatcherData) Attach(ebpf interpreter.EbpfHandler, pid libpf.PID,
10098

10199
// Detach stops watching the process.
102100
func (i *oomWatcherInstance) Detach(_ interpreter.EbpfHandler, pid libpf.PID) error {
103-
log.Debugf("OOM watcher: stopping watch for PID %d", pid)
101+
logf("oom: stopping watch for PID %d", pid)
104102
i.data.state.UnwatchPid(uint32(pid))
105103
return nil
106104
}

0 commit comments

Comments
 (0)