Android: A Bunch of ToolsRomain Guy@romainguyhttp://www.curious-creature.org/+
Command line
$ adb bugreport
$ adb shell dumpsys
$ adb shell dumpsys meminfo <process>
** MEMINFO in pid 1523 [com.example.android.sample] **                         Shared Private      Heap      Heap     Heap...
** MEMINFO in pid 1523 [com.example.android.sample] **                         Shared Private      Heap      Heap     Heap...
** MEMINFO in pid 1523 [com.example.android.sample] **                         Shared Private      Heap      Heap     Heap...
** MEMINFO in pid 1523 [com.example.android.sample] **                         Shared Private      Heap      Heap     Heap...
Objects                 Views:    45             ViewRootImpl:    1           AppContexts:     2               Activities:...
Objects                 Views:    45             ViewRootImpl:    1           AppContexts:     2               Activities:...
Objects                 Views:    45             ViewRootImpl:    1           AppContexts:     2               Activities:...
$ adb shell dumpsys gfxinfo <process>
Caches:Current memory usage / total memory usage (bytes):  TextureCache           1166964 / 25165824  LayerCache          ...
Caches:Current memory usage / total memory usage (bytes):  TextureCache           1166964 / 25165824  LayerCache          ...
Caches:Current memory usage / total memory usage (bytes):  TextureCache           1166964 / 25165824  LayerCache          ...
And more...
Tracking memory
Memory tracking tools• DDMS heap dump – hat, Eclipse MAT• Allocation Tracker
More information• Eclipse Memory Analyzer (MAT) – Supported by ADT – http://eclipse.org/mat/• Memory Management for Androi...
DemoDDMS & hat
Tracking... stuff
DemoDDMS graphs
Analyzing performance
Performance analysis tools• Frame rate• traceview
Tracking Frame Rate
Framerate counter preDrawListener = new OnPreDrawListener() {     @Override     public boolean onPreDraw() {         track...
long mFpsStartTime = -1;long mFpsPrevTime = -1;int mFpsNumFrames = 0;private void trackFPS() {    long nowTime = System.cu...
Framerate counter• Use code on preceding slides in your onDraw() method• Or if you can change the source – Set DEBUG_FPS t...
Demotraceview
Hardware
HDMI Capture• 60 fps recording• Frame by frame replay• Requires fast computer• Requires HDMI output on device – Xoom – Gal...
High-speed Camera• Great framerate – 60 to 1200 fps• Low resolution & affordable – e.g. Casio EX-F1 300fps@512x384• High r...
DemoHDMI recorder and high-speed camera
HierarchyViewer
@ViewDebug.ExportedProperty
@ViewDebug.ExportedProperty• Fields• Methods  – No argument  – Return value  – i.e. getters
@ViewDebug.ExportedProperty(mapping = {    @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"),    @ViewDebug.IntToStri...
@ViewDebug.ExportedProperty(resolveId = true)int mID = NO_ID;
@ViewDebug.ExportedProperty(        deepExport = true,        prefix = "layout_")public ViewGroup.LayoutParams getLayoutPa...
Limitations• Does not work on retail devices – “user” builds – Security reasons• Works on – “userdebug” builds – “eng” bui...
ViewServerhttps://github.com/romainguy/ViewServer
public class ViewServerActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {      ...
public class ViewServerActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {      ...
public class ViewServerActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {      ...
public class ViewServerActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {      ...
ViewServer• Single class  – Apache 2.0 license  – Requires INTERNET permission• API works with  – Activity  – Window• Only...
layoutopt
li n tlayoutopt
lint$ lint frameworks/base/tests/ChetBugs/TextViewScaleAndroidManifest.xml: Warning: Manifest should specify a minimum API...
Better yet, use html$ lint frameworks/base/tests/ChetBugs/TextViewScale --html ~/tmp/lintoutput.html
Future tools
OpenGL Monitor• Tracing• Profiling• State tracking• Capture  – Framebuffer  – Intermediate drawing stages  – Textures
DemoOpenGL Monitor
Q&A
Android tools - 17 avril 2012
Android tools - 17 avril 2012
Android tools - 17 avril 2012
Upcoming SlideShare
Loading in …5
×

Android tools - 17 avril 2012

3,366 views

Published on

Published in: Technology, Business
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,366
On SlideShare
0
From Embeds
0
Number of Embeds
763
Actions
Shares
0
Downloads
114
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Android tools - 17 avril 2012

  1. 1. Android: A Bunch of ToolsRomain Guy@romainguyhttp://www.curious-creature.org/+
  2. 2. Command line
  3. 3. $ adb bugreport
  4. 4. $ adb shell dumpsys
  5. 5. $ adb shell dumpsys meminfo <process>
  6. 6. ** 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
  7. 7. ** 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
  8. 8. ** 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
  9. 9. ** 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
  10. 10. Objects Views: 45 ViewRootImpl: 1 AppContexts: 2 Activities: 1 Assets: 2 AssetManagers: 2 Local Binders: 13 Proxy Binders: 14 Death Recipients: 0 OpenSSL Sockets: 0SQL heap: 0 MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0Asset Allocations zip:/data/app/com.example.android.sample-2.apk:/resources.arsc: 2K 2 of 2
  11. 11. Objects Views: 45 ViewRootImpl: 1 AppContexts: 2 Activities: 1 Assets: 2 AssetManagers: 2 Local Binders: 13 Proxy Binders: 14 Death Recipients: 0 OpenSSL Sockets: 0SQL heap: 0 MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0Asset Allocations zip:/data/app/com.example.android.sample-2.apk:/resources.arsc: 2K 2 of 2
  12. 12. Objects Views: 45 ViewRootImpl: 1 AppContexts: 2 Activities: 1 Assets: 2 AssetManagers: 2 Local Binders: 13 Proxy Binders: 14 Death Recipients: 0 OpenSSL Sockets: 0SQL heap: 0 MEMORY_USED: 0 PAGECACHE_OVERFLOW: 0 MALLOC_SIZE: 0Asset Allocations zip:/data/app/com.example.android.sample-2.apk:/resources.arsc: 2K 2 of 2
  13. 13. $ adb shell dumpsys gfxinfo <process>
  14. 14. 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 MBView hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists)Total ViewRootImpl: 1Total Views: 45Total DisplayList: 4.97 kB
  15. 15. 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 MBView hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists)Total ViewRootImpl: 1Total Views: 45Total DisplayList: 4.97 kB
  16. 16. 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 MBView hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists)Total ViewRootImpl: 1Total Views: 45Total DisplayList: 4.97 kB
  17. 17. And more...
  18. 18. Tracking memory
  19. 19. Memory tracking tools• DDMS heap dump – hat, Eclipse MAT• Allocation Tracker
  20. 20. 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
  21. 21. DemoDDMS & hat
  22. 22. Tracking... stuff
  23. 23. DemoDDMS graphs
  24. 24. Analyzing performance
  25. 25. Performance analysis tools• Frame rate• traceview
  26. 26. Tracking Frame Rate
  27. 27. Framerate counter preDrawListener = new OnPreDrawListener() { @Override public boolean onPreDraw() { trackFPS(); return true; } }; ViewTreeObserver observer = view.getViewTreeObserver(); observer.addOnPreDrawListener(preDrawListener);
  28. 28. long mFpsStartTime = -1;long mFpsPrevTime = -1;int mFpsNumFrames = 0;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; } }}
  29. 29. 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
  30. 30. Demotraceview
  31. 31. Hardware
  32. 32. 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
  33. 33. 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
  34. 34. DemoHDMI recorder and high-speed camera
  35. 35. HierarchyViewer
  36. 36. @ViewDebug.ExportedProperty
  37. 37. @ViewDebug.ExportedProperty• Fields• Methods – No argument – Return value – i.e. getters
  38. 38. @ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), @ViewDebug.IntToString(from = GONE, to = "GONE")})int mVisibility;
  39. 39. @ViewDebug.ExportedProperty(resolveId = true)int mID = NO_ID;
  40. 40. @ViewDebug.ExportedProperty( deepExport = true, prefix = "layout_")public ViewGroup.LayoutParams getLayoutParams() { return mLayoutParams;}
  41. 41. Limitations• Does not work on retail devices – “user” builds – Security reasons• Works on – “userdebug” builds – “eng” builds – emulator
  42. 42. ViewServerhttps://github.com/romainguy/ViewServer
  43. 43. 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); }}
  44. 44. 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); }}
  45. 45. 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); }}
  46. 46. 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); }}
  47. 47. 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
  48. 48. layoutopt
  49. 49. li n tlayoutopt
  50. 50. lint$ lint frameworks/base/tests/ChetBugs/TextViewScaleAndroidManifest.xml: Warning: Manifest should specify a minimum API level with <uses-sdkandroid: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 (671x800px), 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 configurationfolders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res/drawable-mdpi/gbread_sm.jpg: Warning: The gbread_sm.jpg icon has identical contents in the followingconfiguration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res/drawable-mdpi/self_portrait.jpg: Warning: The self_portrait.jpg icon has identical contents in the followingconfiguration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res/drawable-mdpi/self_portrait.jpg: Warning: The self_portrait.jpg icon has identical contents in the followingconfiguration folders: drawable-hdpi, drawable-mdpi [IconDuplicatesConfig]res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder]0 errors, 13 warnings
  51. 51. Better yet, use html$ lint frameworks/base/tests/ChetBugs/TextViewScale --html ~/tmp/lintoutput.html
  52. 52. Future tools
  53. 53. OpenGL Monitor• Tracing• Profiling• State tracking• Capture – Framebuffer – Intermediate drawing stages – Textures
  54. 54. DemoOpenGL Monitor
  55. 55. Q&A

×