Profiling nexe build

271 views
Skip to first unread message

Amol Wagh

unread,
Jan 21, 2021, 2:40:24 PMJan 21
to Native-Client-Discuss
Hello All,

We have a chrome extension written in C++ and Javascript. Recently, we started migrating the extension to make use of WebAssembly instead of NaCl. For that, we used Emscripten compiler v2.0.7 to compile the C++ code. Without modifying the C++ code and using the same optimisation level during compilation, we found that WebAssembly build is slower than the NaCl build.

To address the performance issue, I wanted to compare the profiling (Instrumentation) result of both the builds using Chrome's Developer Tools. I could gather the profiling data for WebAssembly build. However, I am unable to do the same for NaCl build.
For reference, I have attached WebAssembly profiling result.

Can someone guide me about how to do profiling for NaCl build ? Which flags should be used during compilation and/or at linking stage ? And which tool should be used to do the actual profiling ?

The C++ code is compiled using `pnacl-clang++` compiler. Later `pnacl-transalte` is used to generate the .nexe file. (x86_64 arch)

OS and Compiler details are as follows.
NaCl SDK having `Pepper 50`
Emscripten SDK version 2.0.7
Ubuntu 18.04.5 LTS
Chrome version 86.0.4240.75
Processor : Intel® Core™ i5-5200U CPU @ 2.20GHz × 4


This e-mail, including any attached files, may contain confidential and privileged information for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.



qo_point_wasm_profiling.png

Derek Schuff

unread,
Jan 21, 2021, 2:59:42 PMJan 21
to native-cli...@googlegroups.com
Hi Amol,
Unfortunately profiling NaCl isn't nearly as convenient as profiling JS and wasm. Because NaCl isn't integrated into the JS engine the browser devtools can't give you this information. It is possible to use system tools such as Linux perf or oprofile to sample the NaCl process. If you do this you'll get a report that won't be correctly symbolized because the function addresses used at runtime don't match the addresses in the binary file. At runtime each function address is added the sandbox base address (which is different for every run). But when the NaCl module loads, the loader prints the base address to stdout (which you can see if you launch chrome from the console). So you can take your unsymbolized profile output and subtract that base address from each code address and get usable profile information (e.g. you can do manual lookups or write postprocessing scripts, with tools such as addr2line, objdump, and nm that come with the NaCl SDK). here is an example of such a script we wrote a long time ago for use with Linux oprofile.

There are of course also plenty of ways to try to improve the performance of WebAssembly applications. To start with, you might try adding an optimization flag such as -O3 to your linker command line to enable post-link optimizations (build systems generally don't do this by default). You could also use link-time optimization (LTO) by additionally adding -flto to your compiler command line (PNaCl does this by default but emscripten does not).
Since your target is Chrome, you might also try enabling support for the wasm features that emscripten doesn't turn on by default (e.g. -mnontrapping-fptoint at compile time, -s WASM_BIGINT=1 at link time). There is some documentation and you can also ask for advice on the emscripten mailing list.

Best,
-Derek

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/native-client-discuss/ebad990c-950d-42b8-9676-cd127551f742n%40googlegroups.com.

Amol Wagh

unread,
Jan 21, 2021, 6:57:34 PMJan 21
to Native-Client-Discuss
Hello Derek,

Thank you so much for the reply, I really appreciate the help.

Profiling nexe :
As suggested I will use the `oprofile` to profile the NaCl build. However, I have few more questions regarding the procedure. It will be a great help for me if you could answer those, as I couldn't find any documentation with respect to NaCl.
1. Do I need to use any special flag (e.g. `gprof` requires `pg`) during compilation? Shall I use debug build?
2. What flag/s need to pass to Chrome during launching?
3. As mentioned here, the `operf` requires either `command` (or application) or `pid` or an option `--system-wide`. In case of nexe, what should be used? If Chrome's pid need to pass, which one to use amongst multiple pids of the single Chrome instance.

WebAssembly Performance :
In the release build, we are using Optimization level -O3 and -flto. Still, the performance degradation is 30-50% with respect to NaCl. Thank you for suggesting the flags like -mnotrapping-fptoint and -sWASM_BIGINT. We haven't used them earlier. I will give it a try and let you know the result.

Regards,
Amol

Derek Schuff

unread,
Jan 21, 2021, 7:12:33 PMJan 21
to native-cli...@googlegroups.com
comments inline:

On Thu, Jan 21, 2021 at 3:57 PM Amol Wagh <amol...@synerzip.com> wrote:
Hello Derek,

Thank you so much for the reply, I really appreciate the help.

Profiling nexe :
As suggested I will use the `oprofile` to profile the NaCl build. However, I have few more questions regarding the procedure. It will be a great help for me if you could answer those, as I couldn't find any documentation with respect to NaCl.

Just a word of warning, that setup hasn't been tested in a long time; I don't even know if recent kernels support oprofile out of the box. It's very likely you'll need to do some fiddling to make it work and do your own post-processing (and TBH it's unclear to me whether this whole exercise will be worthwhile, compared to just trying to improve your wasm performance. What exactly are you trying to find out about your NaCl build, and what do you plan to do about it?).

 
1. Do I need to use any special flag (e.g. `gprof` requires `pg`) during compilation? Shall I use debug build?
You don't need special flags, but you'll at least want symbols (so a debug or debug+release build).
 
2. What flag/s need to pass to Chrome during launching?
Nothing special. You'll just want to launch it from the command line so you can see its stdout (I'm assuming, based on your screenshot, that you are using Linux). It's also probably worthwhile to use a clean profile directory, which is easiest if you use the --user-data-dir flag.
 
3. As mentioned here, the `operf` requires either `command` (or application) or `pid` or an option `--system-wide`. In case of nexe, what should be used? If Chrome's pid need to pass, which one to use amongst multiple pids of the single Chrome instance.

You'll need to look at the command-line flags passed to the chrome process, specifically the --type flag.

 
Reply all
Reply to author
Forward
0 new messages