Skip to content

Commit 5aed1e5

Browse files
authored
fix(ebpf): python backport fixes (#3268)
* fix(ebpf): fix glibc detection when the file name is libc-2.31.so instead of libc.so.6 * fix(ebpf): elf build id
1 parent e23c664 commit 5aed1e5

File tree

10 files changed

+46
-59
lines changed

10 files changed

+46
-59
lines changed

ebpf/Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GO ?= go
2-
RIDESHARE_REPO ?= korniltsev
3-
RIDESHARE="testdata/rideshare-flask-no-pip"
2+
RIDESHARE_REPO ?= pyroscope
3+
RIDESHARE=testdata/rideshare-flask-no-pip
44

55
ifeq ($(shell uname -s),Linux)
66
ifeq ($(shell uname -m),x86_64)
@@ -29,12 +29,12 @@ python/dwarfdump:
2929
git submodule update --init --recursive
3030

3131
echo "//go:build amd64 && linux" > python/python_offsets_gen_amd64.go
32-
go run cmd/python_dwarfdump/main.go $(shell find testdata/python-x64 -name libpy\*.so\*) \
32+
go run cmd/python_dwarfdump/main.go $(shell find testdata/python-x64 -name libpy\*.so\* | grep -v pyston) \
3333
$(shell find testdata/python-x64 | grep -E "/python3\\.[0-9]+") >> python/python_offsets_gen_amd64.go
3434
go fmt python/python_offsets_gen_amd64.go
3535

3636
echo "//go:build arm64 && linux" > python/python_offsets_gen_arm64.go
37-
go run cmd/python_dwarfdump/main.go $(shell find testdata/python-arm64 -name libpy\*.so\*) \
37+
go run cmd/python_dwarfdump/main.go $(shell find testdata/python-arm64 -name libpy\*.so\* | grep -v pyston) \
3838
$(shell find testdata/python-arm64 | grep -E "/python3\\.[0-9]+") >> python/python_offsets_gen_arm64.go
3939
go fmt python/python_offsets_gen_arm64.go
4040

@@ -104,4 +104,6 @@ rideshare/gen:
104104
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:3.10-alpine --build-arg="PYTHON_VERSION=3.10-alpine" $(RIDESHARE)
105105
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:3.11-alpine --build-arg="PYTHON_VERSION=3.11-alpine" $(RIDESHARE)
106106
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:3.12-alpine --build-arg="PYTHON_VERSION=3.12-alpine" $(RIDESHARE)
107-
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:3.13-rc-alpine --build-arg="PYTHON_VERSION=3.13-rc-alpine" $(RIDESHARE)
107+
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:3.13-rc-alpine --build-arg="PYTHON_VERSION=3.13-rc-alpine" $(RIDESHARE)
108+
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:ubuntu-20.04 --build-arg="BASE=ubuntu:20.04" --build-arg="FLASK_VERSION=3.0.3" -f $(RIDESHARE)/ubuntu.Dockerfile $(RIDESHARE)
109+
docker buildx build --platform=linux/amd64,linux/arm64 --push -t $(RIDESHARE_REPO)/ebpf-testdata-rideshare:ubuntu-22.04 --build-arg="BASE=ubuntu:22.04" --build-arg="FLASK_VERSION=3.0.3" -f $(RIDESHARE)/ubuntu.Dockerfile $(RIDESHARE)

ebpf/cmd/python_dwarfdump/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ var pythonFields = []dwarfdump.Need{
6666
{Name: "_typeobject", PrettyName: "PyTypeObject", Fields: []dwarfdump.NeedField{
6767
{"tp_name", "PyTypeObject_tp_name"},
6868
}},
69-
{Name: "PyThreadState", Fields: []dwarfdump.NeedField{
69+
{Name: "_ts", Fields: []dwarfdump.NeedField{
7070
{"frame", "PyThreadState_frame"},
7171
{"cframe", "PyThreadState_cframe"},
7272
{"current_frame", "PyThreadState_current_frame"},

ebpf/dwarfdump/dwarfdump.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"debug/dwarf"
55
"debug/elf"
66
"fmt"
7+
"os"
78
"reflect"
89
"strings"
910
)
@@ -193,6 +194,7 @@ type FieldDump struct {
193194
}
194195

195196
func Dump(elfPath string, fields []Need) []FieldDump {
197+
fmt.Fprintf(os.Stderr, "Dumping %s\n", elfPath)
196198
var err error
197199

198200
f, err := elf.Open(elfPath)

ebpf/python/procinfo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package python
33
import (
44
"bufio"
55
"fmt"
6+
"path/filepath"
67
"regexp"
78
"strconv"
89
"strings"
@@ -58,7 +59,7 @@ func GetProcInfo(s *bufio.Scanner) (ProcInfo, error) {
5859
strings.Contains(m.Pathname, "/lib/ld-musl-aarch64.so.1") {
5960
res.Musl = append(res.Musl, m)
6061
}
61-
if strings.HasSuffix(m.Pathname, "/libc.so.6") || strings.HasSuffix(m.Pathname, "/libc-2") {
62+
if strings.HasSuffix(m.Pathname, "/libc.so.6") || strings.HasPrefix(filepath.Base(m.Pathname), "libc-2.") {
6263
res.Glibc = append(res.Glibc, m)
6364
}
6465
}

ebpf/python/procinfo_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsysca
5656
info, err := GetProcInfo(bufio.NewScanner(bytes.NewReader([]byte(maps))))
5757
require.NoError(t, err)
5858
require.Nil(t, info.Musl)
59+
require.NotNil(t, info.Glibc)
5960
require.Equal(t, info.Version, Version{3, 6, 0})
6061
require.NotNil(t, info.PythonMaps)
6162
require.NotNil(t, info.LibPythonMaps)
@@ -116,6 +117,7 @@ ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsysca
116117
info, err = GetProcInfo(bufio.NewScanner(bytes.NewReader([]byte(maps))))
117118
require.NoError(t, err)
118119
require.NotNil(t, info.Musl)
120+
require.Nil(t, info.Glibc)
119121
require.Equal(t, info.Version, Version{3, 11, 0})
120122
require.NotNil(t, info.PythonMaps)
121123
require.NotNil(t, info.LibPythonMaps)
@@ -128,6 +130,7 @@ ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsysca
128130
info, err = GetProcInfo(bufio.NewScanner(bytes.NewReader([]byte(maps))))
129131
require.NoError(t, err)
130132
require.Nil(t, info.Musl)
133+
require.Nil(t, info.Glibc)
131134
require.Equal(t, info.Version, Version{3, 7, 0})
132135
require.NotNil(t, info.PythonMaps)
133136
require.Nil(t, info.LibPythonMaps)
@@ -160,6 +163,7 @@ fffff8c25000-fffff8c53000 rw-p 00000000 00:00 0 [stack]
160163
info, err = GetProcInfo(bufio.NewScanner(bytes.NewReader([]byte(maps))))
161164
require.NoError(t, err)
162165
require.Nil(t, info.Musl)
166+
require.NotNil(t, info.Glibc)
163167
require.Equal(t, info.Version, Version{3, 8, 0})
164168
require.Nil(t, info.PythonMaps)
165169
require.NotNil(t, info.LibPythonMaps)

ebpf/python/python_offsets_gen_amd64.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ebpf/python/python_offsets_gen_arm64.go

Lines changed: 4 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ebpf/python3_ebpf_expected.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
python3;server.py <module>;app.py Flask.run;serving.py run_simple;serving.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer._handle_request_noblock;socketserver.py BaseWSGIServer.process_request;socketserver.py BaseWSGIServer.finish_request;socketserver.py WSGIRequestHandler.__init__;serving.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle_one_request;serving.py NullCls.run_wsgi;serving.py execute;app.py Flask.__call__;app.py Flask.wsgi_app;app.py Flask.full_dispatch_request;app.py Flask.dispatch_request;server.py bike;bike.py order_bike;utility.py find_nearest_vehicle
2+
python3;server.py <module>;app.py Flask.run;serving.py run_simple;serving.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer._handle_request_noblock;socketserver.py BaseWSGIServer.process_request;socketserver.py BaseWSGIServer.finish_request;socketserver.py WSGIRequestHandler.__init__;serving.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle_one_request;serving.py NullCls.run_wsgi;serving.py execute;app.py Flask.__call__;app.py Flask.wsgi_app;app.py Flask.full_dispatch_request;app.py Flask.dispatch_request;server.py car;car.py order_car;utility.py find_nearest_vehicle
3+
python3;server.py <module>;app.py Flask.run;serving.py run_simple;serving.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer._handle_request_noblock;socketserver.py BaseWSGIServer.process_request;socketserver.py BaseWSGIServer.finish_request;socketserver.py WSGIRequestHandler.__init__;serving.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle_one_request;serving.py NullCls.run_wsgi;serving.py execute;app.py Flask.__call__;app.py Flask.wsgi_app;app.py Flask.full_dispatch_request;app.py Flask.dispatch_request;server.py car;car.py order_car;utility.py find_nearest_vehicle;utility.py check_driver_availability
4+
python3;server.py <module>;app.py Flask.run;serving.py run_simple;serving.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer.serve_forever;socketserver.py BaseWSGIServer._handle_request_noblock;socketserver.py BaseWSGIServer.process_request;socketserver.py BaseWSGIServer.finish_request;socketserver.py WSGIRequestHandler.__init__;serving.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle;server.py WSGIRequestHandler.handle_one_request;serving.py NullCls.run_wsgi;serving.py execute;app.py Flask.__call__;app.py Flask.wsgi_app;app.py Flask.full_dispatch_request;app.py Flask.dispatch_request;server.py scooter;scooter.py order_scooter;utility.py find_nearest_vehicle

ebpf/python_ebpf_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,28 @@ var pythonEBPFExpected []byte
2525
//go:embed python_ebpf_expected_3.11.txt
2626
var pythonEBPFExpected311 []byte
2727

28+
//go:embed python3_ebpf_expected.txt
29+
var python3EBPFExpected []byte
30+
2831
func TestEBPFPythonProfiler(t *testing.T) {
2932
var testdata = []struct {
3033
image string
3134
expected []byte
3235
}{
33-
{"korniltsev/ebpf-testdata-rideshare:3.8-slim", pythonEBPFExpected},
34-
{"korniltsev/ebpf-testdata-rideshare:3.9-slim", pythonEBPFExpected},
35-
{"korniltsev/ebpf-testdata-rideshare:3.10-slim", pythonEBPFExpected},
36-
{"korniltsev/ebpf-testdata-rideshare:3.11-slim", pythonEBPFExpected311},
37-
{"korniltsev/ebpf-testdata-rideshare:3.12-slim", pythonEBPFExpected311},
38-
{"korniltsev/ebpf-testdata-rideshare:3.13-rc-slim", pythonEBPFExpected311},
39-
{"korniltsev/ebpf-testdata-rideshare:3.8-alpine", pythonEBPFExpected},
40-
{"korniltsev/ebpf-testdata-rideshare:3.9-alpine", pythonEBPFExpected},
41-
{"korniltsev/ebpf-testdata-rideshare:3.10-alpine", pythonEBPFExpected},
42-
{"korniltsev/ebpf-testdata-rideshare:3.11-alpine", pythonEBPFExpected311},
43-
{"korniltsev/ebpf-testdata-rideshare:3.12-alpine", pythonEBPFExpected311},
44-
{"korniltsev/ebpf-testdata-rideshare:3.13-rc-alpine", pythonEBPFExpected311},
36+
{"pyroscope/ebpf-testdata-rideshare:3.8-slim", pythonEBPFExpected},
37+
{"pyroscope/ebpf-testdata-rideshare:3.9-slim", pythonEBPFExpected},
38+
{"pyroscope/ebpf-testdata-rideshare:3.10-slim", pythonEBPFExpected},
39+
{"pyroscope/ebpf-testdata-rideshare:3.11-slim", pythonEBPFExpected311},
40+
{"pyroscope/ebpf-testdata-rideshare:3.12-slim", pythonEBPFExpected311},
41+
{"pyroscope/ebpf-testdata-rideshare:3.13-rc-slim", pythonEBPFExpected311},
42+
{"pyroscope/ebpf-testdata-rideshare:3.8-alpine", pythonEBPFExpected},
43+
{"pyroscope/ebpf-testdata-rideshare:3.9-alpine", pythonEBPFExpected},
44+
{"pyroscope/ebpf-testdata-rideshare:3.10-alpine", pythonEBPFExpected},
45+
{"pyroscope/ebpf-testdata-rideshare:3.11-alpine", pythonEBPFExpected311},
46+
{"pyroscope/ebpf-testdata-rideshare:3.12-alpine", pythonEBPFExpected311},
47+
{"pyroscope/ebpf-testdata-rideshare:3.13-rc-alpine", pythonEBPFExpected311},
48+
{"pyroscope/ebpf-testdata-rideshare:ubuntu-20.04", python3EBPFExpected},
49+
{"pyroscope/ebpf-testdata-rideshare:ubuntu-22.04", python3EBPFExpected},
4550
}
4651

4752
const ridesharePort = "5000"

ebpf/symtab/elf/buildid.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (f *MMapedElfFile) GNUBuildID() (BuildID, error) {
9393
return BuildID{}, fmt.Errorf(".note.gnu.build-id is not a GNU build-id : %s", hex.EncodeToString(data))
9494
}
9595
rawBuildID := data[16:]
96-
if len(rawBuildID) != 20 && len(rawBuildID) != 8 { // 8 is xxhash, for example in Container-Optimized OS
96+
if len(rawBuildID) < 8 {
9797
return BuildID{}, fmt.Errorf(".note.gnu.build-id has wrong size %s : %s ", f.fpath, hex.EncodeToString(data))
9898
}
9999
buildIDHex := hex.EncodeToString(rawBuildID)

0 commit comments

Comments
 (0)