Skip to content

Commit

Permalink
Replace custom debugging technique (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl authored Jun 27, 2024
1 parent 9a7f99b commit 912bef3
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 172 deletions.
4 changes: 4 additions & 0 deletions cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
tracer.ProbabilisticThresholdMax-1, tracer.ProbabilisticThresholdMax-1)
probabilisticIntervalHelp = "Time interval for which probabilistic profiling will be " +
"enabled or disabled."
pprofHelp = "Listening address (e.g. localhost:6060) to serve pprof information."
)

// Variables for command line arguments
Expand All @@ -92,6 +93,7 @@ var (
argMapScaleFactor uint
argProbabilisticThreshold uint
argProbabilisticInterval time.Duration
argPprofAddr string

// "internal" flag variables.
// Flag variables that are configured in "internal" builds will have to be assigned
Expand Down Expand Up @@ -131,6 +133,8 @@ func parseArgs() error {

fs.UintVar(&argProjectID, "project-id", 1, projectIDHelp)

fs.StringVar(&argPprofAddr, "pprof", "", pprofHelp)

// Using a default value here to simplify OTEL review process.
fs.StringVar(&argSecretToken, "secret-token", "abc123", secretTokenHelp)

Expand Down
20 changes: 13 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"runtime"
"time"

//nolint:gosec
_ "net/http/pprof"

"github.com/elastic/otel-profiling-agent/containermetadata"
"github.com/elastic/otel-profiling-agent/vc"
"golang.org/x/sys/unix"
Expand All @@ -33,8 +37,6 @@ import (
"github.com/elastic/otel-profiling-agent/tracer"

log "github.com/sirupsen/logrus"

"github.com/elastic/otel-profiling-agent/memorydebug"
)

// Short copyright / license text for eBPF code
Expand Down Expand Up @@ -122,6 +124,15 @@ func mainWithExitCode() exitCode {
unix.SIGINT, unix.SIGTERM, unix.SIGABRT)
defer mainCancel()

if argPprofAddr != "" {
go func() {
//nolint:gosec
if err = http.ListenAndServe(argPprofAddr, nil); err != nil {
log.Errorf("Serving pprof on %s failed: %s", argPprofAddr, err)
}
}()
}

// Sanity check for probabilistic profiling arguments
if argProbabilisticInterval < 1*time.Minute || argProbabilisticInterval > 5*time.Minute {
log.Error("Invalid argument for probabilistic-interval: use " +
Expand All @@ -145,11 +156,6 @@ func mainWithExitCode() exitCode {
log.Infof("Starting OTEL profiling agent %s (revision %s, build timestamp %s)",
vc.Version(), vc.Revision(), vc.BuildTimestamp())

// Enable dumping of full heaps if the size of the allocated Golang heap
// exceeds 150m, and start dumping memory profiles when the heap exceeds
// 250m (only in debug builds, go build -tags debug).
memorydebug.Init(1024*1024*250, 1024*1024*150)

if !argNoKernelVersionCheck {
var major, minor, patch uint32
major, minor, patch, err = tracer.GetCurrentKernelVersion()
Expand Down
11 changes: 0 additions & 11 deletions memorydebug/README.md

This file was deleted.

113 changes: 0 additions & 113 deletions memorydebug/memorydebug_debug.go

This file was deleted.

16 changes: 0 additions & 16 deletions memorydebug/memorydebug_release.go

This file was deleted.

19 changes: 0 additions & 19 deletions memorydebug/memorydebug_test.go

This file was deleted.

3 changes: 0 additions & 3 deletions processmanager/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/elastic/otel-profiling-agent/libpf"
"github.com/elastic/otel-profiling-agent/libpf/pfelf"
"github.com/elastic/otel-profiling-agent/lpm"
"github.com/elastic/otel-profiling-agent/memorydebug"
"github.com/elastic/otel-profiling-agent/proc"
"github.com/elastic/otel-profiling-agent/process"
eim "github.com/elastic/otel-profiling-agent/processmanager/execinfomanager"
Expand Down Expand Up @@ -455,8 +454,6 @@ func (pm *ProcessManager) synchronizeMappings(pr process.Process,

// Add the new ELF mappings
for _, mapping := range mpAdd {
// Output memory usage in debug builds.
memorydebug.DebugLogMemoryUsage()
pm.processNewExecMapping(pr, mapping)
}

Expand Down
3 changes: 0 additions & 3 deletions tracehandler/tracehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/elastic/otel-profiling-agent/containermetadata"
"github.com/elastic/otel-profiling-agent/host"
"github.com/elastic/otel-profiling-agent/libpf"
"github.com/elastic/otel-profiling-agent/memorydebug"
"github.com/elastic/otel-profiling-agent/reporter"
"github.com/elastic/otel-profiling-agent/util"
)
Expand Down Expand Up @@ -208,8 +207,6 @@ func Start(ctx context.Context, containerMetadataHandler containermetadata.Handl
case <-ctx.Done():
return
}
// Output memory usage in debug builds.
memorydebug.DebugLogMemoryUsage()
}
}()

Expand Down

0 comments on commit 912bef3

Please sign in to comment.