forked from open-telemetry/opentelemetry-ebpf-profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync from upstream (2024-12-03) (#5)
* Fix unwinding at syscall on aarch64 (open-telemetry#218) * Add PID as an attribute in each sample (open-telemetry#212) * ebpf: increase number of stack delta buckets (open-telemetry#231) Signed-off-by: Florian Lehner <florian.lehner@elastic.co> * reporter: use htlhash attribute for profiling specific hash (open-telemetry#236) Signed-off-by: Florian Lehner <florian.lehner@elastic.co> * reporter: drop fifo (open-telemetry#239) Signed-off-by: Florian Lehner <florian.lehner@elastic.co> * Drop more unused code (open-telemetry#240) * reporter: do not add empty attributes (open-telemetry#233) Signed-off-by: Florian Lehner <florian.lehner@elastic.co> * controller: fix reporter interval mix up with monitor interval (open-telemetry#242) * Extract reporter runloop (open-telemetry#228) Co-authored-by: Christos Kalkanis <christos.kalkanis@elastic.co> * Extract lookupcgroupv2 out of the otlp reporter (open-telemetry#227) * Add CPU id to trace and trace metadata (open-telemetry#249) * reporter: don't expire actively used executables (open-telemetry#247) * Remove legacy code from libpf.UnixTime64 (open-telemetry#252) * Turn kernel module file parsing errors into warnings (open-telemetry#255) Co-authored-by: Florian Lehner <florianl@users.noreply.github.com> * readatbuf: add missing check when reading from tail chunk (open-telemetry#259) * metrics: Don't send counters with 0 values (open-telemetry#246) --------- Signed-off-by: Florian Lehner <florian.lehner@elastic.co> Co-authored-by: umanwizard <brennan@umanwizard.com> Co-authored-by: Bhavna Jindal <bhavna.jindal@yahoo.com> Co-authored-by: Florian Lehner <florianl@users.noreply.github.com> Co-authored-by: Tim Rühsen <tim.ruhsen@elastic.co> Co-authored-by: Nayef Ghattas <nayef.ghattas@datadoghq.com> Co-authored-by: Damien Mathieu <42@dmathieu.com> Co-authored-by: Christos Kalkanis <christos.kalkanis@elastic.co> Co-authored-by: Tommy Reilly <gnurizen@gmail.com> Co-authored-by: Joel Höner <joel@elastic.co>
- Loading branch information
1 parent
0aeda32
commit 0d27b95
Showing
39 changed files
with
362 additions
and
632 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,5 @@ type Trace struct { | |
TID libpf.PID | ||
APMTraceID libpf.APMTraceID | ||
APMTransactionID libpf.APMTransactionID | ||
CPU int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package libpf // import "go.opentelemetry.io/ebpf-profiler/libpf" | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"regexp" | ||
|
||
lru "github.com/elastic/go-freelru" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
cgroupv2PathPattern = regexp.MustCompile(`0:.*?:(.*)`) | ||
) | ||
|
||
// LookupCgroupv2 returns the cgroupv2 ID for pid. | ||
func LookupCgroupv2(cgrouplru *lru.SyncedLRU[PID, string], pid PID) (string, error) { | ||
id, ok := cgrouplru.Get(pid) | ||
if ok { | ||
return id, nil | ||
} | ||
|
||
// Slow path | ||
f, err := os.Open(fmt.Sprintf("/proc/%d/cgroup", pid)) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer f.Close() | ||
|
||
var genericCgroupv2 string | ||
scanner := bufio.NewScanner(f) | ||
buf := make([]byte, 512) | ||
// Providing a predefined buffer overrides the internal buffer that Scanner uses (4096 bytes). | ||
// We can do that and also set a maximum allocation size on the following call. | ||
// With a maximum of 4096 characters path in the kernel, 8192 should be fine here. We don't | ||
// expect lines in /proc/<PID>/cgroup to be longer than that. | ||
scanner.Buffer(buf, 8192) | ||
var pathParts []string | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
pathParts = cgroupv2PathPattern.FindStringSubmatch(line) | ||
if pathParts == nil { | ||
log.Debugf("Could not extract cgroupv2 path from line: %s", line) | ||
continue | ||
} | ||
genericCgroupv2 = pathParts[1] | ||
break | ||
} | ||
|
||
// Cache the cgroupv2 information. | ||
// To avoid busy lookups, also empty cgroupv2 information is cached. | ||
cgrouplru.Add(pid, genericCgroupv2) | ||
|
||
return genericCgroupv2, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.