background preloader


Facebook Twitter

Performance instrumentation for Android apps. This post describes some of the challenges we faced in collecting performance telemetry from our Android apps and how we approached them.

Performance instrumentation for Android apps

Here at Facebook we always strive to make our apps faster. While we have systems like CTScan to track performance internally, the Android ecosystem is far too diverse for us to test every possibility in the lab. So we also work to complement our testing data with telemetry from real phones in the hands of real people. For the longest time, this telemetry was limited to painstakingly inserted code, indicating the beginning and end of some high-level action — for example, News Feed pull-to-refresh.

An engineer would find the first touch event handler to start the marker and then a corresponding screen update location to end the marker. The primary problem with this approach is that you receive telemetry about only those things you could predict would influence performance. At this point, it's worth discussing a few of the options we rejected: Android’s Font Renderer. Any developer with a few years of experience writing client-side applications is acutely aware of how complicated text rendering can be.

Android’s Font Renderer

At least that’s what I thought until 2010 when I started writing libhwui, an OpenGL backend for Android 3.0’s 2D drawing API. I then realized that text gets even more complicated when you’re trying to use a GPU to draw it on screen. Text and Android Android’s hardware accelerated font renderer was originally written by a co-worker on the Renderscript team and was then improved upon and optimized by several engineers including my good friend Chet Haase and I. You can easily find many tutorials on how to render text with OpenGL but most — if not all — articles focus on games and conveniently avoid dealing with difficult issues.The approach described here is by no means novel but I thought it would be convenient for some developers to get a high-level overview of how a complete GPU-based text rendering system can be implemented.

Text APIs. An Android app to slow your test device down. - RecursiveRobot. I’ve got a bunch of Android devices at my desk, most of which are several years old.

An Android app to slow your test device down. - RecursiveRobot

I need them for testing the apps that I work on, both to make sure that they work consistently across OEMs, but also to see how the app performs on older devices. The problem that I kept running into was that the old devices would feel faster than my newer phone, simply because there wasn’t as much running on them. The Solution Add some load to those test devices! I decided to create this app to make the phone do some sort of constant and predictable work in the background. I also tried to architect and design the thing in a sane way, hopefully it’s not too difficult to understand.

In addition to launching and configuring manually, there is an API that allows you to broadcast an intent, with all the configuration options that you get in the UI! And, when you’re done, you can kill it too: TimingLogger. Class Overview A utility class to help log timings splits throughout a method call.


Typical usage is: TimingLogger timings = new TimingLogger(TAG, "methodA"); // ... do some work A ... timings.addSplit("work A"); // ... do some work B ... timings.addSplit("work B"); // ... do some work C ... timings.addSplit("work C"); timings.dumpToLog(); The dumpToLog call would add the following to the log: D/TAG ( 3459): methodA: begin D/TAG ( 3459): methodA: 9 ms, work A D/TAG ( 3459): methodA: 1 ms, work B D/TAG ( 3459): methodA: 6 ms, work C D/TAG ( 3459): methodA: end, 16 ms Summary Public Constructors public TimingLogger (String tag, String label) Create and initialize a TimingLogger object that will log using the specific tag.

Parameters Public Methods public void addSplit (String splitLabel) Add a split for the current time, labeled with splitLabel. Public void dumpToLog () Smoothing performance on Fragment transitions. Suppose you're doing a pretty standard Fragment replacement with a custom animation: getSupportFragmentManager() .beginTransaction() .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out) .replace(, new MyFragment()) .commit(); You may notice that the performance can be a bit rough, not as smooth as you'd like.

Smoothing performance on Fragment transitions

A common way to improve Android animation performance is to use hardware layers. Normally you'd add it to the animation directly but with fragments you don't get access to it unless you take advantage of Fragment.onCreateAnimation()*. Multithreading For Performance. [This post is by Gilles Debunne, an engineer in the Android group who loves to get multitasked. — Tim Bray] A good practice in creating responsive applications is to make sure your main UI thread does the minimum amount of work.

