Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate different types of load in an Android device?

I'm trying to test my app's behavior in various situations like let's say there's a lot of RAM and CPU being used or network being consumed by some other apps or battery being drained away by another.

Now, what I've is let's say I want (100-X)% of RAM to be used away(render unavailable) and my app has only X% to use, how can I simulate that and run my app in that condition?

Similarly, let's say I've only Y% of network available due to various other apps running on the system, now I want to render (100-Y)% of the network availability to be simulated and run my app in that condition.

CPU being busy for (100-Z)% and available only Z% of time for my app that I want to test.

These are the situations that I want to simulate. Can someone show me a tool or explain me a way to do this?

like image 393
VoodooChild92 Avatar asked May 23 '13 11:05

VoodooChild92


People also ask

How do I simulate my Android phone?

Emulator for native development with Android StudioIn the Android Studio toolbar, select your app from the run configurations drop-down menu. From the target device drop-down menu, select the device that you want to run your app on. Select Run ▷. This will launch the Android Emulator.

How can I use Android Emulator instead of Android studio?

Run the app on your device as follows: In Android Studio, select your app from the run/debug configurations drop-down menu in the toolbar. In the toolbar, select the device that you want to run your app on from the target device drop-down menu.


3 Answers

Your requirement is that you want to test the application under stressed or release condition which can be controlled by you. so here the solution which I can see is

  • You can develop one more application(background service mostly) which would be responsible for increasing or decreasing the CPU cycles, Occupying or Releasing Memory and keep the network busy by the network operation(make simple UI to give the inputs)

    1. CPU cycles : Create multiple threads which would do Float operations and consume lot many CPU cycles and can be keep on the sleep when not required

    2. Memory : Need to write the C code(malloc to allocate the memory to pointers) and access that through the JNI and function to release the same. use the memory function from java to monitor current usage

    3. Network : Make task to download huge amount of files from dropbox or other server when needed and monitor the state as required.

after this configuration run the service, launch the desired application and test out under that condition.

like image 74
Dinesh Prajapati Avatar answered Oct 03 '22 18:10

Dinesh Prajapati


To test the performance of your application you can use debug trace tools. And check out this How to test the performance of an Android application?

And also this link provides some tools to test application performance.

You can use some applications like this or you can write some app to do some stress testing with CPU and RAM.

How can i stress my phone's CPU programatically?

like image 23
UdayaLakmal Avatar answered Oct 03 '22 17:10

UdayaLakmal


From my understanding of your question, your requirement is to simulate the effect of other apps on the device and see how it impacts your app.

RAM - Each process will have its own memory as in android the memory is per process. This dalvik heap limit is the assured amount of memory the VM gives to an app. There is no encroaching on this limit by any other app. However there is a native heap also which is common for all apps and processes.

Network - The shortage of network availability can be simulated by running an app on the device which connects to a web server and exchanges messages of fixed size at fixed intervals.

CPU - CPU cycles that is awarded to your app is certainly dependent on the load that other apps put on the CPU but it is totally dependent on the operating system to decide how the cpu cycles are scheduled. To ensure that your app gets only Z% of cpu time would be an approximation at best.

If your requirement is to have performance test of your app (with the impact of other apps on the device), you can try out http://www.littleeye.co . It provides performance data (Memory-Dalvik+Native, Network-2G+3G+Wifi, Cpu cycles & Power consumption) of your specific app from among other apps on the device. It is able to gather data for release build apks which means you can test performance of the final product.

DISCLAIMER: I'm associated with Little Eye Labs

like image 3
Srikant Sahay Avatar answered Oct 03 '22 17:10

Srikant Sahay