AOSP emulator memory filling up very quickly - android

I'm currently working with AOSP and building an app for the Android Automotive OS. I have compiled the same code (checked out from version control) on two different PCs (both running Ubuntu). On one of them (with an Intel CPU) the emulator starts up fine and the emulator is stable.
On the other PC (an AMD CPU) the emulator starts up, but will quickly crash with OutOfMemory errors. AOSP is quickly killing all processes, then its system processes and finally reboots due to 'System is deadlocked on memory'.
I found that the culprit is a system process. It hoards a lot of memory:
the android.hardware.automotive.vehicle process is hoarding memory. It keeps growing very quickly and finally the OS reboots.
When I use the meminfo tool to inspect memory usage of the process, I find the following:
The android.hardware.automotive.vehicle process is using over 2GB of RAM.
My questions thus are:
Do you what is happening?
How can I debug this system process?
Why is the system process behaving differently on one PC compared to another PC?

For those who ran into this issue:
After a lot of fiddling around, I found that adding custom vehicle properties to the VHAL definitions (think of the types.hal and DefaultConfig.h files) must be done very carefully. In my case, I added a vehicle property with VehiclePropertyChangeMode set to CONTINUOUS, but did not add a minimum and maximum sample rate. This caused the android.hardware.automotive.vehicle service to keep requesting more and more memory for some reason and finally the emulator would crash.
If you want to prevent this from happening, make sure to add a minSampleRate and maxSampleRate in your DefaultConfig.h file!

Related

My emulator is taking up too much memory

As per the title, my Android Studio seems to be using too much memory, even at idle. For my friend, he is able to run his emulator at only ~300MB of RAM usage, according to Windows' Task Manager. I've tried duplicating his emulator settings, even with his emulator set to 1.5GB of RAM, it is only using about 300MB. Mine goes up to 1.5GB, sometimes even 2GB, just by getting it started, I'm not even running any apps on it.
Is this even possible? Running it at only ~300MB, because on mine, the lowest I can go is 1024MB, setting anything lower results in no change in Task Manager.
Maybe in the installation process you installed more things than him. That's why it's eating a lot more memory

adb.exe spawning many process instances

I'm new to developing for Android and have been tasked with helping the development of some React Native based Android application. I have a working setup in which an emulated Android device can run this application. However, when starting the emulator, the process adb.exe repeatedly gets spawned in the background at a rate of about 1 process per second. These processes seemingly take no/very little memory (144K according to the Task Manager), but over time, this still adds up to a massive list of processes (nearing 3000 at the time of writing) taking up quite a bit of memory (which is already scarce thanks to a fairly heavy development toolchain).
Closing the emulator does not automatically terminate these processes. The only way I have found so far that works is by using taskkill /IM /F.
Is this expected behaviour? If not, how could I begin with tracking down the reasons for behaviour.
If that happens again try to find in task manager, there will be numerous adb.exe processes popping-up most of them with same memory usage.Lookout for a process which uses different amount of memory once you identify it dont make any changes to that one instead stop processes that display same memory usage if you even kill one of those whole stack of them will come down to one adb.exe process. i've faced a similar issue and doing this has solved the problem. generally, it happens when you start to run emulator thats when you need to see the taskmanager.

Emulator awfully slow on Windows 7

