KEMBAR78
Include debug symbols in the release for the lib by krk · Pull Request #1271 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

krk
Copy link
Contributor

@krk krk commented Apr 29, 2025

Motivation and context

It is useful to have the exact symbols corresponding to a release, for debugging purposes.

How has this been tested?

make
objdump -h build/lib/libasyncProfiler.so
objdump -h build/lib/libasyncProfiler.so.debug

Only libasyncProfiler.so.debug has the .debug* sections and libasyncProfiler.so retains symbols.

Sample sizes:

599K libasyncProfiler.so
4.0M libasyncProfiler.so.debug

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@krk
Copy link
Contributor Author

krk commented Apr 29, 2025

Unrelated failure:

FAIL [1/71] AllocTests.alloc took 11.187 s
java.util.concurrent.TimeoutException: Child process has not exited
	at one.profiler.test.TestProcess.waitForExit(TestProcess.java:297)
	at one.profiler.test.TestProcess.profile(TestProcess.java:320)
	at one.profiler.test.TestProcess.profile(TestProcess.java:302)
	at test.alloc.AllocTests.alloc(AllocTests.java:23)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at one.profiler.test.Runner.run(Runner.java:1[28](https://github.com/async-profiler/async-profiler/actions/runs/14728737409/job/41337688736?pr=1271#step:8:29))
	at one.profiler.test.Runner.main(Runner.java:188)

Makefile Outdated
CXXFLAGS=-O3 -fno-exceptions -fno-omit-frame-pointer -fvisibility=hidden -std=c++11 $(CXXFLAGS_EXTRA)
CPPFLAGS=
CXXFLAGS=-O3 -fno-exceptions -fno-omit-frame-pointer -fvisibility=hidden -std=c++11 $(CXXFLAGS_EXTRA)
LIB_PROFILER_CXXFLAGS=$(CXXFLAGS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have many variables with flags, can we do without another one?
Can't we just add an option to CXXFLAGS conditionally?

Makefile Outdated
endif

ifeq ($(OS_TAG),linux)
$(STRIP) --only-keep-debug $@ -o $@.debug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does .debug file get in the release package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not. What's the purpose of having a separate .debug file then? The idea was to keep release package small, but provide debuginfo in a separate package.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the idea was to keep the .so binary small, will provide in a separate package.

Makefile Outdated
endif

ifeq ($(OS_TAG),linux)
$(STRIP) --only-keep-debug $@ -o $@.debug
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not. What's the purpose of having a separate .debug file then? The idea was to keep release package small, but provide debuginfo in a separate package.

Makefile Outdated
endif

ifeq ($(OS_TAG),linux)
CXXFLAGS += -ggdb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already ifeq ($(OS),Darwin) branch above that sets CXXFLAGS depending on a platform, should we move it there?

Makefile Outdated
$(STRIP) --only-keep-debug $@ -o build/sym/$(@F).debug
$(STRIP) -g $@
$(OBJCOPY) --add-gnu-debuglink=build/sym/$(@F).debug $@
endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it the right place to extract debuginfo? I think, for development purposes, one binary with debug symbols is more convenient; we just do redundant steps here. Should we strip binaries at the packaging step instead?

esac
echo "archive=$(basename $(find . -type f -iname "async-profiler-*" ))" >> $GITHUB_OUTPUT
echo "archive=$(find . -type f -name "async-profiler-*" -not -name "*-sym*" -exec basename {} \; || echo "")" >> $GITHUB_OUTPUT
echo "sym_archive=$(find . -type f -name "async-profiler-*-sym*" -exec basename {} \; | awk '{print; exit} END{if(NR==0) print "IGNORE"}')" >> $GITHUB_OUTPUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files were found with the provided path: IGNORE.

Isn't there a less tricky way to skip macOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github actions step did not accept empty string as a valid value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will skip with an "is macos" check.

Makefile Outdated
Comment on lines 12 to 13
SYM_PACKAGE_NAME=$(PACKAGE_NAME)-sym
SYM_PACKAGE_DIR=$(PACKAGE_DIR)-sym
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a common naming convention? I saw -debug or -debuginfo, but not -sym.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to -debug.

macos*)
brew install gcovr
make COMMIT_TAG=$HASH FAT_BINARY=true release coverage -j
echo "debug_archive=UNSUPPORTED" >> $GITHUB_OUTPUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be a condition in the "Upload debug info" step instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upload debug info fails if debug_archive is not set or is set to an empty string - or I don't understand the question.

Copy link
Member

@apangin apangin May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question is whether we can skip upload step altogether on macOS instead of uploading a dummy archive? Doesn't if: work for steps?

Makefile Outdated
.PHONY: all jar release build-test test clean coverage clean-coverage build-test-java build-test-cpp build-test-libs build-test-bins test-cpp test-java check-md format-md

all: build/bin build/lib build/$(LIB_PROFILER) build/$(ASPROF) jar build/$(JFRCONV) build/$(ASPROF_HEADER)
all: build/bin build/lib build/debug build/$(LIB_PROFILER) build/$(ASPROF) jar build/$(JFRCONV) build/$(ASPROF_HEADER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is build/debug still used?

Copy link
Contributor Author

@krk krk May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this creates the folder via

build/%:
	mkdir -p $@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is my question. make creates an empty build/debug directory, and I'm not sure why.

Makefile Outdated

$(PACKAGE_DIR): all LICENSE README.md
$(PACKAGE_DIR): all LICENSE README.md build/$(LIB_PROFILER_DEBUG)
rm -rf $@ || :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why || :? rm -rf does not fail in case of missing file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, removing.

Makefile Outdated
Comment on lines 207 to 209
# To make building debug symbols idempotent, a rebuild of $(LIB_PROFILER) is required.
# Remove stamp file to ensures $(LIB_PROFILER) rule re-runs if needed after this rule modifies it (strip -g).
rm -f build/$(LIB_STAMP)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand this complication. Updating build/$(LIB_PROFILER) in place doesn't seem a good idea, can we only update it in a package dir?

If it helps to keep things simpler, we can eliminate separate rules for $(DEBUG_PACKAGE_DIR) and $(LIB_PROFILER_DEBUG) and always build debug package under $(PACKAGE_NAME).tar.gz rule.

@krk
Copy link
Contributor Author

krk commented May 6, 2025

Unrelated test failure:

 FAIL [1/74] AllocTests.alloc took 7.224 s
java.lang.AssertionError
	at test.alloc.AllocTests.alloc(AllocTests.java:24)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
INFO: Running AllocTests.allocTotal...
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at one.profiler.test.Runner.run(Runner.java:128)
	at one.profiler.test.Runner.main(Runner.java:188)

@apangin apangin merged commit b3907b4 into async-profiler:master May 6, 2025
30 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants