automated historical performance analysis with kmemtracer
DESCRIPTION
Material presented at the 12th Korea Android Conference, Oct. 2013.TRANSCRIPT
![Page 1: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/1.jpg)
Automated Historical
Performance Analysis
with kmemtracer
LG전자 이경민
![Page 2: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/2.jpg)
2 12th Kandroid Conference - www.kandroid.org
Why Automated Historical Performance Testing?
kmemtracer: What and How?
Enhancement I : Automating UI Interaction
Enhancement II: Adding More Performance Metrics
Contents
![Page 3: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/3.jpg)
3 12th Kandroid Conference - www.kandroid.org
If you can’t measure it, you can’t manage it.
Peter F. Drucker (1909~2005)
![Page 4: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/4.jpg)
4 12th Kandroid Conference - www.kandroid.org
If you can’t measure it, you can’t manage it.
Peter F. Drucker (1909~2005)
If you can’t automate the measurement of it,
it is difficult to improve it.
![Page 5: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/5.jpg)
5 12th Kandroid Conference - www.kandroid.org
http://developer.android.com/about/dashboards/index.html
Platform Versions
Diversity or Fragmentation
![Page 6: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/6.jpg)
6 12th Kandroid Conference - www.kandroid.org
http://developer.android.com/about/dashboards/index.html
Platform Versions
Screen Sizes and Densities
Diversity or Fragmentation
![Page 7: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/7.jpg)
7 12th Kandroid Conference - www.kandroid.org
http://www.mactrast.com/2012/05/visualized-the-truth-about-android-fragmentation/
![Page 8: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/8.jpg)
8 12th Kandroid Conference - www.kandroid.org
Why Historical Analysis?
Source: Memory and Performance at the 11th Korea Android Conference
Historical Performance Analysis
![Page 9: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/9.jpg)
9 12th Kandroid Conference - www.kandroid.org
Why Historical Analysis?
Source: Memory and Performance at the 11th Korea Android Conference
Historical Performance Analysis
![Page 10: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/10.jpg)
10 12th Kandroid Conference - www.kandroid.org
Why Historical Analysis?
Source: Memory and Performance at the 11th Korea Android Conference
Activity Navigation & Lifecycle
Historical Performance Analysis
![Page 11: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/11.jpg)
11 12th Kandroid Conference - www.kandroid.org
How to Track Activity Navigation & Lifecycle?
![Page 12: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/12.jpg)
12 12th Kandroid Conference - www.kandroid.org
How to Track Activity Navigation & Lifecycle?
Override onCreate, onStart, … of your Activity classes
![Page 13: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/13.jpg)
13 12th Kandroid Conference - www.kandroid.org
How to Track Activity Navigation & Lifecycle?
Modify android.app.Activity
in the framework
![Page 14: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/14.jpg)
14 12th Kandroid Conference - www.kandroid.org
How to Track Activity Navigation & Lifecycle?
Is there a way that does not require the modification of
an application or framework?
![Page 15: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/15.jpg)
15 12th Kandroid Conference - www.kandroid.org
How to Track Activity Navigation & Lifecycle?
Is there a way that does not require the modification of
an application or framework?
Instrumentation
![Page 16: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/16.jpg)
16 12th Kandroid Conference - www.kandroid.org
![Page 17: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/17.jpg)
17 12th Kandroid Conference - www.kandroid.org
Android instrumentation is a set of control methods or "hooks" in the Android system. These hooks control an Android component independently of its normal lifecycle. They also control how Android loads applications. (http://developer.android.com/tools/testing/testing_android.html)
![Page 18: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/18.jpg)
18 12th Kandroid Conference - www.kandroid.org
Why Automated Historical Performance Testing?
kmemtracer: What and How?
Enhancement I : Automating UI Interaction
Enhancement II: Adding More Performance Metrics
Contents
![Page 19: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/19.jpg)
19 12th Kandroid Conference - www.kandroid.org
Historical Analysis w/ kmemtracer
Test Package
Application Package
android.test. Instrumentation
TestRunner
Control
![Page 20: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/20.jpg)
20 12th Kandroid Conference - www.kandroid.org
Historical Analysis w/ kmemtracer
https://github.com/snailee/kmemtracer-libs
Test Package
Application Package
android.test. Instrumentation
TestRunner
org.kandroid. memtracer.Memory
Instrumentation
Control Track
Trace Package
![Page 21: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/21.jpg)
21 12th Kandroid Conference - www.kandroid.org
android.app.Instrumentation
void callActivityOnCreate(Activity, Bundle)
void callActivityOnDestroy(Activity)
void callActivityOnNewIntent(Activity, Intent)
void callActivityOnPause(Activity)
void callActivityOnPostCreate(Activity, Bundle)
void callActivityOnRestart(Activity)
void callActivityOnRestoreInstanceState(Activity, Bundle)
void callActivityOnResume(Activity)
void callActivityOnSaveInstanceState(Activity, Bundle)
void callActivityOnStart(Activity)
void callActivityOnStop(Activity)
void callActivityOnUserLeaving(Activity)
void callApplicationOnCreate(Application)
![Page 22: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/22.jpg)
22 12th Kandroid Conference - www.kandroid.org
android.app.Instrumentation
void callActivityOnCreate(Activity, Bundle)
void callActivityOnDestroy(Activity)
void callActivityOnNewIntent(Activity, Intent)
void callActivityOnPause(Activity)
void callActivityOnPostCreate(Activity, Bundle)
void callActivityOnRestart(Activity)
void callActivityOnRestoreInstanceState(Activity, Bundle)
void callActivityOnResume(Activity)
void callActivityOnSaveInstanceState(Activity, Bundle)
void callActivityOnStart(Activity)
void callActivityOnStop(Activity)
void callActivityOnUserLeaving(Activity)
void callApplicationOnCreate(Application)
Call for Control
![Page 23: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/23.jpg)
23 12th Kandroid Conference - www.kandroid.org
android.app.Instrumentation
void callActivityOnCreate(Activity, Bundle)
void callActivityOnDestroy(Activity)
void callActivityOnNewIntent(Activity, Intent)
void callActivityOnPause(Activity)
void callActivityOnPostCreate(Activity, Bundle)
void callActivityOnRestart(Activity)
void callActivityOnRestoreInstanceState(Activity, Bundle)
void callActivityOnResume(Activity)
void callActivityOnSaveInstanceState(Activity, Bundle)
void callActivityOnStart(Activity)
void callActivityOnStop(Activity)
void callActivityOnUserLeaving(Activity)
void callApplicationOnCreate(Application)
Call for Control
Override for Track
![Page 24: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/24.jpg)
24 12th Kandroid Conference - www.kandroid.org
org.kandroid.memtracer.MemoryInstrumentation
public class MemoryInstrumentation extends Instrumentation { private static final String ARGUMENT_INSTRUMENT_CLASS = "class"; private MemoryTracer mMemoryTracer; private String mMainActivityName; ... @Override public void onCreate(Bundle arguments) { mMainActivityName = arguments.getString(ARGUMENT_INSTRUMENT_CLASS); mMemoryTracer = createMemoryTracer(); mMemoryTracer.startTracing(getTargetContext().getPackageName()); start(); } @Override public void callActivityOnCreate(Activity activity, Bundle icicle) { String tag = activity.getLocalClassName()+"-OnCreate"; Bundle snapshot = mMemoryTracer.addSnapshot(tag); super.callActivityOnCreate(activity, icicle); } }
![Page 25: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/25.jpg)
25 12th Kandroid Conference - www.kandroid.org
Tracing Performance Snapshots in kmemtracer
public class MemoryInstrumentation extends Instrumentation { ... ... }
![Page 26: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/26.jpg)
26 12th Kandroid Conference - www.kandroid.org
Tracing Performance Snapshots in kmemtracer
public class MemoryInstrumentation extends Instrumentation { ... private MemoryTracer mMemoryTracer; ... @Override public void onCreate(Bundle arguments) { ... mMemoryTracer = createMemoryTracer(); ... } ... ... }
Create an instance of MemoryTracer
![Page 27: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/27.jpg)
27 12th Kandroid Conference - www.kandroid.org
Tracing Performance Snapshots in kmemtracer
public class MemoryInstrumentation extends Instrumentation { ... private MemoryTracer mMemoryTracer; ... @Override public void onCreate(Bundle arguments) { ... mMemoryTracer = createMemoryTracer(); ... } ... @Override public void callActivityOnCreate(Activity activity, Bundle icicle) { String tag = activity.getLocalClassName()+"-OnCreate"; Bundle snapshot = mMemoryTracer.addSnapshot(tag); ... } ... }
Create an instance of MemoryTracer
Add performance snapshot
![Page 28: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/28.jpg)
28 12th Kandroid Conference - www.kandroid.org
MemoryTracer.addSnapshot
public Bundle addSnapshot(String label) { ...
![Page 29: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/29.jpg)
29 12th Kandroid Conference - www.kandroid.org
MemoryTracer.addSnapshot
public Bundle addSnapshot(String label) { ... long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); ...
Get usage data
![Page 30: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/30.jpg)
30 12th Kandroid Conference - www.kandroid.org
MemoryTracer.addSnapshot
public Bundle addSnapshot(String label) { ... long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); ... Bundle snapshot = new Bundle(); snapshot.putString(METRIC_KEY_LABEL, label); ... snapshot.putLong(METRIC_KEY_NATIVE_SIZE, nativeMax); snapshot.putLong(METRIC_KEY_NATIVE_ALLOCATED, nativeAllocated); snapshot.putLong(METRIC_KEY_NATIVE_FREE, nativeFree); ...
Get usage data
Save data to a bundle
![Page 31: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/31.jpg)
31 12th Kandroid Conference - www.kandroid.org
MemoryTracer.addSnapshot
public Bundle addSnapshot(String label) { ... long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); ... Bundle snapshot = new Bundle(); snapshot.putString(METRIC_KEY_LABEL, label); ... snapshot.putLong(METRIC_KEY_NATIVE_SIZE, nativeMax); snapshot.putLong(METRIC_KEY_NATIVE_ALLOCATED, nativeAllocated); snapshot.putLong(METRIC_KEY_NATIVE_FREE, nativeFree); ... if (mResultsWriter != null) { mResultsWriter.writeTraceSnapshot(snapshot); } return snapshot; }
Get usage data
Write date using ResultsWriter
Save data to a bundle
![Page 32: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/32.jpg)
32 12th Kandroid Conference - www.kandroid.org
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ...
![Page 33: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/33.jpg)
33 12th Kandroid Conference - www.kandroid.org
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ... public MemoryTraceCsvWriter(String[] metricKeys) { mMetricKeys = metricKeys; } ...
Create an instance with metrics to print
![Page 34: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/34.jpg)
34 12th Kandroid Conference - www.kandroid.org
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ... public MemoryTraceCsvWriter(String[] metricKeys) { mMetricKeys = metricKeys; } ... private void openTraceFile(String filename) { ... mTraceOut = new PrintStream(new FileOutputStream(traceFile)); ... } ...
Create an instance with metrics to print
Open a trace file in the sdcard at init
![Page 35: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/35.jpg)
35 12th Kandroid Conference - www.kandroid.org
MemoryTracerCsvWriter$writeTraceSnapshot
public class MemoryTraceCsvWriter implements MemoryTracer.ResultsWriter { ... public MemoryTraceCsvWriter(String[] metricKeys) { mMetricKeys = metricKeys; } ... private void openTraceFile(String filename) { ... mTraceOut = new PrintStream(new FileOutputStream(traceFile)); ... } ... @Override public void writeTraceSnapshot(Bundle snapshot) { PrintStream out = mTraceOut; for (String key : mMetricKeys) { out.print(snapshot.get(key)); out.print(','); } out.println(); out.flush(); } ... }
Create an instance with metrics to print
Write snapshot to a line of the file
Open a trace file in the sdcard at init
![Page 36: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/36.jpg)
36 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
![Page 37: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/37.jpg)
37 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
1. Create an Android Test Project for the trace package.
![Page 38: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/38.jpg)
38 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
1. Create an Android Test Project for the trace package.
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
![Page 39: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/39.jpg)
39 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
1. Create an Android Test Project for the trace package.
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> element in the Manifest file.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.apis.test" android:versionCode="1" android:versionName="1.0"> <instrumentation android:name="org.kandroid.memtracer.MemoryInstrumentation" android:targetPackage="com.example.android.apis" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher“> <uses-library android:theme="android.text.runner“> </application> </manifest>
![Page 40: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/40.jpg)
40 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
4. Install the trace package as well as the application package.
$ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk
![Page 41: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/41.jpg)
41 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
4. Install the trace package as well as the application package.
5. Start the instrumentation with ‘am instrument’ in the shell.
$ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk
$ adb shell am instrument -e class \ > com.example.android.apis.ApiDemos \ > com.example.android.apis.tests/\ > org.kandroid.memtracer.MemoryInstrumentation
![Page 42: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/42.jpg)
42 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
4. Install the trace package as well as the application package.
5. Start the instrumentation with ‘am instrument’ in the shell.
6. Do interact with the application.
$ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk
$ adb shell am instrument -e class \ > com.example.android.apis.ApiDemos \ > com.example.android.apis.tests/\ > org.kandroid.memtracer.MemoryInstrumentation
![Page 43: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/43.jpg)
43 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
4. Install the trace package as well as the application package.
5. Start the instrumentation with ‘am instrument’ in the shell.
6. Do interact with the application.
7. Pull the trace file ‘kmemtrace.csv’ from /sdcard/kmemtracer.
$ adb install –r ApiDemos.apk $ adb install –r ApiDemosTest.apk
$ adb shell am instrument -e class \ > com.example.android.apis.ApiDemos \ > com.example.android.apis.tests/\ > org.kandroid.memtracer.MemoryInstrumentation
$ adb pull /sdcard/kmemtracer/kmemtrace.csv .
![Page 44: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/44.jpg)
44 12th Kandroid Conference - www.kandroid.org
How to Use kmemtracer?
8. Open the trace file with Excel and create charts.
![Page 45: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/45.jpg)
45 12th Kandroid Conference - www.kandroid.org
Why Automated Historical Performance Testing?
kmemtracer: What and How?
Enhancement I : Automating UI Interaction
Enhancement II: Adding More Performance Metrics
Contents
![Page 46: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/46.jpg)
46 12th Kandroid Conference - www.kandroid.org
Automate Controlling UI
Test Package
Application Package
android.test. Instrumentation
TestRunner
org.kandroid. memtracer.Memory
Instrumentation
Control Track
Trace Package
![Page 47: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/47.jpg)
47 12th Kandroid Conference - www.kandroid.org
Automate Controlling UI
Test Package
Application Package
android.test. Instrumentation
TestRunner
org.kandroid. memtracer.Memory
Instrumentation
Control Track
Trace Package
![Page 48: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/48.jpg)
48 12th Kandroid Conference - www.kandroid.org
Automate Controlling UI
Test Package
Application Package
android.test. Instrumentation
TestRunner
org.kandroid. memtracer.Memory
Instrumentation
Control Track
Trace Package
![Page 49: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/49.jpg)
49 12th Kandroid Conference - www.kandroid.org
Three Alternatives
![Page 50: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/50.jpg)
50 12th Kandroid Conference - www.kandroid.org
Three Alternatives
Instrumentation
API Level 1 ~ Single activity Framework APIs White-box
http://developer.android.com/tools/testing/testing_android.html
![Page 51: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/51.jpg)
51 12th Kandroid Conference - www.kandroid.org
Three Alternatives
Instrumentation Robotium
API Level 1 ~ Single activity Framework APIs White-box
2010/01 ~ Multiple activities High-level APIs White-box & black-box
http://developer.android.com/tools/testing/testing_android.html https://code.google.com/p/robotium/
![Page 52: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/52.jpg)
52 12th Kandroid Conference - www.kandroid.org
Three Alternatives
Instrumentation Robotium uiautomator
API Level 1 ~ Single activity Framework APIs White-box
2010/01 ~ Multiple activities High-level APIs White-box & black-box
API Level 17 ~ Multiple processes Simple APIs Black-box
http://developer.android.com/tools/testing/testing_android.html https://code.google.com/p/robotium/ http://developer.android.com/tools/testing/testing_ui.html
![Page 53: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/53.jpg)
53 12th Kandroid Conference - www.kandroid.org
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples
![Page 54: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/54.jpg)
54 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples
![Page 55: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/55.jpg)
55 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
https://github.com/snailee/deview-2013-samples
![Page 56: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/56.jpg)
56 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
Scroll down
https://github.com/snailee/deview-2013-samples
![Page 57: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/57.jpg)
57 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
Scroll down
https://github.com/snailee/deview-2013-samples
![Page 58: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/58.jpg)
58 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
Scroll down
Click
https://github.com/snailee/deview-2013-samples
![Page 59: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/59.jpg)
59 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
Scroll down
Click
https://github.com/snailee/deview-2013-samples
![Page 60: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/60.jpg)
60 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
Scroll down
Click Click
https://github.com/snailee/deview-2013-samples
![Page 61: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/61.jpg)
61 12th Kandroid Conference - www.kandroid.org
Click
Case Study: ApiDemos
Scroll down
Click Click
https://github.com/snailee/deview-2013-samples
![Page 62: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/62.jpg)
62 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
![Page 63: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/63.jpg)
63 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
1. Create an Android Test Project for the test package.
$ android create test-project --main ../ApiDemos \ > –-name ApiDemosInstrumentTest --path ApiDemosInstrumentTest
![Page 64: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/64.jpg)
64 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
1. Create an Android Test Project for the test package.
2. Add a test class inheriting ActivityInstrumentationTestCase2.
$ android create test-project --main ../ApiDemos \ > –-name ApiDemosInstrumentTest --path ApiDemosInstrumentTest
public class ApiDemosInstrumentTest extends ActivityInstrumentationTestCase2<ApiDemos> { ... public ApiDemosInstrumentTest() { super(ApiDemos.class); }
![Page 65: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/65.jpg)
65 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
1. Create an Android Test Project for the test package.
2. Add a test class inheriting ActivityInstrumentationTestCase2.
3. Add a test method and launch the activity.
$ android create test-project --main ../ApiDemos \ > –-name ApiDemosInstrumentTest --path ApiDemosInstrumentTest
public class ApiDemosInstrumentTest extends ActivityInstrumentationTestCase2<ApiDemos> { ... public ApiDemosInstrumentTest() { super(ApiDemos.class); }
public void testNavigate() { final ApiDemos apiDemos = getActivity(); ... }
![Page 66: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/66.jpg)
66 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
public void testNavigate() { ...
4. Find and act on a control.
![Page 67: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/67.jpg)
67 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
public void testNavigate() { ... final ListView demoList = apiDemos.getListView(); final View graphicsDemo = getChildViewByText(demoList, "Graphics"); assertNotNull("Graphics demo should exist", graphicsDemo);
Find a view to control
4. Find and act on a control.
![Page 68: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/68.jpg)
68 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
public void testNavigate() { ... final ListView demoList = apiDemos.getListView(); final View graphicsDemo = getChildViewByText(demoList, "Graphics"); assertNotNull("Graphics demo should exist", graphicsDemo); apiDemos.runOnUiThread(new Runnable() { public void run() { int pos = demoList.getPositionForView(graphicsDemo); demoList.smoothScrollToPosition(pos); demoList.setSelection(pos); demoList.performItemClick(graphicsDemo, pos, graphicsDemo.getId()); } }); ...
Find a view to control
Act on the view
4. Find and act on a control.
![Page 69: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/69.jpg)
69 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
public void testNavigate() { ... final ListView demoList = apiDemos.getListView(); final View graphicsDemo = getChildViewByText(demoList, "Graphics"); assertNotNull("Graphics demo should exist", graphicsDemo); apiDemos.runOnUiThread(new Runnable() { public void run() { int pos = demoList.getPositionForView(graphicsDemo); demoList.smoothScrollToPosition(pos); demoList.setSelection(pos); demoList.performItemClick(graphicsDemo, pos, graphicsDemo.getId()); } }); ...
Find a view to control
Act on the view
4. Find and act on a control.
![Page 70: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/70.jpg)
70 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private View getChildViewByText(ListView listView, String text) {
4. Find and act on a control: getChildViewByText.
![Page 71: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/71.jpg)
71 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i);
Iterate through child views
4. Find and act on a control: getChildViewByText.
![Page 72: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/72.jpg)
72 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); Log.e(TAG, i + "-th text view is " + textView); if (textView != null && textView.getText().equals(text)) { view = textView; break; } } return view; }
Iterate through child views
Compare texts
4. Find and act on a control: getChildViewByText.
![Page 73: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/73.jpg)
73 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private View getChildViewByText(ListView listView, String text) { View view = null; int count = listView.getCount(); Log.e(TAG, “no. children = " + count); for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); Log.e(TAG, i + "-th text view is " + textView); if (textView != null && textView.getText().equals(text)) { view = textView; break; } } return view; }
Iterate through child views
Compare texts
4. Find and act on a control: getChildViewByText.
com.example.android.apis.instrument.test.ApiDemosInstrumentTest: INSTRUMENTATION_RESULT: shortMsg=junit.framework.AssertionFailedError INSTRUMENTATION_RESULT: longMsg= junit.framework.AssertionFailedError: OpenGL ES demo should exist INSTRUMENTATION_CODE: 0
![Page 74: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/74.jpg)
74 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private View getChildViewByText(final ListView listView, String text) { ... for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); if (textView != null && textView.getText().equals(text)) { view = textView; break; } if (textView == null) { final int lastPos = listView.getLastVisiblePosition(); getInstrumentation().runOnMainSync(new Runnable() { public void run() { listView.smoothScrollToPosition(lastPos + 5, lastPos); } }); getInstrumentation().waitForIdleSync(); i = listView.getFirstVisiblePosition(); } } return view; }
4. Find and act on a control: Revised getChildViewByText.
![Page 75: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/75.jpg)
75 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private View getChildViewByText(final ListView listView, String text) { ... for (int i = 0; i < count; i++) { TextView textView = (TextView) listView.getChildAt(i); if (textView != null && textView.getText().equals(text)) { view = textView; break; } if (textView == null) { final int lastPos = listView.getLastVisiblePosition(); getInstrumentation().runOnMainSync(new Runnable() { public void run() { listView.smoothScrollToPosition(lastPos + 5, lastPos); } }); getInstrumentation().waitForIdleSync(); i = listView.getFirstVisiblePosition(); } } return view; }
Scroll down
4. Find and act on a control: Revised getChildViewByText.
![Page 76: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/76.jpg)
76 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private int getPositionForChildViewByText(ListView listView, String text) { ListAdapter listAdapter = listView.getAdapter(); int count = listAdapter.getCount(); Log.e(TAG, "children: " + count); for (int i = 0; i < count; i++) { String itemText = (String) ((Map)listAdapter.getItem(i)).get("title"); Log.e(TAG, i + "-th text item " + itemText); if (itemText != null && itemText.equals(text)) { return i; } } return -1; }
4. Find and act on a control: getPositionForChildViewByText.
... final ListView graphicsDemoList = graphicsDemoActivity.getListView(); int pos = getPositionForChildViewByText(graphicsDemoList, "OpenGL ES"); assertTrue("Cannot find OpenGL ES", pos != -1); ...
![Page 77: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/77.jpg)
77 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
private int getPositionForChildViewByText(ListView listView, String text) { ListAdapter listAdapter = listView.getAdapter(); int count = listAdapter.getCount(); Log.e(TAG, "children: " + count); for (int i = 0; i < count; i++) { String itemText = (String) ((Map)listAdapter.getItem(i)).get("title"); Log.e(TAG, i + "-th text item " + itemText); if (itemText != null && itemText.equals(text)) { return i; } } return -1; }
4. Find and act on a control: getPositionForChildViewByText.
... final ListView graphicsDemoList = graphicsDemoActivity.getListView(); int pos = getPositionForChildViewByText(graphicsDemoList, "OpenGL ES"); assertTrue("Cannot find OpenGL ES", pos != -1); ...
![Page 78: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/78.jpg)
78 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
5. Monitor a new Activity to launch.
public void testNavigate() { ... Instrumentation.ActivityMonitor graphicsDemoActivityMonitor = getInstrumentation().addMonitor( ApiDemos.class.getName(), null, false); final ApiDemos graphicsDemoActivity = (ApiDemos) graphicsDemoActivityMonitor.waitForActivity(); assertNotNull("Graphics Demo (ApiDemos) activity should not be null", graphicsDemoActivity); ...
![Page 79: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/79.jpg)
79 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
5. Monitor a new Activity to launch.
6. Iterate step 4 & 5.
public void testNavigate() { ... Instrumentation.ActivityMonitor graphicsDemoActivityMonitor = getInstrumentation().addMonitor( ApiDemos.class.getName(), null, false); final ApiDemos graphicsDemoActivity = (ApiDemos) graphicsDemoActivityMonitor.waitForActivity(); assertNotNull("Graphics Demo (ApiDemos) activity should not be null", graphicsDemoActivity); ...
![Page 80: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/80.jpg)
80 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
7. Build and Install the test package.
$ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
![Page 81: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/81.jpg)
81 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
7. Build and Install the test package.
8. Run the test and see the result.
$ adb shell am instrument -w \ > com.example.android.apis.instrument.test/\ > android.test.InstrumentationTestRunner
$ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
![Page 82: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/82.jpg)
82 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Instrumentation
7. Build and Install the test package.
8. Run the test and see the result.
$ adb shell am instrument -w \ > com.example.android.apis.instrument.test/\ > android.test.InstrumentationTestRunner
$ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
$ ant test
![Page 83: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/83.jpg)
83 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
![Page 84: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/84.jpg)
84 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
1. Create an Android Test Project for the test package.
$ android create test-project --main ../ApiDemos \ > –-name ApiDemosRobotiumTest --path ApiDemosRobotiumTest
![Page 85: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/85.jpg)
85 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
1. Create an Android Test Project for the test package.
2. Add ‘robotium-solo-<ver>.jar’ in the ‘libs’ directory.
$ android create test-project --main ../ApiDemos \ > –-name ApiDemosRobotiumTest --path ApiDemosRobotiumTest
![Page 86: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/86.jpg)
86 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
1. Create an Android Test Project for the test package.
2. Add ‘robotium-solo-<ver>.jar’ in the ‘libs’ directory.
3. Add a test class inheriting ActivityInstrumentationTestCase2.
$ android create test-project --main ../ApiDemos \ > –-name ApiDemosRobotiumTest --path ApiDemosRobotiumTest
public class ApiDemosRobotiumTest extends ActivityInstrumentationTestCase2<ApiDemos> { ... public ApiDemosRobotiumTest() { super(ApiDemos.class); } ...
![Page 87: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/87.jpg)
87 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
4. Create an instance of Solo in the setUp method and
close open activities in the tearDown method.
... private Solo solo; ... @Override public void setUp() throws Exception { solo = new Solo(getInstrumentation(), getActivity()); } @Override public void tearDown() throws Exception { solo.finishOpenedActivities(); } ...
![Page 88: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/88.jpg)
88 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
4. Find and act on a control.
public void testNavigate() { solo.assertCurrentActivity("Should be on ApiDemos", ApiDemos.class); solo.clickOnText("^Graphics$", 1, true); solo.assertCurrentActivity("Should be on a new ApiDemos", ApiDemos.class, true); solo.clickOnText("^OpenGL ES$", 1, true); solo.assertCurrentActivity("Should be on a new ApiDemos", ApiDemos.class, true); solo.clickOnText("^Kube$", 1, true); solo.assertCurrentActivity("Should be on a Kube", Kube.class, true); solo.sleep(3000); }
![Page 89: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/89.jpg)
89 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
6. Build and Install the test package.
$ cd ApiDemosRobotiumTest $ ant debug $ adb install –r bin/ApiDemosRobotiumTest-debug.apk
![Page 90: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/90.jpg)
90 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
6. Build and Install the test package.
7. Run the test and see the result.
$ adb shell am instrument -w \ > com.example.android.apis.robotium.test/\ > android.test.InstrumentationTestRunner
$ cd ApiDemosRobotiumTest $ ant debug $ adb install –r bin/ApiDemosRobotiumTest-debug.apk
![Page 91: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/91.jpg)
91 12th Kandroid Conference - www.kandroid.org
Controlling UI Using Robotium
6. Build and Install the test package.
7. Run the test and see the result.
$ adb shell am instrument -w \ > com.example.android.apis.robotium.test/\ > android.test.InstrumentationTestRunner
$ cd ApiDemosRobotiumTest $ ant debug $ adb install –r bin/ApiDemosRobotiumTest-debug.apk
$ ant test
![Page 92: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/92.jpg)
92 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
1. Create an Java Project for the test jar.
![Page 93: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/93.jpg)
93 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
1. Create an Java Project for the test jar.
2. Add ‘android.jar’ and ‘uiautomator.jar’ in the build path.
![Page 94: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/94.jpg)
94 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
1. Create an Java Project for the test jar.
2. Add ‘android.jar’ and ‘uiautomator.jar’ in the build path.
3. Add a test class inheriting UiAutomatorTestCase.
public class ApiDemosUiAutoTest extends UiAutomatorTestCase { ... }
![Page 95: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/95.jpg)
95 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException {
![Page 96: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/96.jpg)
96 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome();
Press home button
![Page 97: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/97.jpg)
97 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow();
Click ‘All Apps’ button
Press home button
![Page 98: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/98.jpg)
98 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click();
Click ‘All Apps’ button
Press home button
Click ‘Apps’ tab
![Page 99: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/99.jpg)
99 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click(); UiScrollable appList = new UiScrollable( new UiSelector().scrollable(true)); appList.setAsHorizontalList(); UiObject apiDemos = appList.getChildByText( new UiSelector().className(TextView.class.getName()), "API Demos"); apiDemos.clickAndWaitForNewWindow();
Click ‘All Apps’ button
Press home button
Click ‘Apps’ tab
Click ‘ApiDemos’ icon
![Page 100: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/100.jpg)
100 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
4. Launch ApiDemos.
public void testNavigate() throws UiObjectNotFoundException { getUiDevice().pressHome(); UiObject allAppsButton = new UiObject( new UiSelector().description("Apps")); allAppsButton.clickAndWaitForNewWindow(); UiObject appsTab = new UiObject(new UiSelector().text("Apps")); appsTab.click(); UiScrollable appList = new UiScrollable( new UiSelector().scrollable(true)); appList.setAsHorizontalList(); UiObject apiDemos = appList.getChildByText( new UiSelector().className(TextView.class.getName()), "API Demos"); apiDemos.clickAndWaitForNewWindow(); UiObject apiDemosPackage = new UiObject( new UiSelector().packageName("com.example.android.apis")); assertTrue("Should be on ApiDemos", apiDemosPackage.exists()); ...
Click ‘All Apps’ button
Press home button
Click ‘Apps’ tab
Click ‘ApiDemos’ icon
Validate the launch of ‘ApiDemos’
![Page 101: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/101.jpg)
101 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
5. Find and act on a control.
... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView")); UiObject graphicsDemo = demoList.getChildByText( new UiSelector().className(TextView.class.getName()), “Graphics"); graphicsDemo.clickAndWaitForNewWindow(); UiObject alphaBitmapDemo = new UiObject( new UiSelector().text(“AlphaBitmap")); assertTrue(“AlphaBitmap should be visible", alpahBitmapDemo.exists()); ...
![Page 102: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/102.jpg)
102 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
5. Find and act on a control.
6. Iterate step 5.
... UiScrollable demoList = new UiScrollable( new UiSelector().className("android.widget.ListView")); UiObject graphicsDemo = demoList.getChildByText( new UiSelector().className(TextView.class.getName()), “Graphics"); graphicsDemo.clickAndWaitForNewWindow(); UiObject alphaBitmapDemo = new UiObject( new UiSelector().text(“AlphaBitmap")); assertTrue(“AlphaBitmap should be visible", alpahBitmapDemo.exists()); ...
![Page 103: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/103.jpg)
103 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
$ android create uitest-project --name ApiDemosUiAutoTest \ > --target 1 --path ApiDemosUiAutoTest $ cd ApiDemosUiAutoTest $ ant build
![Page 104: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/104.jpg)
104 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
8. Install the jar on your test device.
$ android create uitest-project --name ApiDemosUiAutoTest \ > --target 1 --path ApiDemosUiAutoTest $ cd ApiDemosUiAutoTest $ ant build
$ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/
![Page 105: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/105.jpg)
105 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
8. Install the jar on your test device.
9. Run the test and view the test result.
$ android create uitest-project --name ApiDemosUiAutoTest \ > --target 1 --path ApiDemosUiAutoTest $ cd ApiDemosUiAutoTest $ ant build
$ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/
$ adb shell uiautomator runtest ApiDemosUiAutoTest.jar \ > –c com.example.android.apis.uiauto.test.ApiDemosUiAutoTest
![Page 106: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/106.jpg)
106 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
8. Install the jar on your test device.
9. Run the test and view the test result.
$ android create uitest-project --name ApiDemosUiAutoTest \ > --target 1 --path ApiDemosUiAutoTest $ cd ApiDemosUiAutoTest $ ant build
$ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/
$ adb shell uiautomator runtest ApiDemosUiAutoTest.jar \ > –c com.example.android.apis.uiauto.test.ApiDemosUiAutoTest
$ ant test
![Page 107: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/107.jpg)
107 12th Kandroid Conference - www.kandroid.org
Controlling UI Using uiautomator
7. Compile your test case into a JAR file.
8. Install the jar on your test device.
9. Run the test and view the test result.
$ android create uitest-project --name ApiDemosUiAutoTest \ > --target 1 --path ApiDemosUiAutoTest $ cd ApiDemosUiAutoTest $ ant build
$ adb push bin/ApiDemosUiAutoTest.jar /data/local/tmp/
$ adb shell uiautomator runtest ApiDemosUiAutoTest.jar \ > –c com.example.android.apis.uiauto.test.ApiDemosUiAutoTest
$ ant test
![Page 108: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/108.jpg)
108 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
![Page 109: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/109.jpg)
109 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
![Page 110: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/110.jpg)
110 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
![Page 111: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/111.jpg)
111 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
![Page 112: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/112.jpg)
112 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
1. Modify org.kandroid.memtracer.MemoryInstrumentation.
public class MemoryInstrumentation extends InstrumentationTestRunner { ... @Override public void onCreate(Bundle arguments) { ... start(); super.onCreate(arguments); } @Override public void onStart() { String mainActivityName = getMainActivityName(); if (mainActivityName != null && mainActivityName.length() > 0) { launchMainActivity(getTargetContext().getPackageName(), getMainActivityName()); } else { super.onStart(); } } ...
![Page 113: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/113.jpg)
113 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
![Page 114: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/114.jpg)
114 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> element in the manifest file.
![Page 115: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/115.jpg)
115 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> element in the manifest file.
4. Build and Install the test package.
$ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
![Page 116: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/116.jpg)
116 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> element in the manifest file.
4. Build and Install the test package.
5. Run the test and see the result.
$ adb shell am instrument -w \ > com.example.android.apis.instrument.test/\ > org.kandroid.memtracer.MemoryInstrumentation
$ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
![Page 117: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/117.jpg)
117 12th Kandroid Conference - www.kandroid.org
Doing both Controlling and Tracking
2. Add ‘kmemtracer-libs.jar’ in the ‘libs’ directory.
3. Edit the <instrumentation> element in the manifest file.
4. Build and Install the test package.
5. Run the test and see the result.
6. Pull the trace file ‘kmemtrace.csv’ from /sdcard/kmemtracer.
$ adb shell am instrument -w \ > com.example.android.apis.instrument.test/\ > org.kandroid.memtracer.MemoryInstrumentation
$ cd ApiDemosInstrumentTest $ ant debug $ adb install –r bin/ApiDemosInstrumentTest-debug.apk
$ adb pull /sdcard/kmemtracer/kmemtrace.csv .
![Page 118: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/118.jpg)
118 12th Kandroid Conference - www.kandroid.org
Instrument Robotium uiautomator
Compatibility O O X
Multi-activities O O
Multi-processes X X O
Ease of APIs X O
Black box X O
Comparison
![Page 119: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/119.jpg)
119 12th Kandroid Conference - www.kandroid.org
Why Automated Historical Performance Testing?
kmemtracer: What and How?
Enhancement I : Automating UI Interaction
Enhancement II: Adding More Performance Metrics
Contents
![Page 120: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/120.jpg)
120 12th Kandroid Conference - www.kandroid.org
What to Measure?
Rendering (or GUI) Performance Frame Rate (FPS), Frame Time , Jankiness, Input Latency, …
Resource Consumption Memory, CPU, I/O (Disk, Network), Battery, …
Network Performance Response time, Throughput, … …
![Page 121: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/121.jpg)
121 12th Kandroid Conference - www.kandroid.org
What to Measure?
Rendering (or GUI) Performance Frame Rate (FPS), Frame Time , Jankiness, Input Latency, …
Resource Consumption Memory, CPU, I/O (Disk, Network), Battery, …
Network Performance Response time, Throughput, … …
![Page 122: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/122.jpg)
122 12th Kandroid Conference - www.kandroid.org
How to Measure Resource Consumption?
![Page 123: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/123.jpg)
123 12th Kandroid Conference - www.kandroid.org
How to Measure Resource Consumption?
API cmds
![Page 124: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/124.jpg)
124 12th Kandroid Conference - www.kandroid.org
How to Measure Resource Consumption?
API cmds
Public Internal
![Page 125: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/125.jpg)
125 12th Kandroid Conference - www.kandroid.org
How to Measure Resource Consumption?
API cmds
Public Internal Android Linux
![Page 126: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/126.jpg)
126 12th Kandroid Conference - www.kandroid.org
How to Measure Resource Consumption?
API cmds
Public Internal Android Linux
Easy Flexible
![Page 127: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/127.jpg)
127 12th Kandroid Conference - www.kandroid.org
Measuring Memory Usage
![Page 128: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/128.jpg)
128 12th Kandroid Conference - www.kandroid.org
Measuring Memory Usage
Public
android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo
![Page 129: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/129.jpg)
129 12th Kandroid Conference - www.kandroid.org
Measuring Memory Usage
Public Internal
android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo
dalvik.system.VMDebug
![Page 130: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/130.jpg)
130 12th Kandroid Conference - www.kandroid.org
Measuring Memory Usage
Public Internal Android
android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo
adb shell dumpsys meminfo [pid|pname] adb shell dumpsys gfxinfo [pid|pname] adb shell procrank
dalvik.system.VMDebug
![Page 131: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/131.jpg)
131 12th Kandroid Conference - www.kandroid.org
Measuring Memory Usage
Public Internal Android Linux
android.app.ActivityManager.MemoryInfo android.os.Debug android.os.Debug.MemoryInfo
adb shell dumpsys meminfo [pid|pname] adb shell dumpsys gfxinfo [pid|pname] adb shell procrank
adb shell cat /proc/meminfo adb shell cat /proc/<pid>/[s]maps adb shell cat /proc/vmstat adb shell top adb shell ps
dalvik.system.VMDebug
![Page 132: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/132.jpg)
132 12th Kandroid Conference - www.kandroid.org
$ adb shell dumpsys meminfo com.example.android.apis Applications Memory Usage (kB): Uptime: 93065 Realtime: 93065 ** MEMINFO in pid 1259 [com.example.android.apis] ** native dalvik other total size: 3548 5831 N/A 9379 allocated: 3475 3335 N/A 6810 free: 48 2496 N/A 2544 (Pss): 699 382 4889 5970 (shared dirty): 1500 1876 8356 11732 (priv dirty): 628 40 2472 3140 ...
GB (API Level 10)
Measuring Memory Usage: dumpsys meminfo
![Page 133: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/133.jpg)
133 12th Kandroid Conference - www.kandroid.org
$ adb shell dumpsys meminfo com.example.android.apis Applications Memory Usage (kB): Uptime: 93065 Realtime: 93065 ** MEMINFO in pid 1259 [com.example.android.apis] ** native dalvik other total size: 3548 5831 N/A 9379 allocated: 3475 3335 N/A 6810 free: 48 2496 N/A 2544 (Pss): 699 382 4889 5970 (shared dirty): 1500 1876 8356 11732 (priv dirty): 628 40 2472 3140 ...
GB (API Level 10)
Measuring Memory Usage: dumpsys meminfo
![Page 134: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/134.jpg)
134 12th Kandroid Conference - www.kandroid.org
$ adb shell dumpsys meminfo com.example.android.apis ... ** MEMINFO in pid 1875 [com.example.android.apis] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 1377 1256 1300 12084 7332 567 Dalvik 5274 5476 4952 6260 5712 548 Stack 76 12 76 Cursor 0 0 0 Ashmem 0 0 0 Other dev 4 20 0 .so mmap 1526 4836 592 .jar mmap 0 0 0 .apk mmap 267 0 0 .ttf mmap 5 0 0 .dex mmap 1085 0 0 Other mmap 18 8 4 Unknown 824 0 824 TOTAL 10456 11608 7748 18344 13044 1115 ...
JB (API Level 18)
Measuring Memory Usage: dumpsys meminfo
![Page 135: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/135.jpg)
135 12th Kandroid Conference - www.kandroid.org
$ adb shell dumpsys meminfo com.example.android.apis ... ** MEMINFO in pid 1875 [com.example.android.apis] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 1377 1256 1300 12084 7332 567 Dalvik 5274 5476 4952 6260 5712 548 Stack 76 12 76 Cursor 0 0 0 Ashmem 0 0 0 Other dev 4 20 0 .so mmap 1526 4836 592 .jar mmap 0 0 0 .apk mmap 267 0 0 .ttf mmap 5 0 0 .dex mmap 1085 0 0 Other mmap 18 8 4 Unknown 824 0 824 TOTAL 10456 11608 7748 18344 13044 1115 ...
JB (API Level 18)
Measuring Memory Usage: dumpsys meminfo
![Page 136: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/136.jpg)
136 12th Kandroid Conference - www.kandroid.org
https://android.googlesource.com/platform/frameworks/base.git/+/0e3328fbdd3845b0e2bec364e951498eaee6b079
![Page 137: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/137.jpg)
137 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys meminfo’ works?
adb shell dumpsys meminfo [-a] [-oom] [-process]
![Page 138: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/138.jpg)
138 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys meminfo’ works?
com.android.server.am. ActivityManagerService
adb shell dumpsys meminfo [-a] [-oom] [-process]
![Page 139: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/139.jpg)
139 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys meminfo’ works?
com.android.server.am. ActivityManagerService
android.os Debug
android.app.ActivityThread. ApplicationThread
adb shell dumpsys meminfo [-a] [-oom] [-process]
android.app.ActivityThread. ApplicationThread
android.app.ActivityThread. ApplicationThread
![Page 140: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/140.jpg)
140 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys meminfo’ works?
com.android.server.am. ActivityManagerService
android.os Debug
android.app.ActivityThread. ApplicationThread
adb shell dumpsys meminfo [-a] [-oom] [-process]
android.app.ActivityThread. ApplicationThread
android.app.ActivityThread. ApplicationThread
![Page 141: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/141.jpg)
141 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys meminfo’ works?
com.android.server.am. ActivityManagerService
android.os Debug
android.app.ActivityThread. ApplicationThread
/proc/<pid>/smaps
adb shell dumpsys meminfo [-a] [-oom] [-process]
mallinfo()
getNativeHeap*() getMemoryInfo()
android.app.ActivityThread. ApplicationThread
android.app.ActivityThread. ApplicationThread
![Page 142: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/142.jpg)
142 12th Kandroid Conference - www.kandroid.org
android.app.ActivityThread.ApplicationThread.dumpMemInfo()
long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); Runtime runtime = Runtime.getRuntime(); long dalvikMax = runtime.totalMemory() / 1024; long dalvikFree = runtime.freeMemory() / 1024; long dalvikAllocated = dalvikMax - dalvikFree;
How ‘dumpsys meminfo’ works?
![Page 143: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/143.jpg)
143 12th Kandroid Conference - www.kandroid.org
android.app.ActivityThread.ApplicationThread.dumpMemInfo()
long nativeMax = Debug.getNativeHeapSize() / 1024; long nativeAllocated = Debug.getNativeHeapAllocatedSize() / 1024; long nativeFree = Debug.getNativeHeapFreeSize() / 1024; Debug.MemoryInfo memInfo = new Debug.MemoryInfo(); Debug.getMemoryInfo(memInfo); Runtime runtime = Runtime.getRuntime(); long dalvikMax = runtime.totalMemory() / 1024; long dalvikFree = runtime.freeMemory() / 1024; long dalvikAllocated = dalvikMax - dalvikFree;
struct mallinfo info = mallinfo(); (jlong) info.usmblks; // Debug.getNativeHeapSize() (jlong) info.uordblks; // Debug.getNativeHeapAllocatedSize() (jlong) info.fordblks; // Debug.getNativeHeapFreeSize()
android.os.Debug.getNativeHeap*()
How ‘dumpsys meminfo’ works?
![Page 144: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/144.jpg)
144 12th Kandroid Conference - www.kandroid.org
struct mallinfo { MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ MALLINFO_FIELD_TYPE smblks; /* always 0 */ MALLINFO_FIELD_TYPE hblks; /* always 0 */ MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ MALLINFO_FIELD_TYPE fordblks; /* total free space */ MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ };
bionic\libc\upstream-dlmalloc\malloc.c
① Total allocated = uordblks ② Total free = fordblks ③ Footprint = uordblks + fordblks ④ Max footprint = usmblks
2
1
3
4
How ‘dumpsys meminfo’ works?
![Page 145: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/145.jpg)
145 12th Kandroid Conference - www.kandroid.org
Measuring CPU Usage
![Page 146: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/146.jpg)
146 12th Kandroid Conference - www.kandroid.org
Measuring CPU Usage
Public
android.os.Process android.os.Debug.InstructionCount
![Page 147: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/147.jpg)
147 12th Kandroid Conference - www.kandroid.org
Measuring CPU Usage
Public Internal
android.os.Process android.os.Debug.InstructionCount
com.android.internal.os.ProcessStats
![Page 148: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/148.jpg)
148 12th Kandroid Conference - www.kandroid.org
Measuring CPU Usage
Public Internal Android
android.os.Process android.os.Debug.InstructionCount
adb shell dumpsys cpuinfo
com.android.internal.os.ProcessStats
![Page 149: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/149.jpg)
149 12th Kandroid Conference - www.kandroid.org
Measuring CPU Usage
Public Internal Android Linux
android.os.Process android.os.Debug.InstructionCount
adb shell dumpsys cpuinfo
adb shell cat /proc/stat adb shell cat /proc/<pid>/stat adb shell top
com.android.internal.os.ProcessStats
![Page 150: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/150.jpg)
150 12th Kandroid Conference - www.kandroid.org
Measuring CPU Usage: dumpsys cpuinfo
$ adb shell dumpsys cpuinfo Load: 0.0 / 0.01 / 0.05 CPU usage from 27006ms to 5405ms ago: 1.1% 1421/com.android.launcher: 0.3% user + 0.8% kernel / faults: 2187 minor 2.4% 1225/system_server: 0.4% user + 1.9% kernel / faults: 2030 minor 0.1% 949/surfaceflinger: 0% user + 0.1% kernel / faults: 3 minor 0% 952/mediaserver: 0% user + 0% kernel / faults: 8 minor 0% 959/adbd: 0% user + 0% kernel / faults: 11 minor 0% 1295/com.android.systemui: 0% user + 0% kernel / faults: 5 minor +0% 1901/com.example.android.apis: 0% user + 0% kernel 56% TOTAL: 10% user + 45% kernel + 0.7% softirq
![Page 151: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/151.jpg)
151 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys cpuinfo’ works?
adb shell dumpsys cpuinfo
![Page 152: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/152.jpg)
152 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys cpuinfo’ works?
adb shell dumpsys cpuinfo
com.android.server.am. ActivityManagerService
![Page 153: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/153.jpg)
153 12th Kandroid Conference - www.kandroid.org
com.android.internal.os ProcessStats
How ‘dumpsys cpuinfo’ works?
adb shell dumpsys cpuinfo
com.android.server.am. ActivityManagerService
![Page 154: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/154.jpg)
154 12th Kandroid Conference - www.kandroid.org
com.android.internal.os ProcessStats
com.android.internal.os ProcessStats.Stats
com.android.internal.os ProcessStats.Stats
com.android.internal.os ProcessStats.Stats
How ‘dumpsys cpuinfo’ works?
adb shell dumpsys cpuinfo
com.android.server.am. ActivityManagerService
![Page 155: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/155.jpg)
155 12th Kandroid Conference - www.kandroid.org
com.android.internal.os ProcessStats
com.android.internal.os ProcessStats.Stats
android.os Process
com.android.internal.os ProcessStats.Stats
com.android.internal.os ProcessStats.Stats
android_util_Process.cpp
How ‘dumpsys cpuinfo’ works?
adb shell dumpsys cpuinfo
/proc/stat /proc/loadavg /proc/<pid>/stat /proc/<ppid>/task/<pid>/stat
com.android.server.am. ActivityManagerService
![Page 156: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/156.jpg)
156 12th Kandroid Conference - www.kandroid.org
How ‘dumpsys cpuinfo’ works?
procfs (or the proc filesystem) is a special filesystem in UNIX-
like operating systems that presents information about processes
and other system information in a hierarchical file-like structure,
providing a more convenient and standardized method for
dynamically accessing process data held in the kernel than
traditional tracing methods or direct access to kernel memory.
http://en.wikipedia.org/wiki/Procfs
![Page 157: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/157.jpg)
157 12th Kandroid Conference - www.kandroid.org
http://manpages.courier-mta.org/htmlman5/proc.5.html
How ‘dumpsys cpuinfo’ works?
procfs (or the proc filesystem) is a special filesystem in UNIX-
like operating systems that presents information about processes
and other system information in a hierarchical file-like structure,
providing a more convenient and standardized method for
dynamically accessing process data held in the kernel than
traditional tracing methods or direct access to kernel memory.
http://en.wikipedia.org/wiki/Procfs
![Page 158: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/158.jpg)
158 12th Kandroid Conference - www.kandroid.org
Measuring I/O Usage
![Page 159: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/159.jpg)
159 12th Kandroid Conference - www.kandroid.org
Measuring I/O Usage
Public
android.net.TrafficStats
![Page 160: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/160.jpg)
160 12th Kandroid Conference - www.kandroid.org
Measuring I/O Usage
Public Internal
android.net.TrafficStats
android.net.NetworkStats android.net.NetworkStatsHistory com.android.internal.net.NetworkStatsFactory
![Page 161: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/161.jpg)
161 12th Kandroid Conference - www.kandroid.org
Measuring I/O Usage
Public Internal Android
android.net.TrafficStats
adb shell dumpsys netstats adb shell dumpsys diskstats
android.net.NetworkStats android.net.NetworkStatsHistory com.android.internal.net.NetworkStatsFactory
![Page 162: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/162.jpg)
162 12th Kandroid Conference - www.kandroid.org
Measuring I/O Usage
Public Internal Android Linux
android.net.TrafficStats
adb shell dumpsys netstats adb shell dumpsys diskstats
/proc/net/*
android.net.NetworkStats android.net.NetworkStatsHistory com.android.internal.net.NetworkStatsFactory
![Page 163: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/163.jpg)
163 12th Kandroid Conference - www.kandroid.org
Measuring Network IO Usage: dumpsys netstats
$ adb shell dumpsys netstats Active interfaces: iface=eth0 ident=[[type=MOBILE, subType=COMBINED, subscriberId=310260000000000]] Dev stats: Pending bytes: 43783 History since boot: ident=[[type=MOBILE_HIPRI, subType=COMBINED, subscriberId=310260000000000], [type=MOBILE, subType=COMBINED, subscriberId=310260000000000]] uid=-1 set=ALL tag=0x0 NetworkStatsHistory: bucketDuration=3600000 bucketStart=1382443200000 activeTime=4813 rxBytes=17410 rxPackets=203 txBytes=25579 txPackets=173 operations=0 ... Xt stats: Pending bytes: 37557 History since boot: ident=[[type=MOBILE_HIPRI, subType=COMBINED, subscriberId=310260000000000], [type=MOBILE, subType=COMBINED, subscriberId=310260000000000]] uid=-1 set=ALL tag=0x0 ... UID stats: ... UID tag stats: ...
![Page 164: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/164.jpg)
164 12th Kandroid Conference - www.kandroid.org
adb shell dumpsys netstats [--full] [--uid] [--tag]
How ‘dumpsys netstats’ works?
![Page 165: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/165.jpg)
165 12th Kandroid Conference - www.kandroid.org
com.android.server.net. NetworkStatsService
adb shell dumpsys netstats [--full] [--uid] [--tag]
How ‘dumpsys netstats’ works?
![Page 166: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/166.jpg)
166 12th Kandroid Conference - www.kandroid.org
com.android.server.net. NetworkStatsService
com.android.server.net NetworkStatsRecorder
adb shell dumpsys netstats [--full] [--uid] [--tag]
How ‘dumpsys netstats’ works?
com.android.server.net NetworkStatsRecorder
com.android.server.net NetworkStatsRecorder
com.android.server.net NetworkStatsRecorder
![Page 167: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/167.jpg)
167 12th Kandroid Conference - www.kandroid.org
com.android.server.net. NetworkStatsService
android.net NetworkStatsHistory
com.android.server.net NetworkStatsCollection
com.android.server.net NetworkStatsRecorder
adb shell dumpsys netstats [--full] [--uid] [--tag]
How ‘dumpsys netstats’ works?
com.android.server.net NetworkStatsRecorder
com.android.server.net NetworkStatsRecorder
com.android.server.net NetworkStatsRecorder
android.net NetworkStatsHistory
android.net NetworkStatsHistory
![Page 168: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/168.jpg)
168 12th Kandroid Conference - www.kandroid.org
com.android.internal.net NetworkStatsFactory
com.android.server.net. NetworkStatsService
android.net NetworkStats
android.net NetworkStatsHistory
com.android.server.net NetworkStatsCollection
com.android.server.net NetworkStatsRecorder
adb shell dumpsys netstats [--full] [--uid] [--tag]
How ‘dumpsys netstats’ works?
com.android.server.net NetworkStatsRecorder
com.android.server.net NetworkStatsRecorder
com.android.server.net NetworkStatsRecorder
android.net NetworkStatsHistory
android.net NetworkStatsHistory
/proc/net/xt_qtaguid/iface_stat_all /proc/net/xt_qtaguid/iface_stat_fmt /proc/net/xt_qtaguid/stats
com.android.server NetworkManagementService
![Page 169: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/169.jpg)
169 12th Kandroid Conference - www.kandroid.org
@Override public Config getDevConfig() { return new Config(getSecureLong(NETSTATS_DEV_BUCKET_DURATION, HOUR_IN_MILLIS), getSecureLong(NETSTATS_DEV_ROTATE_AGE, 15 * DAY_IN_MILLIS), getSecureLong(NETSTATS_DEV_DELETE_AGE, 90 * DAY_IN_MILLIS)); } @Override public Config getXtConfig() { return getDevConfig(); } @Override public Config getUidConfig() { return new Config(getSecureLong(NETSTATS_UID_BUCKET_DURATION, 2 * HOUR_IN_MILLIS), getSecureLong(NETSTATS_UID_ROTATE_AGE, 15 * DAY_IN_MILLIS), getSecureLong(NETSTATS_UID_DELETE_AGE, 90 * DAY_IN_MILLIS)); } @Override public Config getUidTagConfig() { return new Config(getSecureLong(NETSTATS_UID_TAG_BUCKET_DURATION, 2 * HOUR_IN_MILLIS), getSecureLong(NETSTATS_UID_TAG_ROTATE_AGE, 5 * DAY_IN_MILLIS), getSecureLong(NETSTATS_UID_TAG_DELETE_AGE, 15 * DAY_IN_MILLIS)); }
How ‘dumpsys netstats’ works?
com.android.server.net.NetworkStatsService.DefaultNetworkStatsSettings
![Page 170: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/170.jpg)
170 12th Kandroid Conference - www.kandroid.org
$ adb shell cat /proc/net/xt_qtaguid/iface_stat_all eth0 1 0 0 0 0 220609 3228 2891157 2995
$ adb shell cat /proc/net/xt_qtaguid/iface_stat_fmt ifname total_skb_rx_bytes total_skb_rx_packets total_skb_tx_bytes total_skb_tx_packets eth0 163781 3231 2846738 2994
Dev: IP + Non IP layer traffic
Xt: Only IP layer traffic
$ adb shell cat /proc/net/xt_qtaguid/stats idx iface acct_tag_hex uid_tag_int cnt_set rx_bytes rx_packets tx_bytes tx_packets rx_tcp_bytes rx_tcp_packets rx_udp_bytes rx_udp_packets rx_other_bytes rx_other_packets tx_tcp_bytes tx_tcp_packets tx_udp_bytes tx_udp_packets tx_other_bytes tx_other_packets 2 eth0 0x0 0 0 163335 3226 2846228 2988 161473 3222 1862 4 0 0 2845850 2982 266 4 112 2 3 eth0 0x0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 eth0 0x0 1000 0 819 11 965 12 667 9 152 2 0 0 813 10 152 2 0 0 5 eth0 0x0 1000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Uid: UID level details
How ‘dumpsys netstats’ works?
![Page 171: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/171.jpg)
171 12th Kandroid Conference - www.kandroid.org
Measuring Battery Usage
![Page 172: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/172.jpg)
172 12th Kandroid Conference - www.kandroid.org
Measuring Battery Usage
Public
android.os.BatteryManager
![Page 173: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/173.jpg)
173 12th Kandroid Conference - www.kandroid.org
Measuring Battery Usage
Public Internal
android.os.BatteryManager
android.os.BatteryStats com.android.internal.os.BatteryStatsImpl com.android.internal.os.PowerProfile com.android.server.os.BatteryStatsService
![Page 174: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/174.jpg)
174 12th Kandroid Conference - www.kandroid.org
Measuring Battery Usage
Public Internal Android
android.os.BatteryManager
adb shell dumpsys battery adb shell dumpsys batteryinfo
android.os.BatteryStats com.android.internal.os.BatteryStatsImpl com.android.internal.os.PowerProfile com.android.server.os.BatteryStatsService
![Page 175: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/175.jpg)
175 12th Kandroid Conference - www.kandroid.org
Measuring Battery Usage
Public Internal Android Linux
android.os.BatteryManager
adb shell dumpsys battery adb shell dumpsys batteryinfo
None (?)
android.os.BatteryStats com.android.internal.os.BatteryStatsImpl com.android.internal.os.PowerProfile com.android.server.os.BatteryStatsService
![Page 176: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/176.jpg)
176 12th Kandroid Conference - www.kandroid.org
$ adb shell dumpsys batteryinfo Battery History: -1d00h43m02s057ms START -1d00h40m00s730ms 050 20080002 status=charging health=good plug=ac temp=0 volt=0 +plugged +sensor brightness=medium -1d00h39m57s332ms 050 60080002 +wake_lock -1d00h39m57s202ms 050 60080302 phone_state=off ... Per-PID Stats: PID 1227 wake time: +3s445ms PID 1227 wake time: +199ms ... Statistics since last charge: System starts: 29, currently on battery: false Time on battery: 0ms (0.0%) realtime, 0ms (0.0%) uptime Total run time: 1d 2h 1m 3s 606ms realtime, 1d 2h 1m 3s 603ms uptime, ... #1000: User activity: 26 other, 27 button, 93 touch Sensor 0: (not used) Apk com.android.keychain: (nothing executed) ... Statistics since last unplugged: Time on battery: 0ms (0.0%) realtime, 0ms (0.0%) uptime ...
Measuring Battery Usage: dumpsys batteryinfo
![Page 177: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/177.jpg)
177 12th Kandroid Conference - www.kandroid.org
adb shell dumpsys batteryinfo
How ‘dumpsys batteryinfo’ works?
![Page 178: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/178.jpg)
178 12th Kandroid Conference - www.kandroid.org
com.android.server.am. BatteryStatsService
adb shell dumpsys batteryinfo
How ‘dumpsys batteryinfo’ works?
![Page 179: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/179.jpg)
179 12th Kandroid Conference - www.kandroid.org
com.android.internal.os BatteryStatsImpl
com.android.server.am. BatteryStatsService
adb shell dumpsys batteryinfo
How ‘dumpsys batteryinfo’ works?
![Page 180: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/180.jpg)
180 12th Kandroid Conference - www.kandroid.org
com.android.internal.os BatteryStatsImpl
android.os BatteryStats
com.android.server.am. BatteryStatsService
adb shell dumpsys batteryinfo
How ‘dumpsys batteryinfo’ works?
![Page 181: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/181.jpg)
181 12th Kandroid Conference - www.kandroid.org
com.android.internal.os BatteryStatsImpl
android.os BatteryStats
com.android.server.am. BatteryStatsService
adb shell dumpsys batteryinfo
How ‘dumpsys batteryinfo’ works?
noteBluetoothOff() noteBluetoothOn() noteFullWifiLockAcquired(int) noteFullWifiLockAcquiredFromSource(WorkSource) noteFullWifiLockReleased(int) noteFullWifiLockReleasedFromSource(WorkSource) noteInputEvent() noteNetworkInterfaceType(String, int) notePhoneDataConnectionState(int, boolean) notePhoneOff() notePhoneOn() notePhoneSignalStrength(SignalStrength) notePhoneState(int) noteScreenBrightness(int) noteScreenOff() noteScreenOn() ... noteWifiScanStarted(int) noteWifiScanStartedFromSource(WorkSource) noteWifiScanStopped(int) noteWifiScanStoppedFromSource(WorkSource) noteWifiStopped(WorkSource)
![Page 182: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/182.jpg)
182 12th Kandroid Conference - www.kandroid.org
If you can’t automate the measurement of it,
it is difficult to improve it.
![Page 183: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/183.jpg)
183 12th Kandroid Conference - www.kandroid.org
If you can’t automate the measurement of it,
it is difficult to improve it.
If you can’t understand the measurement results,
it is impossible to improve it.
![Page 184: Automated Historical Performance Analysis with kmemtracer](https://reader033.vdocuments.pub/reader033/viewer/2022052903/557957d8d8b42ab6648b4b94/html5/thumbnails/184.jpg)