58
Android: A Bunch of Tools Romain Guy @romainguy http://www.curious-creature.org/+

Android tools - 17 avril 2012

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Android tools - 17 avril 2012

Android: A Bunch of ToolsRomain Guy@romainguyhttp://www.curious-creature.org/+

Page 2: Android tools - 17 avril 2012

Command line

Page 3: Android tools - 17 avril 2012

$ adb bugreport

Page 4: Android tools - 17 avril 2012

$ adb shell dumpsys

Page 5: Android tools - 17 avril 2012

$ adb shell dumpsys meminfo <process>

Page 6: Android tools - 17 avril 2012

** MEMINFO in pid 1523 [com.example.android.sample] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 3260 944 3220 9960 6359 20 Dalvik 6952 15612 6344 21319 16224 5095 Cursor 0 0 0 Ashmem 0 0 0 Other dev 12583 660 1096 .so mmap 1149 1812 352 .jar mmap 0 0 0 .apk mmap 114 0 0 .ttf mmap 7 0 0 .dex mmap 807 0 0 Other mmap 44 8 28 Unknown 1439 356 1424 TOTAL 26355 19392 12464 31279 22583 5115

1 of 2

Page 7: Android tools - 17 avril 2012

** MEMINFO in pid 1523 [com.example.android.sample] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 3260 944 3220 9960 6359 20 Dalvik 6952 15612 6344 21319 16224 5095 Cursor 0 0 0 Ashmem 0 0 0 Other dev 12583 660 1096 .so mmap 1149 1812 352 .jar mmap 0 0 0 .apk mmap 114 0 0 .ttf mmap 7 0 0 .dex mmap 807 0 0 Other mmap 44 8 28 Unknown 1439 356 1424 TOTAL 26355 19392 12464 31279 22583 5115

1 of 2

Page 8: Android tools - 17 avril 2012

** MEMINFO in pid 1523 [com.example.android.sample] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 3260 944 3220 9960 6359 20 Dalvik 6952 15612 6344 21319 16224 5095 Cursor 0 0 0 Ashmem 0 0 0 Other dev 12583 660 1096 .so mmap 1149 1812 352 .jar mmap 0 0 0 .apk mmap 114 0 0 .ttf mmap 7 0 0 .dex mmap 807 0 0 Other mmap 44 8 28 Unknown 1439 356 1424 TOTAL 26355 19392 12464 31279 22583 5115

1 of 2

Page 9: Android tools - 17 avril 2012

** MEMINFO in pid 1523 [com.example.android.sample] ** Shared Private Heap Heap Heap Pss Dirty Dirty Size Alloc Free ------ ------ ------ ------ ------ ------ Native 3260 944 3220 9960 6359 20 Dalvik 6952 15612 6344 21319 16224 5095 Cursor 0 0 0 Ashmem 0 0 0 Other dev 12583 660 1096 .so mmap 1149 1812 352 .jar mmap 0 0 0 .apk mmap 114 0 0 .ttf mmap 7 0 0 .dex mmap 807 0 0 Other mmap 44 8 28 Unknown 1439 356 1424 TOTAL 26355 19392 12464 31279 22583 5115

1 of 2

Page 10: Android tools - 17 avril 2012

2 of 2

Objects Views: 45 ViewRootImpl: 1 AppContexts: 2 Activities: 1 Assets: 2 AssetManagers: 2 Local Binders: 13 Proxy Binders: 14 Death Recipients: 0 OpenSSL Sockets: 0 SQL heap: 0 MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0 Asset Allocations zip:/data/app/com.example.android.sample-2.apk:/resources.arsc: 2K

Page 11: Android tools - 17 avril 2012

2 of 2

Objects Views: 45 ViewRootImpl: 1 AppContexts: 2 Activities: 1 Assets: 2 AssetManagers: 2 Local Binders: 13 Proxy Binders: 14 Death Recipients: 0 OpenSSL Sockets: 0 SQL heap: 0 MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0 Asset Allocations zip:/data/app/com.example.android.sample-2.apk:/resources.arsc: 2K

