No PGO profile raw file was found on Android

20 views
Skip to first unread message

maxwell1991

unread,
Dec 9, 2021, 3:18:59 PM12/9/21
to android-ndk

Hello, I try to use PGO for my native applications on Android, but I can not find PGO profile raw file. Here is what I do: 

The NDK Version is 22.1.7171670, Device API level is 30.
Adding -fprofile-generate to cpp flags.

externalNativeBuild { cmake { cppFlags "-std=c++14 -fprofile-generate " } }

Calling the __llvm_profile_write_file function before the end of workload.
However, after executing the app, no profile file named default_unique_id_0.profraw was found in /data/local/tmp on Android.
Although I set up LLVM_PROFILE_FILE env to /data/local/tmp, nothing happened.

Do I miss something? Looking forward to answering, thank you.

yu...@unity3d.com

unread,
Dec 10, 2021, 10:17:27 AM12/10/21
to android-ndk
When I tried using PGO (history here https://github.com/android/ndk/issues/1564), I found out calling __llvm_profile_write() with a writeable path works just fine. Writeable == something within your applications' files path, something like  /storage/emulated/0/Android/data/<packagename>/files.

enh

unread,
Dec 10, 2021, 2:31:28 PM12/10/21
to andro...@googlegroups.com, Pirama Arumuga Nainar
ah, thanks ... that probably explains what the submitter of https://github.com/android/ndk/issues/1622 (which i'm guessing is the same person as here) found confusing in the docs.

i'll update the docs to explicitly point out that /data/local/tmp isn't usually accessible.

+Pirama Arumuga Nainar --- can we just fix this in LLVM? if i'm understanding the docs right, they're implying that /data/local/tmp is the *default*[1], so there's already some Android-specific code here. can we just make it a bit cleverer? on recent versions of Android, $TMPDIR should be set correctly to a usable directory[2], so even if it's hard to do the perfect thing on old OS versions, it should be easy on new OS versions (and that shouldn't give _worse_ behavior on old OS versions).

____
1. tbh, the docs and source don't seem to match? the *source* seems to imply that you get a "default.profraw" file in the cwd, but the *docs* explicitly claim that it's in /data/local/tmp?
2. "you're welcome" :-)

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/78503996-6c41-4679-8209-dace5f09adb7n%40googlegroups.com.

enh

unread,
Dec 10, 2021, 3:07:46 PM12/10/21
to Pirama Arumuga Nainar, andro...@googlegroups.com


On Fri, Dec 10, 2021 at 12:01 PM Pirama Arumuga Nainar <pir...@google.com> wrote:


On Fri, Dec 10, 2021 at 11:31 AM enh <e...@google.com> wrote:
ah, thanks ... that probably explains what the submitter of https://github.com/android/ndk/issues/1622 (which i'm guessing is the same person as here) found confusing in the docs.

i'll update the docs to explicitly point out that /data/local/tmp isn't usually accessible.

+Pirama Arumuga Nainar --- can we just fix this in LLVM? if i'm understanding the docs right, they're implying that /data/local/tmp is the *default*[1], so there's already some Android-specific code here. can we just make it a bit cleverer? on recent versions of Android, $TMPDIR should be set correctly to a usable directory[2], so even if it's hard to do the perfect thing on old OS versions, it should be easy on new OS versions (and that shouldn't give _worse_ behavior on old OS versions).

https://source.android.com/devices/tech/perf/pgo describes how to use PGO for code in the platform image (target audience being an OEM or a vendor). 

(i don't think i have a single page on source.android.com that doesn't now contain text saying "if you're an _app_ developer ..." --- web searches don't distinguish well between whether you want s.a.c or d.a.c :-) )
 
In that case, the Android build system sets the default path to /data/local/tmp (https://android.googlesource.com/platform/build/soong/+/refs/heads/master/cc/pgo.go#42).

ah, *that's* where it's coming from. makes sense!
 
I think it makes sense to have LLVM default to $TMPDIR if $LLVM_PROFILE_FILE is empty.  I'll file a bug internally to track this.

awesome, thanks!

that should let you remove your line from the build system too ;-)
Reply all
Reply to author
Forward
0 new messages