Re: [llvm-dev] FW: How to use -forder-file-instrumentation to generate order file for iOS Apps?

229 views
Skip to first unread message

Manman Ren via llvm-dev

unread,
Sep 23, 2021, 5:48:31 PM9/23/21
to llvm-dev, jac...@google.com
I don't think I wrote a doc on this. 'compiler-rt/test/profile/instrprof-order-file.test' shows how to use it, build the app with -forder-file-instrumentation and -mllvm -orderfile-write-mapping, then run the app, use the mapping file to decode the profile.

The profile should be in default.profraw.order. But you can change its name via:

- Writes to the file with the last name given to \a *
- __llvm_profile_set_filename(),
- or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
- or if that's not set, the last name set to INSTR_PROF_PROFILE_NAME_VAR,
- or if that's not set,  \c "default.profraw".

Hope this helps!
Manman

On Thu, Sep 23, 2021 at 2:45 PM Manman Ren <mr...@fb.com> wrote:

 

 

From: Manman Ren <mr...@fb.com>
Date: Thursday, September 23, 2021 at 2:20 PM
To: Jack Chen <jac...@google.com>, llvm...@lists.llvm.org <llvm...@lists.llvm.org>
Subject: Re: How to use -forder-file-instrumentation to generate order file for iOS Apps?

I don't think I wrote a doc on this. 'compiler-rt/test/profile/instrprof-order-file.test' shows how to use it, build the app with -forder-file-instrumentation and -mllvm -orderfile-write-mapping, then run the app, use the mapping file to decode the profile.

The profile should be in default.profraw.order. But you can change its name via:

- Writes to the file with the last name given to \a *
- __llvm_profile_set_filename(),
- or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
- or if that's not set, the last name set to INSTR_PROF_PROFILE_NAME_VAR,
- or if that's not set,  \c "default.profraw".

Hope this helps!
Manman

 

 

From: Jack Chen <jac...@google.com>
Date: Thursday, September 23, 2021 at 1:05 AM
To: llvm...@lists.llvm.org <llvm...@lists.llvm.org>
Cc: Manman Ren <mr...@fb.com>
Subject: How to use -forder-file-instrumentation to generate order file for iOS Apps?

Hello llvm developers,

 

I wonder how to use the flag -forder-file-instrumentation for iOS Apps written in objective-C and swift?

 

I enabled the flags -forder-file-instrumentation -mllvm -orderfile-write-mapping -fprofile-instr-generate when building my iOS App, which is written in objective-C and swift. 

After running the App on the iOS simulator on my macbook, a profraw.order file is generated in the simulator's folder. However, the file doesn't contain the correct contents. It contains too few bytes, also most data blobs are 32 bits (I believe the right format is 64-bits MD5), and many of them are duplicated. FWIW, here are the first few bytes:

00000000: 70aa cb11 0100 0000 f8ac cb11 0100 0000  p...............
00000010: 90ab cb11 0100 0000 58aa cb11 0100 0000  ........X.......
00000020: ffff ffff 0000 0000 0000 0000 0000 0000  ................
00000030: 0000 0000 0000 0000 ffff ffff 0000 0000  ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000  ................

I wonder if the feature -forder-file-instrumentation is supported for iOS Apps that are written in objective-C and swift?  

If yes, then I wonder what's the proper steps to use it?

 

Thank you very much for your time.

 

Regards,

Jack

 

Jack Chen via llvm-dev

unread,
Sep 23, 2021, 6:50:27 PM9/23/21
to llvm...@lists.llvm.org, mr...@fb.com

Manman Ren via llvm-dev

unread,
Sep 23, 2021, 6:50:50 PM9/23/21
to Jack Chen, llvm...@lists.llvm.org

I don't think I wrote a doc on this. 'compiler-rt/test/profile/instrprof-order-file.test' shows how to use it, build the app with -forder-file-instrumentation and -mllvm -orderfile-write-mapping, then run the app, use the mapping file to decode the profile.

The profile should be in default.profraw.order. But you can change its name via:

- Writes to the file with the last name given to \a *
- __llvm_profile_set_filename(),
- or if it hasn't been called, the \c LLVM_PROFILE_FILE environment variable,
- or if that's not set, the last name set to INSTR_PROF_PROFILE_NAME_VAR,
- or if that's not set,  \c "default.profraw".

Hope this helps!
Manman

 

 

From: Jack Chen <jac...@google.com>
Date: Thursday, September 23, 2021 at 1:05 AM
To: llvm...@lists.llvm.org <llvm...@lists.llvm.org>
Cc: Manman Ren <mr...@fb.com>
Subject: How to use -forder-file-instrumentation to generate order file for iOS Apps?

Jack Chen via llvm-dev

unread,
Sep 24, 2021, 6:12:19 AM9/24/21
to Manman Ren, llvm-dev
Thank you Manman!

I did try the feature with a C file and it worked well. I called __llvm_profile_set_filename() and __llvm_orderfile_dump() in the C file, built it with the flags, and ran the binary on Linux. After running, a profraw.order file was generated with correct contents.

However, I wasn't able to make it work for my iOS app - the profraw.order file is indeed generated, but it doesn't contain valid contents.

The major differences between them are: (1) the iOS app is written in objective c and swift, as opposed to C and (2)  The iOS app was run on iOS simulator, and the profraw.order data was collected on iOS simulator, as opposed to on linux. 

I wonder if you know what could be wrong? Maybe this feature isn't supported by objective c and swift, or perhaps it doesn't work on the iOS platform?

Thanks again! Really appreciate your help!

Regards,
Jack

Manman Ren via llvm-dev

unread,
Sep 24, 2021, 4:13:21 PM9/24/21
to Jack Chen, llvm-dev, ellis.sp...@gmail.com
We mainly use this for iOS, simulator should work and it should work for ObjectiveC and Swift.
I don't think we need -fprofile-instr-generate.

We are experimenting with a new instrumentation: https://lists.llvm.org/pipermail/llvm-dev/2021-June/151086.html in case you are interested.
+ Ellis

Manman

Jack Chen via llvm-dev

unread,
Sep 25, 2021, 2:24:45 AM9/25/21
to Manman Ren, llvm-dev, ellis.sp...@gmail.com
Hi Manman,

I tried again using XCode directly (previously I built the binary on linux, and then downloaded the binary to the iOS simulator for execution), and it works for me now.
Thank you so much for your help!

The new instrumentation looks interesting. I will look at that too.
Thanks again!

Regards,
Jack
Reply all
Reply to author
Forward
0 new messages