Page 12: Android tools - 17 avril 2012

2 of 2

Objects Views: 45 ViewRootImpl: 1 AppContexts: 2 Activities: 1 Assets: 2 AssetManagers: 2 Local Binders: 13 Proxy Binders: 14 Death Recipients: 0 OpenSSL Sockets: 0 SQL heap: 0 MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0 Asset Allocations zip:/data/app/com.example.android.sample-2.apk:/resources.arsc: 2K

Page 13: Android tools - 17 avril 2012

$ adb shell dumpsys gfxinfo <process>

Page 14: Android tools - 17 avril 2012

Caches:Current memory usage / total memory usage (bytes): TextureCache 1166964 / 25165824 LayerCache 0 / 16777216 GradientCache 0 / 524288 PathCache 0 / 4194304 CircleShapeCache 0 / 1048576 OvalShapeCache 0 / 1048576 RoundRectShapeCache 0 / 1048576 RectShapeCache 0 / 1048576 ArcShapeCache 0 / 1048576 TextDropShadowCache 0 / 2097152 FontRenderer 0 262144 / 262144 FontRenderer 1 262144 / 262144 FontRenderer 2 262144 / 262144Other: FboCache 1 / 16 PatchCache 22 / 512Total memory usage: 1953396 bytes, 1.86 MB

View hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists)

Total ViewRootImpl: 1Total Views: 45Total DisplayList: 4.97 kB

Page 15: Android tools - 17 avril 2012

Caches:Current memory usage / total memory usage (bytes): TextureCache 1166964 / 25165824 LayerCache 0 / 16777216 GradientCache 0 / 524288 PathCache 0 / 4194304 CircleShapeCache 0 / 1048576 OvalShapeCache 0 / 1048576 RoundRectShapeCache 0 / 1048576 RectShapeCache 0 / 1048576 ArcShapeCache 0 / 1048576 TextDropShadowCache 0 / 2097152 FontRenderer 0 262144 / 262144 FontRenderer 1 262144 / 262144 FontRenderer 2 262144 / 262144Other: FboCache 1 / 16 PatchCache 22 / 512Total memory usage: 1953396 bytes, 1.86 MB

View hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists)

Total ViewRootImpl: 1Total Views: 45Total DisplayList: 4.97 kB

Page 16: Android tools - 17 avril 2012

Caches:Current memory usage / total memory usage (bytes): TextureCache 1166964 / 25165824 LayerCache 0 / 16777216 GradientCache 0 / 524288 PathCache 0 / 4194304 CircleShapeCache 0 / 1048576 OvalShapeCache 0 / 1048576 RoundRectShapeCache 0 / 1048576 RectShapeCache 0 / 1048576 ArcShapeCache 0 / 1048576 TextDropShadowCache 0 / 2097152 FontRenderer 0 262144 / 262144 FontRenderer 1 262144 / 262144 FontRenderer 2 262144 / 262144Other: FboCache 1 / 16 PatchCache 22 / 512Total memory usage: 1953396 bytes, 1.86 MB

View hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists)

Total ViewRootImpl: 1Total Views: 45Total DisplayList: 4.97 kB

Page 17: Android tools - 17 avril 2012

And more...

Page 18: Android tools - 17 avril 2012

Tracking memory

Page 19: Android tools - 17 avril 2012

Memory tracking tools

• DDMS heap dump– hat, Eclipse MAT

• Allocation Tracker

Page 20: Android tools - 17 avril 2012

More information

• Eclipse Memory Analyzer (MAT)– Supported by ADT– http://eclipse.org/mat/

• Memory Management for Android Apps– Google I/O 2011– http://www.google.com/events/io/2011/sessions/memory-

management-for-android-apps.html

Page 21: Android tools - 17 avril 2012

DemoDDMS & hat

Page 22: Android tools - 17 avril 2012

Tracking... stuff

Page 23: Android tools - 17 avril 2012

DemoDDMS graphs

Page 24: Android tools - 17 avril 2012

Analyzing performance

Page 25: Android tools - 17 avril 2012

Performance analysis tools

