Android: A Bunch of Tools
Romain Guy
@romainguy
http://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
                   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
** 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
** 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
** 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
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




                                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




                                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




                                2 of 2
$ adb shell dumpsys gfxinfo <process>
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 /   262144
Other:
  FboCache                     1 /       16
  PatchCache                  22 /      512
Total memory usage:
  1953396 bytes, 1.86 MB

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

Total ViewRootImpl: 1
Total Views:        45
Total DisplayList: 4.97 kB
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 /   262144
Other:
  FboCache                     1 /       16
  PatchCache                  22 /      512
Total memory usage:
  1953396 bytes, 1.86 MB

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

Total ViewRootImpl: 1
Total Views:        45
Total DisplayList: 4.97 kB
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 /   262144
Other:
  FboCache                     1 /       16
  PatchCache                  22 /      512
Total memory usage:
  1953396 bytes, 1.86 MB

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

Total ViewRootImpl: 1
Total Views:        45
Total DisplayList: 4.97 kB
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 Android Apps
 – Google I/O 2011
 – http://www.google.com/events/io/2011/sessions/memory-
   management-for-android-apps.html
Demo
DDMS & hat
Tracking... stuff
Demo
DDMS graphs
Analyzing performance
Performance analysis tools
• Frame rate
• traceview
Tracking Frame Rate
Framerate counter



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

 ViewTreeObserver observer = view.getViewTreeObserver();
 observer.addOnPreDrawListener(preDrawListener);
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;
        }
    }
}
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
Demo
traceview
Hardware
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
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
Demo
HDMI 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.IntToString(from = INVISIBLE, to = "INVISIBLE"),
    @ViewDebug.IntToString(from = GONE, to = "GONE")
})
int mVisibility;
@ViewDebug.ExportedProperty(resolveId = true)
int mID = NO_ID;
@ViewDebug.ExportedProperty(
        deepExport = true,
        prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() {
    return mLayoutParams;
}
Limitations
• Does not work on retail devices
 – “user” builds
 – Security reasons
• Works on
 – “userdebug” builds
 – “eng” builds
 – emulator
ViewServer
https://github.com/romainguy/ViewServer
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);
    }
}
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);
    }
}
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);
    }
}
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);
    }
}
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
layoutopt
li n t
layoutopt
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
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
Demo
OpenGL Monitor
Q&A

Android tools - 17 avril 2012

  • 1.
    Android: A Bunchof Tools Romain Guy @romainguy http://www.curious-creature.org/+
  • 2.
  • 3.
  • 4.
    $ adb shelldumpsys
  • 5.
    $ adb shelldumpsys meminfo <process>
  • 6.
    ** MEMINFO inpid 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.
    ** MEMINFO inpid 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.
    ** MEMINFO inpid 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.
    ** MEMINFO inpid 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.
    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 2 of 2
  • 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: 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 2 of 2
  • 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: 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 2 of 2
  • 13.
    $ adb shelldumpsys gfxinfo <process>
  • 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 / 262144 Other: FboCache 1 / 16 PatchCache 22 / 512 Total memory usage: 1953396 bytes, 1.86 MB View hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists) Total ViewRootImpl: 1 Total Views: 45 Total DisplayList: 4.97 kB
  • 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 / 262144 Other: FboCache 1 / 16 PatchCache 22 / 512 Total memory usage: 1953396 bytes, 1.86 MB View hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists) Total ViewRootImpl: 1 Total Views: 45 Total DisplayList: 4.97 kB
  • 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 / 262144 Other: FboCache 1 / 16 PatchCache 22 / 512 Total memory usage: 1953396 bytes, 1.86 MB View hierarchy: android.view.ViewRootImpl@40b82f70: 45 views, 4.97 kB (display lists) Total ViewRootImpl: 1 Total Views: 45 Total DisplayList: 4.97 kB
  • 17.
  • 18.
  • 19.
    Memory tracking tools •DDMS heap dump – hat, Eclipse MAT • Allocation Tracker
  • 20.
    More information • EclipseMemory 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.
  • 22.
  • 23.
  • 24.
  • 25.
    Performance analysis tools •Frame rate • traceview
  • 26.
  • 27.
    Framerate counter preDrawListener= new OnPreDrawListener() { @Override public boolean onPreDraw() { trackFPS(); return true; } }; ViewTreeObserver observer = view.getViewTreeObserver(); observer.addOnPreDrawListener(preDrawListener);
  • 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.
    Framerate counter • Usecode 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.
  • 31.
  • 32.
    HDMI Capture • 60fps recording • Frame by frame replay • Requires fast computer • Requires HDMI output on device – Xoom – Galaxy Nexus • e.g. BlackMagic Intensity Pro
  • 34.
    High-speed Camera • Greatframerate – 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
  • 36.
    Demo HDMI recorder andhigh-speed camera
  • 37.
  • 38.
  • 39.
    @ViewDebug.ExportedProperty • Fields • Methods – No argument – Return value – i.e. getters
  • 40.
    @ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"), @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"), @ViewDebug.IntToString(from = GONE, to = "GONE") }) int mVisibility;
  • 41.
  • 42.
    @ViewDebug.ExportedProperty( deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams() { return mLayoutParams; }
  • 43.
    Limitations • Does notwork on retail devices – “user” builds – Security reasons • Works on – “userdebug” builds – “eng” builds – emulator
  • 44.
  • 45.
    public class ViewServerActivityextends 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.
    public class ViewServerActivityextends 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.
    public class ViewServerActivityextends 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); } }
  • 48.
    public class ViewServerActivityextends 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); } }
  • 49.
    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
  • 50.
  • 51.
  • 52.
    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
  • 53.
    Better yet, usehtml $ lint frameworks/base/tests/ChetBugs/TextViewScale --html ~/tmp/lintoutput.html
  • 54.
  • 55.
    OpenGL Monitor • Tracing •Profiling • State tracking • Capture – Framebuffer – Intermediate drawing stages – Textures
  • 56.
  • 58.