18

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
VoodooChild92
  • 1,993
  • 3
  • 19
  • 24

5 Answers5

9

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.

Dinesh Prajapati
  • 9,274
  • 5
  • 30
  • 47
  • Thanks. Started on that a while ago. Posted the question to dig into details that'll help me simulate a condition that's accurate to my needs. – VoodooChild92 Jun 04 '13 at 06:04
  • 1
    I would like to help you if you stuck some where – Dinesh Prajapati Jun 04 '13 at 06:10
  • How exactly can I make my process occupy 'X%' of total RAM? How can I make sure that I won't let any memory swap happen to this process' memory? – VoodooChild92 Jun 04 '13 at 06:13
  • 1
    Need to make 2 functions in C which would occupy 1MB memory and release the same. now from JAVA call the thread which will check for current memory usage and take X from user and (X - Current) MB would be allocated through JNI call. – Dinesh Prajapati Jun 04 '13 at 06:22
6

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?

Prashant Pokhriyal
  • 3,727
  • 4
  • 28
  • 40
UdayaLakmal
  • 4,035
  • 4
  • 29
  • 40
  • Traceview is deprecated. If you're using Android Studio 3.2 or later, you should instead use CPU Profiler to inspect .trace files captured by instrumenting your app with the Debug class, record new method traces, save .trace files, and inspect real-time CPU usage of your app's processes. – Prashant Pokhriyal Oct 15 '18 at 08:54
3

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

Srikant Sahay
  • 885
  • 6
  • 9
1

I was faced with this issue as well. There were some posix compliant load generation tools out there. I found stress to be an attractive tool since it allowed you to control stress over CPU or IO. To make the most use of this, I'm writing a wrapper around it to set the amount of load that is being generated.

Here's the binary compiled for android.

Here's the original site, stress project page

siesta
  • 1,365
  • 2
  • 16
  • 21
0

Thanks to @Dinesh Prajapati, this helps me a lot, I wrote a thread class to do float calculation, and cpu idle percentage decreased a lot as I would expected. I'd like to put my solution here for reference:

@Override
    public void run() {
        Random rd = new Random();
        float a, b;
        int x, y;
        @SuppressWarnings("unused") double r;
        while (run) {
            x = rd.nextInt(20) + 20;
            y = rd.nextInt(20) + 20;
            a = rd.nextFloat();
            b = rd.nextFloat();
            //noinspection UnusedAssignment
            r = Math.pow(a + x, b + y) / Math.tan((double) (a + x) / (b + y));
        }
    }

Thanks a lot.

MadHatter
  • 301
  • 3
  • 12