Skip to content

Commit 765bab0

Browse files
committed
moved biggestbinarysize logic from reporter/symbol/elf.go to reporter/symbol_uploader.go
1 parent ee10a57 commit 765bab0

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

reporter/symbol/elf.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"os"
1212
"runtime"
13-
"sync/atomic"
1413

1514
log "github.com/sirupsen/logrus"
1615
"go.opentelemetry.io/ebpf-profiler/libpf"
@@ -125,19 +124,6 @@ func (e *Elf) Close() {
125124
}
126125
}
127126

128-
var BiggestBinarySize int64
129-
130-
func updateBiggestBinarySize(size int64) {
131-
for {
132-
current := atomic.LoadInt64(&BiggestBinarySize)
133-
if current >= size {
134-
break
135-
}
136-
if atomic.CompareAndSwapInt64(&BiggestBinarySize, current, size) {
137-
break
138-
}
139-
}
140-
}
141127

142128
// GetSize returns the size of the elf file or data it contains.
143129
// It will return 0 if the size can't be retrieved.
@@ -161,8 +147,6 @@ func (e *Elf) GetSize() int64 {
161147
size = fi.Size()
162148
}
163149

164-
updateBiggestBinarySize(size)
165-
166150
return size
167151
}
168152

reporter/symbol_uploader.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type DatadogSymbolUploader struct {
7777
retrievalQueue chan *reporter.ExecutableMetadata
7878
pipeline pipeline.Pipeline[*reporter.ExecutableMetadata]
7979
mut sync.Mutex
80+
biggestBinarySize int64
8081
}
8182

8283
type goPCLnTabDump struct {
@@ -449,6 +450,18 @@ func newSymbolUploadRequestMetadata(e *symbol.Elf, symbolSource symbol.Source, p
449450
}
450451
}
451452

453+
func (d *DatadogSymbolUploader) updateBiggestBinarySize(size int64) {
454+
for {
455+
current := atomic.LoadInt64(&d.biggestBinarySize)
456+
if current >= size {
457+
break
458+
}
459+
if atomic.CompareAndSwapInt64(&d.biggestBinarySize, current, size) {
460+
break
461+
}
462+
}
463+
}
464+
452465
func (d *DatadogSymbolUploader) createSymbolFile(ctx context.Context, e *symbol.Elf) (*os.File, error) {
453466
symbolFile, err := os.CreateTemp("", "objcopy-debug")
454467
if err != nil {
@@ -481,7 +494,14 @@ func (d *DatadogSymbolUploader) createSymbolFile(ctx context.Context, e *symbol.
481494
sectionsToKeep = e.GetSectionsRequiredForDynamicSymbols()
482495
}
483496

497+
d.updateBiggestBinarySize(e.GetSize())
484498
err = CopySymbols(ctx, elfPath, symbolFile.Name(), goPCLnTabInfo, sectionsToKeep, d.compressDebugSections)
499+
500+
var exitError *exec.ExitError
501+
if errors.As(err, &exitError) && exitError.ExitCode() == -1 { // killed by signal
502+
return nil, fmt.Errorf("failed to copy symbols: got killed. Consider increasing memory limits to at least %v (biggest uncompressed elf file size found)", atomic.LoadInt64(&d.biggestBinarySize))
503+
}
504+
485505
if err != nil {
486506
return nil, fmt.Errorf("failed to copy symbols: %w", err)
487507
}
@@ -590,7 +610,7 @@ func CopySymbols(ctx context.Context, inputPath, outputPath string, goPCLnTabInf
590610
if err := cmd.Wait(); err != nil {
591611
var ExitError *exec.ExitError
592612
if errors.As(err, &ExitError) && ExitError.ExitCode() == -1 { // killed by signal
593-
return fmt.Errorf("got killed. Consider increasing memory limits to at least %v (biggest uncompressed elf file size found)", atomic.LoadInt64(&symbol.BiggestBinarySize))
613+
return ExitError
594614
}
595615
return fmt.Errorf("failed to extract debug symbols: %w", cleanCmdError(err))
596616
}

0 commit comments

Comments
 (0)