Android: is there any tool for profiling native code? - android-ndk

I have only found one profiling tool - http://code.google.com/p/android-ndk-profiler/. Wasn't able to get it working so far, so I wonder if there are other tools available.
I need to profile on a physical device, as my application doesn't even work on emulator.

It is not easy to make the Android-NDK profiler work. You need to follow the steps here thoroughly.
Here are some tips that led me to success:
Make sure your android.mk is correct and that you export the NDK_MODULE_PATH.
Use correctly the following functions
monstartup("your_lib.so");
moncleanup();
If the gmon.out is generated now you need to pull it from the device, but not to anywhere in your PC. For me it only works if I go to the application's folder (where jni, obj, res and other folders are) and I do:
console$ adb pull sdcard/gmon.out
Then run gprof. Try will all the versions in your NDK toolchains. For me only one worked, this one:
console$ ~/Libraries/android-ndk-r9/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gprof obj/local/armeabi-v7a/libxxxx.so > profile.txt

The Shiny profiler is platform independent, it runs anywhere and it does not have any dependencies besides a standard C++ compiler. In its more simple usage, all you need to do is add a macro at the beginning of all functions and methods (or at least those that you want to profile).

Intel VTune Amplifier. This profiler allows you to collect hotspots with stacks on Android devices without root or any OS modification.
Here is simple guide:
http://software.intel.com/en-us/articles/using-intel-vtune-amplifier-on-non-rooted-android-devices

In the NDK r13b there is a new tool called simpleperf

Related

Can one compile Windows code on Linux?

