FileDocCategorySizeDatePackage
TraceTest.javaAPI DocAndroid 5.1 API6019Thu Mar 12 22:22:12 GMT 2015android.os

TraceTest

public class TraceTest extends android.test.AndroidTestCase
This class is used to test the native tracing support. Run this test while tracing on the emulator and then run traceview to view the trace.

Fields Summary
private static final String
TAG
private int
eMethodCalls
private int
fMethodCalls
private int
gMethodCalls
Constructors Summary
Methods Summary
private intaMethod()
Calls other methods to make some interesting trace data.

return
a meaningless value

        int count = 0;
        for (int ii = 0; ii < 6; ii++) {
            count += bMethod();
        }
        for (int ii = 0; ii < 5; ii++) {
            count += cMethod();
        }
        for (int ii = 0; ii < 4; ii++) {
            count += dMethod(ii);
        }
        return count;
    
private intbMethod()
Calls another method to make some interesting trace data.

return
a meaningless value

        int count = 0;
        for (int ii = 0; ii < 4; ii++) {
            count += cMethod();
        }
        return count;
    
private intcMethod()
Executes a simple loop to make some interesting trace data.

return
a meaningless value

        int count = 0;
        for (int ii = 0; ii < 1000; ii++) {
            count += ii;
        }
        return count;
    
private intdMethod(int level)
Calls itself recursively to make some interesting trace data.

return
a meaningless value

        int count = 0;
        if (level > 0) {
            count = dMethod(level - 1);
        }
        for (int ii = 0; ii < 100; ii++) {
            count += ii;
        }
        if (level == 0) {
            return count;
        }
        return dMethod(level - 1);
    
public voiddisableTestNativeTracingFromC()

        long start = System.currentTimeMillis();
        nativeMethodAndStartTracing();
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        Log.i(TAG, "elapsed millis: " + elapsed);
    
public inteMethod()

        eMethodCalls += 1;
        int count = fMethod();
        count += gMethod(3);
        return count;
    
public intfMethod()

        fMethodCalls += 1;
        int count = 0;
        for (int ii = 0; ii < 10; ii++) {
            count += ii;
        }
        return count;
    
public intgMethod(int level)

        gMethodCalls += 1;
        int count = level;
        if (level > 1)
            count += gMethod(level - 1);
        return count;
    
native voidnativeMethod()

native voidnativeMethodAndStartTracing()

public voidtestMethodTracing()

        long start = System.currentTimeMillis();
        Debug.startMethodTracing("traceTest");
        topMethod();
        Debug.stopMethodTracing();
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        Log.i(TAG, "elapsed millis: " + elapsed);
    
public voidtestNativeTracingFromJava()

    
    
      
    
        long start = System.currentTimeMillis();
        Debug.startNativeTracing();
        //nativeMethod();
        int count = 0;
        for (int ii = 0; ii < 20; ii++) {
            count = eMethod();
        }
        Debug.stopNativeTracing();
        long end = System.currentTimeMillis();
        long elapsed = end - start;
        Log.i(TAG, "elapsed millis: " + elapsed);
        Log.i(TAG, "eMethod calls: " + eMethodCalls
                + " fMethod calls: " + fMethodCalls
                + " gMethod calls: " + gMethodCalls);
    
private voidtopMethod()

        aMethod();
        bMethod();
        cMethod();
        dMethod(5);
        
        Thread t1 = new aThread();
        t1.start();
        Thread t2 = new aThread();
        t2.start();
        Thread t3 = new aThread();
        t3.start();
        try {
            t1.join();
            t2.join();
            t3.join();
        } catch (InterruptedException e) {
        }