• Frame rate• traceview

Page 26: Android tools - 17 avril 2012

Tracking Frame Rate

Page 27: Android tools - 17 avril 2012

Framerate counter

preDrawListener = new OnPreDrawListener() { @Override public boolean onPreDraw() { trackFPS(); return true; }};

ViewTreeObserver observer = view.getViewTreeObserver();observer.addOnPreDrawListener(preDrawListener);

Page 28: Android tools - 17 avril 2012

private void trackFPS() { long nowTime = System.currentTimeMillis(); if (mFpsStartTime < 0) { mFpsStartTime = mFpsPrevTime = nowTime; mFpsNumFrames = 0; } else { ++mFpsNumFrames; long frameTime = nowTime - mFpsPrevTime; long totalTime = nowTime - mFpsStartTime; Log.d("FPS", "Frame time:\t" + frameTime); mFpsPrevTime = nowTime; if (totalTime > 1000) { float fps = (float) mFpsNumFrames * 1000 / totalTime; Log.d("FPS", "FPS:\t" + fps); mFpsStartTime = nowTime; mFpsNumFrames = 0; } }}

long mFpsStartTime = -1;long mFpsPrevTime = -1;int mFpsNumFrames = 0;

Page 29: Android tools - 17 avril 2012

Framerate counter

• Use code on preceding slides in your onDraw() method• Or if you can change the source

– Set DEBUG_FPS to true in ViewRootImpl.java– Rebuild frameworks

Page 30: Android tools - 17 avril 2012

Demotraceview

Page 31: Android tools - 17 avril 2012

Hardware

Page 32: Android tools - 17 avril 2012

HDMI Capture

• 60 fps recording• Frame by frame replay• Requires fast computer• Requires HDMI output on device

– Xoom– Galaxy Nexus

• e.g. BlackMagic Intensity Pro

Page 33: Android tools - 17 avril 2012
Page 34: Android tools - 17 avril 2012

High-speed Camera

• Great framerate– 60 to 1200 fps

• Low resolution & affordable– e.g. Casio EX-F1 300fps@512x384

• High resolution & (very) expensive– e.g. RED EPIC-M 300fps@2048x854

• Support all devices

Page 35: Android tools - 17 avril 2012
Page 36: Android tools - 17 avril 2012

DemoHDMI recorder and high-speed camera

Page 37: Android tools - 17 avril 2012

HierarchyViewer

Page 38: Android tools - 17 avril 2012

@ViewDebug.ExportedProperty

Page 39: Android tools - 17 avril 2012

@ViewDebug.ExportedProperty

• Fields• Methods

– No argument– Return value– i.e. getters

Page 40: Android tools - 17 avril 2012

@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), @ViewDebug.IntToString(from = GONE, to = "GONE")})int mVisibility;

Page 41: Android tools - 17 avril 2012

@ViewDebug.ExportedProperty(resolveId = true)int mID = NO_ID;

Page 42: Android tools - 17 avril 2012

@ViewDebug.ExportedProperty( deepExport = true, prefix = "layout_")public ViewGroup.LayoutParams getLayoutParams() { return mLayoutParams;}

Page 43: Android tools - 17 avril 2012

Limitations

• Does not work on retail devices– “user” builds– Security reasons

• Works on– “userdebug” builds– “eng” builds– emulator

Page 44: Android tools - 17 avril 2012

ViewServerhttps://github.com/romainguy/ViewServer

Page 45: Android tools - 17 avril 2012

public class ViewServerActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

ViewServer.get(this).addWindow(this); } @Override public void onDestroy() { super.onDestroy(); ViewServer.get(this).removeWindow(this); } @Override public void onResume() { super.onResume(); ViewServer.get(this).setFocusedWindow(this); }}

Page 46: Android tools - 17 avril 2012

public class ViewServerActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

ViewServer.get(this).addWindow(this); } @Override public void onDestroy() { super.onDestroy(); ViewServer.get(this).removeWindow(this); } @Override public void onResume() { super.onResume(); ViewServer.get(this).setFocusedWindow(this); }}