I have an Ubuntu server (with a VPN and a samba share), where I store all my project files and so on.
I would like not to have to back up the files I have on my computer to the server, but instead, directly use the files that are on the server.
But, when I want to build a project on Windows, it gets really slow, since I basically have to be transferring that whole bunch of files visual studio creates through the internet, so I can build the project.
The core concept is:
Open files that are on the server and use them (ie. saving one file at a time is fast enough not to make a difference).
Compile the code on Linux (Maybe code a VS extension with sockets that will tell the server to build, and that server-side, when done building, will send a message back, for VS to run and debug the program). Which would be much better since my laptop is nothing compared to the server performance-wise.
Run and debug the program with VS on windows.
I've so far only been able to find this(which is not what I want because it uses g++, and I'd like VC++) and this(which is not what I want because it's compiling for linux and executing it remotely). What I'm looking for is a mixture of both.
Remote compiling, local programming and executing.
Would also be great because supposedly, I could build with whatever VC++ version I wanted with whatever SDK I wanted. So I could basically easily switch between compiling for Windows 7 and 10.
I'd just like to know: Is it possible to achieve that? And if so how?
Using VC++ directly on Linux is not possible.
To let the Linux server do the compiling with VC++ anyway you could either use wine which apparently works with older Versions (see https://appdb.winehq.org/objectManager.php?sClass=application&iId=5766
) but propably is not easy to set up in a CLI envrioment and might cause License Issues with Microsoft, or use Windows Virtual Machines, which tend to have some Performance drawback.
The best Solution would be to use GCC (g++), which works on a wide range of architectures and operating systems and supports cross compiling.

Run Google Native Client (nacl_sdk) on Samsung Chromebook

I was trying to follow the the installation tutorial of the Native Client SDK found here. However, my Samsung Chromebook (in developer mode) does not want to run ./naclsdk (chmod +x done), but instead returns the following:
32-bit runtime environment was not found on this
system. Specifically the 32-bit dynamic loader which is needed by the NaCl
compilers was not found ('/lib/ld-linux.so.2'). On modern debian/ubuntu
systems this is included in the 'libc6:i386' package.
On here they write that the PNaCl should run on ARM computers, however, on some other forums I read that wasn't the case. I've tried enabling two flags, as described on a site which I can't post due to a lack of reputation, but it looks like that'll only change things when using PNaCl, not during the installation of the SDK.
Is it possible to install that SDK on my Chromebook and, if so, how?
There's a bit of confusion: when the documentation says "PNaCl and NaCl work on ARM", it means the part that runs inside of Chrome which users would use. The SDK is currently only built for x86-64 Windows/Linux/OSX, and not for ARM. The main reason is that it's never been requested, probably because ARM machines are quite slow compared to usual development machines.
That being said, I don't think it's silly to use ARM as a development machine, and I've built my own PNaCl toolchain for ARM in the past. There are build instructions for the toolchain. I haven't built it recently, and it may have bitrotted a bit so if you run into issues I suggest emailing the team or better yet sending a patch! I expect any issue to be fairly minor, especially if you only want to use pnacl-clang or nacl-clang (as opposed to the GCC toolchain).

Running J2me apps on Android phones

Is it possible to run J2ME apps on Android phones? If so, what is the installation procedure?
Otherwise, is it possible to convert .jad files to .apk? In this case, what is the procedure.
(I have already tested the procedure offered by netmite but it doesn't seem to work.)
Using this site http://www.netmite.com/android/srv/2.0/getapk.php you can convert your J2ME application in to Android Application. You need to just supply your .Jad & .Jar file in it and it will generate Android's executable file .apk for you.
However in it doesn't able to convert all the feature of Java ME to Android, but basics can be easily converted.
You can try phoneME, netmite j2me app runner, jblend, jbed like jeme emulators in android. For now, phoneME is the best. you can get various version of phoneME here http://davy.preuveneers.be/phoneme
You also need OI file manager to select files in phoneME.
A complete guide can be found here http://w3epic.com/run-java-apps-j2me-on-android-devices-guide/ for rest of other emulators (if you want to try).
#dennis
I got it, thanks.
MicroEmu open source project hasn't been mentioned yet, and here it goes: https://code.google.com/p/microemu/
I searched for a good JavaME emulator for Android for a long time, and finally found one. This here is what you need:
http://davy.preuveneers.be/phoneme/
No doubt the best there is for Android.
Added 15th January 2016:
Reply from the author of phoneME, Davy Preuveneers, in regards to the Android 5.0+ issue commented by Álvaro Gutiérrez:
Hi,
I am testing on a Samsung Galaxy S4 running Android 5.0.1, and the
"phoneME Advanced - Foundation Profile + MIDP FullHD Resolution" build
seems to run just fine on this device.
Also, following this thread
Position Independent Executables and Android Lollipop,
I ran:
$ readelf -l libcvm.so | grep -i "file type"
and it reports:
Elf file type is DYN (Shared object file)
So according to the website this is OK.
However, for the CDC and Foundation profiles (console like
applications), there is indeed an issue where you get this error:
"Error: only position independent executables (PIE) are supported"
However, for those 2 profile I call a native executables and redirect
the native stdout/stderr streams to Android, whereas for the MIDP dual
stack I load a library and create a complicated wrapper to get things going.
I can recompile with -fPIE and -pie options but will then end up with
binaries that are no longer backwards compatible with devices running
Android 4.0 and below. That is why I added some additional builds to my
website for Android 5+ devices:
http://davy.preuveneers.be/phoneme/?q=node/10
Best regards,
Davy

How do I generate .dSYM for MonoTouch app in Simulator?

I want to profile a MonoTouch application in Instruments without an iPad. I am able to profile an app compiled for Simulator but it's no fun without the symbols:
There is no option to generate IPA with dSYM in project build settings—looks like they're only available when compiling for the device.
All I want is a MonoTouch-aware dSYM for Simulator.
Is this possible?
This is unfortunately not possible, because in the simulator we JIT managed code. This means that it is not possible to know before executing the process where methods will be in memory, and Instruments doesn't support the required mechanisms for MonoTouch to inform about JIT'ed methods at runtime [1].
[1] See last comment on the response here: Is it possible to notify DTrace on Mac OS X of dynamically generated code?
Take a look at this - miguel wrote a blog post recently to compile aot for profiling on mac - I think this will give you what you're looking for:
Using Instruments to profile Mac apps built with Mono

Is is possible to build Android games in Go using the NDK with cgo and/or SWIG or similar?

Is it possible to use Go to build Android games at all? I'm not wedded to the technologies mentioned in the subject line. I know that some people have built some Android programs in Go, but they may have been headless.
No, it is not possible right now. Go and C programs can interoperate via cgo. but in that case, the Go program has to start and initialize its runtime before passing control to the C-based part of the program.
When using the NDK in Android, your C code is called by the Dalvik virtual machine via dlopen. So the Go runtime would not have a chance to initialize itself.
If you want non-headless apps, my advice would be to use cgo for the GUI. That sounds counterintuitive, but if the NDK supports C android gui libraries, it'd probably be easiest to write the GUI using those calls. Of course, you don't have to write all the logic in C. You could simply cgo wrappers for each of the GUI calls and then write the GUI in go, except that each gui call would be translated through cgo.

Resources