Background: I am trying to track down a memory leak in a Xamarin.Android app. Using DDMS and Eclipse Memory Profiler, I am able to see which objects are alive. When trying to track what is holding them alive (GC Root), I only see "Native stack" (of course).
How can I take a heap snapshot of the MONO VM? So I can later use it with i.e. heapshot tool?
Or are there ANY OTHER TECHNIQUES I can use to find what is holding an object alive in Xamarin.Android's .NET part? Is it possible to do something from within the program?
How can I take a heap snapshot of the MONO VM? So I can later use it with i.e. heapshot tool?
It is now possible to get heap snapshots of the Mono VM (tested with Xamarin.Android 4.8.2 beta; may apply to prior releases, your mileage may vary). It's a four step process:
Enable heapshot logging:
adb shell setprop debug.mono.profile log:heapshot
Start your app. (If your app was already running before (1), kill and restart it.)
Use your app.
Grab the profile data for your app:
adb pull /data/data/#PACKAGE_NAME#/files/.__override__/profile.mlpd
#PACKAGE_NAME# is the package name of your application, e.g. if your package is FooBar.FooBar-Signed.apk, then #PACKAGE_NAME# will be FooBar.FooBar.
Analyze the data:
mprof-report profile.mlpd
mprof-report is included with Mono.
Note: profile.mlpd is only updated when a GC occurs, so you may want to call GC.Collect() at some "well known" point to ensure that profile.mlpd is regularly updated .
I have been having troubles with Xamarin Android memory profiling, and have used a few tricks:
On the Dalvik side I have used Android Monitor to dump a heap snapshot and then opening it with JProfiler or Eclipse MAT. This standard Android.
A large portion of my code is shared (70-80%) and to verify this I have built a simple WinForms application to drive the shared API. This way I can use .Net Memory Profiler (or ANTS if you would prefer) as well as dotTrace for performance. I could easily pick quite a few
issues this way.
By using the solution explained by #jnop above I could open the profile.mldp in Mono's HeapShot tool and get a visual tool instead of the mprof-report textual output.
By the way used should vote for better profilers:
http://xamarin.uservoice.com/forums/144858-xamarin-suggestions/suggestions/3229534-add-memory-and-performance-profiler
Related
I have a simple application that contains two implementations which I want to compare(benchmark) with each other in terms of usage during a certain amount of time.
The testing method is equal for both implementations (they both execute exactly the same commands/events) the only difference is the way they process the command and events.
I wish to get a log per second of:
CPU load
Memory usage
Network traffic
The Android Monitor provides everything I need in a graph and logs per second the current CPU load, Memory usage and the TX/RX for network traffic, great!
However I wish to have this all in a text log instead of a live graph. Can someone tell me where I could find such a log? OR if there is no such thing, any suggestions to get similar data?
Doppie, I looked for a solution using out-of-box tools, but there is no good way to use the Android tools to export just the information you want to a text file without lots of work. Logcat is way too verbose and requires conversion, and Dalvik doesn't exactly provide you the every-second control over data collection. I would love to have a simple solution for this too. :/
[Disclaimer: Because I work with Perfecto, I know that the devices in their cloud lab can do this easily, so if you are trying to diagnose a specific problem, you could use their free public cloud and export the device vitals (shown below). This is not a pitch, but since it's free to play, it might help you in the short-term.]
hi first of all if you looking for memory logs. There is one option you can directly go and check that one.
Open Android Device Monitor then checks heap dumps.Check the uses of memory.
Another way to monitor Android Device Monitor then see the Allocation Tracker it gives you details in everyclass where you memory is used.
Expect these things you can directly check your Current logs.
Click Android Monitor and see logcat and second option Monitors.
Monitors gives you Four type of details :
1. Memory usages.
2. CPU how kuch usages of your phone.
3. Network
4. GPU.
Now after these all things. If you still have some problem then need to check your gradle.
What kind of libraries you used.
First of all remove unwanted libraries.
Secondly need to import only useful libraries. Like if you looking for map related things in your app then import only.
compile "com.google.android.gms:play-services-maps:9.4.0"
not this one.
compile 'com.google.android.gms:play-services:9.4.0'
Aware about replication of libraries.
Example : If you using some libraries and that libaray contain appcompt and you are also using same libaray in your app side.Then its better to use that libaray as module.
At last try to use proguard rules.
These are few ways to handle better memory management.
I have made one android app architecture here is link..
Thanks hope this will help you.
I have been searching for this answer for days and can't find a straightforward answer. I am working on an application written in C++ and that has been ported to Android. I am able to launch and run without too much hassle. My task is to figure out how much RAM our app is using dynamically so that we can handle memory issues dynamically-- which in my mind means that I need to have something in my C++ that can somehow be aware of system characteristics. What I have been able to do, is in my Java code, I can pull certain metrics that belong to my app via the getMemoryInfo call. Like in this post: Programmatically find Android system info
However, I would really like to be able to probe this from our C++ code so that we can handle everything in there...
Is this even possible?
If it is, are the calls unrealistically expensive?
If it is not, how is it possible to manage your memory through the native code rather than the Java code? i.e. If I see that I only have x amount of RAM available, I can dynamically change how much memory I want allocated to something in my C++ code to accommodate what the system has to offer.
Something along the lines of:
Ex. C++ Code:
if (android.os.thisApp.RAM left < 20 )
allocate 10M
else
allocate 20M
My PM wants me to test that how much time my android app is taking on GPRS/edge/3g when i navigate in app.
Is there any tool that i can use as he want me to use a tool that we can run.
he wants that when we use our app on mobile network how much time each page takes to load..
Please help!!
There are several tool provided by Android itself to optimize and monitor Application Performance
One of the tool is TraceView
Documentation:
Traceview is a graphical viewer for execution logs saved by your
application. Traceview can help you debug your application and profile
its performance.
Android also provides Device Monitor is available which comprises of several tools including TraceView
Documentation:
Android Device Monitor is a stand-alone tool that provides a graphical user interface for several Android application debugging and analysis tools.
Give it a try to these tools
Also if you want to find out how to improve performance, go through following blog I usually refer to optimize application performance
http://opensignal.com/blog/2013/07/30/40-developer-tips-for-android-optimization/
Hope this will help
If you are looking for a way to log the time that is spend in some method call you could use TimingLogger. With that you could log every network request and how long it takes to receive the network response.
This question is related to android system.
Dalvik VM uses JIT concept, it means that when you first run application Dalvik VM compiles it and loads into RAM as long as it could stay there. I understand that concept. But new virtual machine called ART, uses AOT method. ART compiles app after you install it(or when you are installing it?). What this means ? Apps compiled by ART are the same as already compiled apps(like C apps) but run in a separate processes separated from the rest of OS ?
Can somebody explains me this concepts more thoroughly. I have to make some presentation, and this is mentioning there, but I don't understand this concept and I don't want to look dumb if somebody asks me something about that :)
Sorry for bad English, it would be nice if somebody could edit question a bit.
I am not completely familier how Dalvik JIT on Android works in practice, because JIT have several options how can work.
First option is, that JIT translate all bytecode into CPU instructions on application launch. This option spent some time before application launches and after that application can run as native. Problem is, that translated application has to kept in memory during launch, which is not good.
Second option is, that JIT works as real Just-In-Time, which means that translate block of code when is about to launch. Whole application is not translated on launch, but only main function is translated on launch and then is translated during run, when certain block of code (function etc.) is used. This option consumes less memory, but application is much slower during run.
According to informations I found, Android uses first option. Application is translated on launch and after that it runs "almost" natively. And this "almost" makes main difference between JIT and AOT.
When you are about to launch some application, JIT have only limited time to compile all bytecode to CPU instructions to make launch-lag "acceptable" long. This means, it can perform only basic optimizations. However, when you install some application, you have usually more time to waste and you are doing it only once - not on every launch. This means that AOT compiler has much more time to find tricks how to optimize that application. Resulted code should be more "efficient". Second benefit is, that compiled application is stored to cache and only part of it can be loaded to memory on launch. That means that OS hadn't keep whole code in memory and can save it. And that is main differences.
And last part of your question - ART on Android will perform compilation on installation (after saving apk to /data/app/). However, if you wipe that cache, or switch from Dalvik to ART, it will compile all installed application on first boot, which can take 10 or even more minutes.
And sorry for my bad english too, I am Czech :-)
Ahead Of Time(AOT) - Android Runtime(ART) - generates machine byte code during installation.
[JIT vs AOT]
I am currently pondering the feasability of implementing part of the Android APIs on a desktop JVM and I was wondering whether you had already heard of such a project.
If there aren't, and you know good reasons why (beyond "no one has begun that yet"), I would be glad to read them.
There is another project (apparently in its infancy) to bring the Android API on Linux Desktop. It is called IcedRobot. On the project's home page, it states its goals as:
Have Dalvik completely separated from the usual Android infrastructure
so that it runs as any other *unix
program in the Linux environment (and
non Linux, I personally want it to
work on OSX and QNX).
Avoid Dalvik and Harmony as much as possible and put the Android stack on
top of the OpenJDK class library, and
run the whole thing in Hotspot (this
is cool, ins’t it?).
Some related resources:
The GNUlization of Android (PDF of FOSDEM presentation)
IcedRobot Dev mailing list
Running HelloAndroid
The False Dawn of IcedRobot
FOSDEM: Icing the robot
I'm not entirely certain I understand your goal, but I'll assume you do not want to emulate ARM execution and therefore not run the whole Android stack, but instead implement some subset of the Android Java APIs running on standard JVM running standard Java byte code right? If so, I do not know of any similar projects.
However, if you'd like to run the full Android stack (including Dalvik VM) on an arbitrary desktop machine (without emulation), take a look at the android-x86.org project. There are instructions for running a complete Android image within a virtual machine so that you could host Android applications within the same box.
There is also a project supplying a LiveAndroid CD image suitable for running in VirtualBox, VMWare or Microsoft Virtual PC which may expedite proof of concept.
Hope that helps.