Multithreading For Performance

Any potentially long task that may hang your application should be handled in a different thread. Typical examples of such tasks are network operations, which involve unpredictable delays. Users will tolerate some pauses, especially if you provide feedback that something is in progress, but a frozen application gives them no clue. In this article, we will create a simple image downloader that illustrates this pattern. An Image downloader Downloading an image from the web is fairly simple, using the HTTP-related classes provided by the framework. Static Bitmap downloadBitmap(String url) { final AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); final HttpGet getRequest = new HttpGet(url); Slides et vidéo "Android rendu et performance" par Romain Guy le 17 avril 2012. – juin 21, 2012Classé dans : Compte-rendu De passage à Paris pour Devoxx France, Romain Guy, ingénieur Android chez Google spécialisé sur l’application Home et l’UI Toolkit, est intervenu le 17 avril 2012 au Google Master Class organisé par Telecom Paritech Entrepreneurs.

Slides et vidéo "Android rendu et performance" par Romain Guy le 17 avril 2012

Il a parlé de Rendu et de Performance sur Android. Nous vous proposons quelques notes, les slides et une vidéo de sa présentation: Pas de traitement dans UI RunnableStrict mode: pour afficher logs, messsages erreur, afficher flash à l’écran. TrafficStats. Class Overview Class that provides network traffic statistics.


These statistics include bytes transmitted and received and network packets transmitted and received, over all interfaces, over the mobile interface, and on a per-UID basis. These statistics may not be available on all platforms. If the statistics are not supported by this device, UNSUPPORTED will be returned. Summary Constants public static final int UNSUPPORTED The return value to indicate that the device does not support the statistic. Constant Value: -1 (0xffffffff) Optimizing Downloads for Efficient Network Access. Using the wireless radio to transfer data is potentially one of your app's most significant sources of battery drain.

Optimizing Downloads for Efficient Network Access

To minimize the battery drain associated with network activity, it's critical that you understand how your connectivity model will affect the underlying radio hardware. This lesson introduces the wireless radio state machine and explains how your app's connectivity model interacts with it. It goes on to propose ways to minimize your data connections, use prefetching, and bundle your transfers in order to minimize the battery drain associated with your data transfers. The Radio State Machine A fully active wireless radio consumes significant power, so it transitions between different energy states in order to conserve power when not in use, while attempting to minimize latency associated with "powering up" the radio when it's required. The state machine for a typical 3G network radio consists of three energy states: Hardware - How does Android calculate battery consumption by apps.

Current community your communities Sign up or log in to customize your list. more stack exchange communities Stack Exchange sign up log in tour help.

hardware - How does Android calculate battery consumption by apps

StrictMode. StrictMode is a developer tool which detects things you might be doing by accident and brings them to your attention so you can fix them. StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications.

By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users. Note that even though an Android device's disk is often on flash memory, many devices run a filesystem on top of that memory with very limited concurrency. It's often the case that almost all disk accesses are fast, but may in individual cases be dramatically slower when certain I/O is happening in the background from other processes. Android 3.0 Hardware Acceleration. [This post is by Romain Guy, who likes things on your screen to move fast. —Tim Bray] One of the biggest changes we made to Android for Honeycomb is the addition of a new rendering pipeline so that applications can benefit from hardware accelerated 2D graphics.

Hardware accelerated graphics is nothing new to the Android platform, it has always been used for windows composition or OpenGL games for instance, but with this new rendering pipeline applications can benefit from an extra boost in performance. On a Motorola Xoom device, all the standard applications like Browser and Calendar use hardware-accelerated 2D graphics. In this article, I will show you how to enable the hardware accelerated 2D graphics pipeline in your application and give you a few tips on how to use it properly.

Go faster To enable the hardware accelerated 2D graphics, open your AndroidManifest.xml file and add the following attribute to the <application /> tag: ProGuard.