-
-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Profiling #1106
Comments
Right now that would be possible if you init the SDK manually. Enable Performance and Profiling directly on the Native SDKs, for example, Android. The same steps for iOS, would work for Android and iOS native code only, not in the Dart bits nor C/C++ code. |
Hey @marandaneto , I was talking to @vaind and he might take a look at this to see how hard/what options do we have. |
Hey @bruno-garcia @vaind are there any updates on this? |
@kahest no updates yet, just started looking into this recently |
This article by a Dart SDK developer gives some intro how profiling is implemented in the Dart VM and exposed via DevTools. TLDR:
Therefore, this looks like a dead end. I'll update here if I can find an alternative solution, e.g. isolate stacks sampling from dart directly. |
@vaind what if we propose to make this available on release builds under a build opt-in flag, the port is closed in this case. |
@marandaneto I've considered that too but I'm not sure it's feasible because of the VM service port being exposed to every app on the device. It doesn't really matter whether it's an opt-in at build time, you wouldn't want to distribute such an app, especially on mobile devices. |
@vaind that was my point, can we change this approach about the port? finding another way to consume the service without opening the port, or via dart-lang/sdk#37664 |
To send profiles, the SDK will need to update the way it sends/enriches events on Android. The Outbox sender opens the saved envelope and sends envelope items as individual envelopes, but profiles have to be ingested with Tx in one envelope. |
So apparently, native profilers should work with AOT compiled dart. Going to see if I can make it work with our existing native SDK profilers. See this thread on Discord
|
@vaind the Android profiler right now only profiled Java/Kotlin code, No native (C/C++) code, maybe the iOS one works though. |
Update: sentry-cocoa profiler seems to work, somewhat. In a flutter app on macOS, I've started a transaction in swift, than ran a heavy operation in dart and stopped the swift transaction afterwards. The profile is captured and after symbolication, it shows function names, albeit the line numbers are not available consistently... See sample profile. On the other hand, the CPU profiler is going to show work that is actually being executed, so in case of async-await, it may get more complicated to see what is actually going on. I'll have to devise a better testing app to evaluate that. |
After some testing, It seems like the native profiler could be the way to go, at least for iOS and macOS. |
@vaind not aware of any changes/bugs. |
OK, so this would definitely need more attention to get working properly. I'm not sure trying to investigate this deeply makes sense just yet, with other platforms not resolved yet. I'm thinking we should first make sure all other desired platforms can be supported, before the detailing work on iOS. WDYT @marandaneto ? Also, I understand the goal would be to support all platforms supported by Flutter. However, if we go the route of native profiling, that means the platforms would be evaluated & implemented one by one. Would that be acceptable? If so, what are the priorities for platform support and is there a hard stop if some specific platform cannot be supported? |
@vaind makes sense, I'd focus on iOS and Android first, most likely starting from iOS since the iOS profiler should work (as you stated with a few gotchas). I know this: https://developer.android.com/topic/performance/tracing/custom-events-native Wondering if the Android native profiler would work for Windows and Linux but that's definitely a stretch since we don't have the sentry-native SDK yet built-in in Sentry Flutter anyway. |
Good, my idea was to verify the feasibility of native profiling on Flutter with the android SDK (as you have mentioned, via sentry-native most likely). PoC would be enough IMO and then we can go on and finish iOS first before fully implementing Android. |
Some notes on Android profiling:
|
@vaind your best bet to find out which native profilers work well on Android - Native code/NDK (at runtime/low frequency/release mode) will be asking on the Android united slack community, there's a #ndk channel and some Googlers are there, including @DanAlbert which is one of the lead contributors on https://github.com/android/ndk If we can't use |
https://android.googlesource.com/platform/system/extras/+/refs/heads/main/simpleperf/doc/android_application_profiling.md
@vaind did you check the firefox profiler? https://profiler.firefox.com/docs/#/./guide-profiling-android-directly-on-device Edit: apparently simpleperf as well https://searchfox.org/mozilla-central/source/third_party/libwebrtc/tools_webrtc/android/profiling/perf_setup.sh |
I know nothing about Dart. |
Flutter apps written in Dart compiles to Native code so it's not really about Dart profilers but rather Android Profilers that are able to profile Native code and not only Java/Kotlin. |
OK so at least in errors, the issue of some stack frames not being symbolicated is due to dSYMs missing for the Flutter.framework (or FlutterMacOS.framework). They're currently not shipped with Flutter at the moment so the dart plugin won't upload them to Sentry and thus they can't be used for symbolication, see flutter/flutter#117404 (comment) |
@vaind we can probably make a flutter symbol server https://docs.sentry.io/platforms/unreal/data-management/debug-files/symbol-servers/ |
and the third one, IMO safer for long term maintenance, would be to update the flutter tool to include the dSYM together with the rest of the build output. The same applies to iOS, macOS and likely Android symbols. FYI, after downloading the dSYM manually and uploading it to sentry.io as a DIF, the issue stack trace now looks much better: |
@vaind totally agree but the issue is ~2y old already, not sure if this will ever be addressed. What we can do for now is also amend the docs and let people know that they can do this manually (via sentry-cli), so at least is documented as a limitation of our automatic approach (and linking to the original GH issue). |
I've filed a feature request for a new built-in Flutter symbol server, let's see if this is possible, and is less work/less to maintain than the other options. |
The additional issue with symbolication on iOS I'm having trouble with is: While symbolication works reasonable well, one function I've devised to actually produce a lot of load is getting multiple frames, with no line numbers present. I just can't seem to figure out what is the issue and why other frames in the stack trace do have the line number, even the caller Dart function which is the second in the stack... Maybe @Swatinem could help out here? I've uploaded the whole build folder with the debug symbols, the envelope with the captured profile and the profile as downloaded (symbolicated) from Sentry. |
@vaind I will be OOO until the 7th but feel free to ping @Swatinem on Discord |
It might be that the information is simply missing from the DWARF we generate. We emit just enough information to make meaningful stack traces, which means we don't emit any useful DWARF for the places which are not calls. So if you write something like this: void foo() {
for (var i = 0; i < N; i++) {
// Do some math without any calls.
}
} Then the best you can be get is that the time is spent in I suggest just looking at raw PCs that profiler has collected and then looking at the corresponding generated machine code & DWARF to see if this is indeed the case. |
Thanks Slava, I also suspect as much, just wasn't able to confirm with my limited knowledge of DWARF. I was hoping @Swatinem could have a look at some point. It's not a blocker really as it seems to be "just" the leaf function code. |
I’m stretched really thin these days, please ping me again next week :-) |
@Swatinem any chance you could have a look? The latest profile has even less info, probably inlined? |
Was looking at the DWARF, it is indeed reporting line 0, column 0 for the whole block of code that is hit by the profiler. Looking at the very latest profile / debug file you posted, indeed the DWARF only reports that as a single toplevel function, but it has a ton of line table entries from multiple files as well. So maybe the DWARF info for inlined functions is not being generated correctly. |
Description
Similar to https://docs.sentry.io/platforms/android/profiling/ but for Dart code
Relates issues on the Dart SDK dart-lang/sdk#3686, dart-lang/sdk#37664, dart-lang/sdk#50055, flutter/flutter#37204
The text was updated successfully, but these errors were encountered: