dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.57k forks source link

Make `dart build` / `dart compile exe` / `dart compile aot-snapshot` produce code that can be profiled with native profilers #54254

Open mkustermann opened 11 months ago

mkustermann commented 11 months ago

By default our AOT compiler (gen_snapshot) emits static symbols (that users can, if they want to, strip). Though that's not sufficient for native profiling tools to work properly:

The dart build must have (@dcharkes ?) logic to find assembler/compiler/linker installed on the system (as it passes paths to them to native asset build scripts). Could we use that and make the above tools by-default, if system-installed tools are available, produce dylib / .so / .dll files with symbols by using --snapshot-kind=app-aot-assembly and then producing the shared library?

If not by default, can we at least have a way for users to opt into the assembly behavior?

For context: See https://github.com/dart-lang/sdk/issues/54207

/cc @sstrickl @dcharkes

dcharkes commented 11 months ago

That would be lovely! I've always been compiling and running manually with --generate-perf-events-symbols to ensure I get both the Dart and C++ symbols.

The dart build must have (@dcharkes ?) logic to find assembler/compiler/linker installed on the system (as it passes paths to them to native asset build scripts).

No, only Flutter passes the assembler/compiler/linker. When invoking native asset builds from Dart, it's empty. The native_toolchain_c package used inside the build.dart script has the logic for discovering the native compiler.

Since native_toolchain_c is already being DEPSed into the SDK, we could opt to use it if it's available. But we should probably have a discussion on a product level whether we want to ship a C compiler of have a dart doctor that can tell you if you have a C compiler etc. cc @mit-mit

fzyzcjy commented 11 months ago

P.S. I am indeed using dart build because flutter_rust_bridge has some build.dart to compile the accompany Rust code. Thus though #54207 workaround works, I am looking forward to this feature!

mkustermann commented 11 months ago

Since native_toolchain_c is already being DEPSed into the SDK, we could opt to use it if it's available. But we should probably have a discussion on a product level whether we want to ship a C compiler of have a dart doctor that can tell you if you have a C compiler etc. cc @mit-mit

Well, it can transparently fallback to the current solution (ELF writer & ELF loader) if it's not available. It may be sufficient to check whether gcc or clang is available, try using it and if it fails falling back to current behavior. (possibly emitting a note about it)