Exploring Qt Performance on ARM using FineToothComb

Published Tuesday September 29th, 2009
6 Comments on Exploring Qt Performance on ARM using FineToothComb
Posted in Performance, Symbian

Have you ever been developing an app, and at some point wanted to know exactly which code was being run, and for how long, when you used it?

On the path to getting Qt inside your Nokia devices, we’ve recently been making use of a special Nokia tool for doing just that, and I thought I would give you a short behind-the-scenes tour of it so that you can see how serious we are about taking Qt everywhere.

If you’ve ever tried to speed up some of your own code before, you probably used some kind of profiling tool. Valgrind is a good example, and one that is heavily used in the development of Desktop Qt.

Desktops normally use x86 processors, but away from the desktop and running on batteries, ARM processors are most widely used. These systems tend to have quite a different architecture from desktop computers, as well as slower clocks and smaller caches. So some effort is needed to make software run fast on them because the performance bottlenecks can also be quite different.

One feature ARM-based chips often have which you don’t find on the desktop is ETM. Using this, the ARM can send trace information about every instruction it executes out through a dedicated debug port in real time, without slowing down execution of the software at all.

As ARMs usually run at hundreds of MHz, ETM creates a large amount of data in a very short time, so you have capture it using an external box with a few Gbytes of RAM. For cost reasons, you won’t ever find an ETM port on a device you buy in the shops, but during development of the devices, special versions are often made with just such a port.

Here’s a picture of a “special device” which is ETM-enabled, along with the Lauterbach PowerTrace II I use to capture the data:

ETM with "special device" running Qt

Even with Gigs of RAM, you can only trace for about 10 seconds or so. Although that doesn’t sound like much, it’s actually enough to take a look at almost all interesting use cases.

Ok, so now I’ve got all that data, how do I make some sense of it? This is where FineToothComb comes in.

FineToothComb, or FTC as we usually call it, is a Nokia tool which takes all that ETM data plus some extra information taken from the device at the same time using JTAG, and all the binary code and symbols installed on the device, and then spends some minutes correlating all that together to create a database a few Gigs in size for a each trace.

To see what happened I then use FTC’s “Trace Explorer”, which starts off showing me something like this:

OpenStreetMap example on Symbian

What you can see here is a “MIPS graph”. Time increases to the right, and the number of millions of instructions executed per second goes upwards. The colours represent different threads and processes that ran, with the names and instruction counts for those shown below the graph.

Because of memory latency and caches, you almost never see a CPU running one instruction for every clock cycle. Memory copies especially cause the CPU to spend most of the time waiting, which show up as “low” MIPS values on these graphs.

This first graph gives you the big picture of what happened during your use case. To see more detail you can zoom in on a region of interest. Here’s 165ms:

165ms from OpenStreetMap example on Symbian

And again down to just 1.3ms:

1.3ms from OpenStreetMap on Symbian

Eventually you get down to the level of seeing individual context switches between threads – the operating system in action.

To see what a thread was doing, you simply choose it from the graph and the tool shows you a call stack for that time, along with the time taken (in nanoseconds) and number of instructions run for each call. From that last graph I opened the “lightmaps” stack:

Call stack from OpenStreetMap on Symbian

The white lines are blocks of instructions being run from within one function. Red lines are calls from there to other functions, with the total time for that call in nanoseconds show in the second column.
Any call can be opened up to see what it called, in this case I opened the operator>>> call to see that it ended up in a file read which went to the Symbian file server. The tool can even cross over from user space into kernel calls to see what happened there as a result of a user call. Green lines show calls that have been opened up. As you move the mouse over calls, the graph at the bottom highlights the time range for that call so you can see where you are in the trace.

You can also see into any system servers or kernel threads that ran, as well as interrupts. Another feature is statistics of which functions used time and instructions for any block of time. Here are the top 10 functions from the big blue section in the 2nd graph – obviously a PNG decode:

Statistics from OpenStreetMap on Symbian

And it can even capture and show what was on the display of the device to help understand the trace later:

Screenshot from OpenStreetMap on Symbian, captured with ETM

Overall it’s really useful for quickly homing in on any code that needs performance optimisation, and because it’s not just a statistical sampling of what happened, it can be used for studying many kinds of use cases, for instance answering a question of why a system is waiting when it should be busy. Most importantly it does all this with the device running at full speed without requiring any special “debug” software build, so you don’t need to guess about how anything is in the “real” case, because this is it.

Using FineToothComb on Qt has already helped us quite a bit with performance of the Qt port to Symbian. Early on in the port, it highlighted some bottleneck functions which were converted from smaller but slower THUMB instructions to faster ARM instructions. It caught when we were not compiling using the ARM’s vector floating point instructions. It also helped with the optimisation of raster rendering functions using ARMv6 and data preloading. In another case it caught the fact that we were using a slow blit operation for the final screen update, when a different parameter would cause a much faster blit to be used.

Even though FTC isn’t a tool that is available outside Nokia, the improvements it can and has found already are, and more of them should be coming your way soon.

I’m going to be at the Qt Developer Days 2009 in Munich, so if you are there too and would like a quick demo of FineToothComb, just track me down and ask!

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Performance, Symbian


Damn, you’re teasing us. That tool looks sexy! πŸ˜‰ Great post.

hamishwillee says:

G’day Andrew, planning at being at the San Francisco developer day, or SEE as well? Hamish

Robert Gerus says:

Nice. Now I wonder if my OpenRD has ETM πŸ™‚
Too bad the Lauterbach PowerTrace II probably costs too much for me. And even if it didn’t, I’d probably need a faster device (as the openrd has 1.2GHz cpu).
Still, very neat thing to see.

Andrew Baldwin says:

@elvis, thanks! and sorry again you can’t get your hands on all this.

@hamish, hi! Just Munich this year.

@robert, OpenRD looks like a nice board, but it only seems to have JTAG and no ETM. There’s a similar situation also with the OMAP3 Beagleboard. It’s a pity there doesn’t seem to be a cheap ARM board+ETM capture box combination out there (at least that I know of) that could bring this kind of feature to more developers. Although simulators like QEMU might be another way to get some of the benefits without the cost.

holger says:

The closest thing I have seen in the wild is the XEEMU emulator of the university of szeged (http://www.inf.u-szeged.hu/xeemu/index.html).

P says:

We’ve found the Lauterbach tool is limited in Linux Virtual memory environments on MIPS platforms that don’t provide (and save) appropriate VM physical address mappings. Doesn’t play nice with Linux page swapping. Only physical addresses are saved in our case.

Did you have any such issues on ARM – assume you are running Linux under the hood??

Looks a great software tool if it can get the right trace data.

PS the security image is ridiculously tough. Any chance you could make it easier for humans…

Commenting closed.

Get started today with Qt Download now