This is not a rant, and also not a duplicate of the forever "why is Android emulator so slow" problem. So, until a few weeks (maybe months) ago, emulating Android devices on my Win7 64-bit system was at the very least acceptable (x86 emulation was decently fast to be usable). However, trying to create any ("fast" "new" "2.0") emulator instances using the latest version of the SDK, platform tools, etc., is only a source of frustration and pain for several days now. I'm trying to understand if it's an issue on my side or people can actually use the latest version of the Android emulator included in the latest SDK, on Windows 7.
My PC config: Win7 x64 / Intel Core 2 Quad #3.8 GHz / 6 GB RAM / plenty of HDD space / dedicated GPU
What happens when trying to start an emulator with any API level, with either x86 or x86_64:
version 1) emulator starts, Android logo appears, glows for a bit, and that's it. It never reaches the Home screen. Emulator log shows absolutely no errors. Trying to connect using adb freezes Android Studio until I kill the emulator process.
version 2) Same like version 1, but in this case I can't even kill the qemu-system-i386 process (yes, not even with full admin rights). I have to actually restart Windows. Process remains a zombie, using 1 GB of RAM.
version 3) If I'm lucky, sometimes it reaches the Home screen, but becomes completely unusable. Sometimes I can click on things (maybe 2-3 clicks), and then becomes completely unresponsive. Occasional "Launcher has stopped" / "System has stopped" messages appear randomly in the emulator's home screen...
I've installed the latest Intel HAXM 6.0.3 version (the one downloaded by the Android SDK manager). Virtualization is enabled in BIOS.
I've tried all kinds of emulator options (more or less RAM, hardware vs software GPU, x86 / x86_64). Almost same result every time.
I've completely deleted and reinstalled the entire Android SDK and Android Studio.
CPU is not the issue - it's not under load while emulator runs.
Free RAM is not the issue - it's not fully used while emulator runs,
HDD is not the issue - I even defragmented it, and it's not looking like it's under any sort of load while emulator is running.
So, my question is very simple: is anyone out there using Windows 7, who can actually start up, let's say, a Marshmallow x86 emulator just by a simple 2-3 clicks process, and actually have it reach the home screen? Or does the "new, faster" emulator actually need some sort of super-powerful machine which I don't seem to possess anymore? The only thing that apparently changed was the HAXM driver. But it's stating that it has initialized just fine, so I don't know. Oh, and VirtualBox runs just fine. GenyMotion, by contrast, just flies. But I'd like to have the official Android emulator in a working state, or am I asking for too much?
Adrian, in my sad opinion: yes, you would need a powerfull processor, even a litle bit more of ram. The almost-aceptable scenario for you to run api 24 emulation in xxxhdpi resolution is an i7 with 8 of ram.
But this is what hard and software manufacturers want you for: upgrade, upgrade, upgrade. And it's not necessairilly true for you, or not obligatory for today. Maybe tomorrow...
It's my case too. I have a second generation i5 with 6 of ram and plenty of disk. Have a good geforce gpu too. And what I do to have my emulators running, or, how do I emulate in my win7? First of all: unninstalled all the last (about 30) non-security system updates from windows (! yes..., they make your system very heavy, the same with the various distributed c++ packages microsoft want us to carry on with our systems even if we use it once a year, or less - go to control panel and ripp'em off! Keep only the most recent c++ package - if you need it later, update again). Actually I'm even investigating what else "updates" I can delete from my system to have it usable again, mine again. Microsoft...
Second: enabling "power save mode" on your android studio (menu file), only in testing times, seems to make things faster.
Third: do heavy tests on emulators with "low" apis, like android 4 or 5 at max. And emulate devices with small screens or resolution, 5 pol. with 720 points (hor.), at max. If possible use _x86 64 emulation.
With this you can make it happen. The emulator is slow to load and open, but when running it works in a fairly good speed. First thing to do there: enter developer options and "force gpu" on both places. This will instruct your pc to take advantage of your dedicated gpu system.
Do not try to open two or more emulators at the same time, sorry.
When 90% of your debug is done (i do it in an emulator running android version lower than 5, normally 4.0 or 4.1 - 480x800 screen), then you pay the price to load a big screen, big dpi android 5, 6 or N). While it loads, make a coffee and use the bath.
When the beauty (beast?) is loaded, then do the final tests with all your apps that stayed waiting for this special moment. I maintain all my apps waiting for it. When I load the "big" emu I use this oportunity to do all tests I was needing - because it's not a simple task open this everytime I want.
In the future, as said: i7, 8ram, powerfull gpu and, very important: a good SSD drive (until 10x faster) to throw up damn nasty harddisk to the garbage. :) Best.
EDIT: when you create an AVD image with the latests APIs, Android Studio defines the ram and disk space values for the emulation and, in my opinions, these values are too big and too hard for the hostage computer to deal with. First point: your testing app never will demand all those resources. Two: your pc suffers hard to deal with a very fragmented Gb data from here to there, and there to here. Three: the virtual image created on your hard disk gets bigger with the use. So: 1 - lower the default values from your avd images, ram and disk sizes; 2 - on the avd launching window dialog, edit the options of each image and rip information everytime before start the emulation OR/AND 3 - uninstall your apps from the emu when not needed.

Emulator is starting and running slowly for android application using elicpse

I am using Eclipse new v22.6.2 . My emulator is starting and running very slowly... How to overcomes this problem..using 3.7"WQVGA(240x432:IDPI).
system configuration is 2GB RAM and 64 bit windows 8 and i3 processor
Increase eclipse Memory size since you emulator is using its memory to run. See here to give more memory.
Genymotion is the better option if you want to test your app with emulator.
In my personal opinion it is always best to test app with the real devices.
I recommend using Genymotion (https://www.genymotion.com/). It is free for personal use.
Just had this issue myself (even though I believe to have a nice piece of hardware) and found that it's really faster as it claims to be.
In my notebook, it will get up and running in about 20-30 secs. Hope that will suit your needs.

Memory monitor in Android Studio reports different RAM usage than the device

When investigating RAM usage in an app I am working on, I have been using the Memory Monitor tool in Android Studio (can be accessed in Android Studio by going to Tools>Android>Memory Monitor). I have noticed the RAM usage of my app that is reported in Memory Monitor, is always far lower than when viewing the RAM usage from the device (can be accessed by going to Settings>Apps>Running). As you can see in the screenshots below, Memory Monitor is reporting about 18MB of RAM usage (23MB if you include free space), but the device is reporting 43MB.
Why the difference and also is one more accurate than the other?
I suspect that the memory monitor tool is talking to the dalvik virtual machine about heap allocations made by Java code, and the device manager is showing what the entire process is using for memory. So the first does not include overhead or memory used by the virtual machine itself (or its text and libraries), or any off-heap allocations (sometimes native code can allocate memory that isn't directly visible to the VM).
See https://developer.android.com/tools/debugging/debugging-memory.html#ViewingAllocations and try running the command:
adb shell dumpsys meminfo <package_name>
to get a more precise breakdown of the run-time memory usage of your application.
I've tested the Android Studio's Memory Monitor's Allocated can be get this way programmatically:
long allocatedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
But this only works to get information of the current app.

Categories

Resources