Page 47: Android tools - 17 avril 2012

public class ViewServerActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

ViewServer.get(this).addWindow(this); } @Override public void onDestroy() { super.onDestroy(); ViewServer.get(this).removeWindow(this); } @Override public void onResume() { super.onResume(); ViewServer.get(this).setFocusedWindow(this); }}

Page 48: Android tools - 17 avril 2012

public class ViewServerActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);

ViewServer.get(this).addWindow(this); } @Override public void onDestroy() { super.onDestroy(); ViewServer.get(this).removeWindow(this); } @Override public void onResume() { super.onResume(); ViewServer.get(this).setFocusedWindow(this); }}

Page 49: Android tools - 17 avril 2012

ViewServer

• Single class– Apache 2.0 license– Requires INTERNET permission

• API works with– Activity– Window

• Only– for your app– for debuggable apps– on user builds

Page 50: Android tools - 17 avril 2012

layoutopt

Page 51: Android tools - 17 avril 2012

layoutoptlint

Page 52: Android tools - 17 avril 2012

lint

$ lint frameworks/base/tests/ChetBugs/TextViewScale

AndroidManifest.xml: Warning: Manifest should specify a minimum API level with <uses-sdk android:minSdkVersion="?" />; if it really supports all versions of Android set it to 1. [UsesSdk]res/drawable-hdpi/change_background.png: Warning: The resource R.drawable.change_background appears to be unused [UnusedResources]res/drawable-hdpi/gbread.jpg: Warning: The resource R.drawable.gbread appears to be unused [UnusedResources]res/drawable-hdpi/gbread_sm.jpg: Warning: The resource R.drawable.gbread_sm appears to be unused [UnusedResources]res/drawable-hdpi/refresh.png: Warning: The resource R.drawable.refresh appears to be unused [UnusedResources]res/drawable-hdpi/self_portrait.jpg: Warning: The resource R.drawable.self_portrait appears to be unused [UnusedResources]res/drawable-hdpi/gbread.jpg: Warning: The image gbread.jpg varies significantly in its density-independent (dip) size across the various density versions: drawable-mdpi/gbread.jpg: 2560x1920 dp (2560x1920 px), drawable-hdpi/gbread.jpg: 1707x1280 dp (2560x1920 px) [IconDipSize]res/drawable-hdpi/gbread_sm.jpg: Warning: The image gbread_sm.jpg varies significantly in its density-independent (dip) size across the various density versions: drawable-mdpi/gbread_sm.jpg: 480x640 dp (480x640 px), drawable-hdpi/gbread_sm.jpg: 320x427 dp (480x640 px) [IconDipSize]res/drawable-hdpi/self_portrait.jpg: Warning: The image self_portrait.jpg varies significantly in its density-independent (dip) size across the various density versions: drawable-mdpi/self_portrait.jpg: 671x800 dp (671x800 px), drawable-hdpi/self_portrait.jpg: 447x533 dp (671x800 px) [IconDipSize]res/drawable-mdpi/gbread.jpg: Warning: The gbread.jpg icon has identical contents in the following configuration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res/drawable-mdpi/gbread_sm.jpg: Warning: The gbread_sm.jpg icon has identical contents in the following configuration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res/drawable-mdpi/self_portrait.jpg: Warning: The self_portrait.jpg icon has identical contents in the following configuration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res/drawable-mdpi/self_portrait.jpg: Warning: The self_portrait.jpg icon has identical contents in the following configuration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder]0 errors, 13 warnings

Page 53: Android tools - 17 avril 2012

Better yet, use html$ lint frameworks/base/tests/ChetBugs/TextViewScale --html ~/tmp/lintoutput.html

Page 54: Android tools - 17 avril 2012

Future tools

Page 55: Android tools - 17 avril 2012

OpenGL Monitor

• Tracing• Profiling• State tracking• Capture

– Framebuffer– Intermediate drawing stages– Textures

Page 56: Android tools - 17 avril 2012

DemoOpenGL Monitor

Page 57: Android tools - 17 avril 2012
Page 58: Android tools - 17 avril 2012

Q & A