Stop Coding!

The Unofficial Flex Compiler Blog

Posts Tagged ‘Flex Profiler

The Future of The Flex Profiler

with 6 comments

If you haven’t read my previous blog about the Flex Profiler, I recommend you go take a look…

Ever since the Flex Profiler was made available in early FB3 beta, I’ve been hearing some legitimate concerns. One example and I paraphrase:

It’s great that Flex has implemented a large number of Eclipse views for the main use cases. But they are not showing me what I want…

Another example:

The steps of showing profiling data are quite simple and easy to remember. But once the data is shown, it seems to me that it usually takes too many steps to navigate to the root cause of the performance/memory problems. Why can’t the tool be smarter?

Like I said, these are legitimate concerns and I’m sure the Flex engineering team is going to improve the profiler going forward. How? I’m going to give my $0.02 here..

Just to recap, there are 4 pieces in the profiler architecture:

  1. The flash.sampler.* API support and the PreloadSwf support in the Player
  2. ProfilerAgent.swf as the PreloadSwf
  3. Java-based profiler client library
  4. Eclipse plugin + the graphical user interface

As you can see, if the current Flex profiler doesn’t work for you and you can’t wait for any improvements in the next release, your most logical option will be the flash.sampler API, i.e. write your own profiler agent or simply use the flash.sampler classes in your application. There are many advantages and disadvantages.

Advantages:

  • Free. You don’t have to pay several hundred dollars more for FB Pro. Well, your time is money too. so, this point doesn’t make sense. 🙂
  • Your profiler agent could be very lightweight if you know exactly what you’re looking for.

Disadvantages:

  • You want a profiler agent that is lightweight, i.e. not using up too much of CPU cycles and Player memory. However, it could take you a long time to write a good one.
  • You have to use another timing approach to verify the correctness of your implementation.
  • You may waste your valuable time if you have to move your sampling code from one wrong spot to another in your application.

I think most developers would avoid writing their own. At some point, some developers/software vendors may make theirs available (free of charge? who knows?). I don’t see that in my crystal ball yet.

If the current Flex profiler works for you but you want some enhancements, feel free to submit your enhancement requests. However, they may not work on every enhancement (e.g. they may not build 15 more new profiler views). Instead, you should tell Adobe the following:

  • Expose the API of the Java-based profiler client library. The API returns pre-calculated data that’s ready for tabulation. It can also return raw data from ProfilerAgent.swf if you want to do your own calculations.
  • Expose the API of the foundation classes (e.g. the base class of the performance/memory views) and the utility classes.
  • Define extension points in the Eclipse-based profiler plugin.

If Adobe listens to you and do the above, it will be very easy for you to extend the Flex profiler. I think it’s in their best interest to provide the flexibility you need because the Player doesn’t provide profiling support in a closed environment – the flash.sampler API is available to everyone. Sooner or later, the Flex Profiler will not be the only game in town.

Another great thing that developers can do if the API of the profiler client library is exposed is static code analysis. Did you notice that in the inclusion/exclusion filter dialog, it automatically shows a list of packages as you type?

The package list is built dynamically by the Flex Profiler by decoding the bytecodes in your application. Yep, the application SWF is available via the profiler client library API. That’s why I think someone could write a profiler extension plugin that uses SWFKit (the open source SWF encoding/decoding library) to decode and run static code analysis. It sure would be very nice to be able to do both static/dynamic code analysis with the Flex Profiler.

Written by Clement Wong

April 28, 2008 at 6:10 pm

Posted in profiler, Technology

Tagged with ,

Let’s Talk About The Flex Profiler

with 10 comments

Yeah, I know. This is a compiler blog, not a profiler blog. But I can explain…

The performance and memory profiling feature in Flex Builder Professional Edition wasn’t done by the FB development team. It was done by the Flex compiler team. Yes. I mean everything: the Eclipse plugin, user interface, profiler agent, data collection and processing!

So now you know that the compiler team was not only busy with the compiler, but also the profiler, during the Flex 3 development cycle. And that explains why I’m “eligible” to talk about the profiler here…

Those who have been closely following Flex since version 1 should notice that profiling was present in version 1 and 1.5 but absent in version 2 and 2.0.1. Why no profiler in version 2? It’s a long story. But it was a combination of poor scheduling, coordination and… well… lack of technological advances.

You may ask, what technological advances? Well, if you had used Flex 1.0 and 1.5 in the past, you should know that there was a performance profiler (http://www.adobe.com/devnet/flex/articles/profiler.html). The performance profiler in Flex 1.x was trace-based, i.e. the Player records timing data for everything that happens in the old AVM. The upside is that it captures everything. The downside is that it makes the Player run slowly and the amount of data for a short period of time (say 10 seconds) could be huge and take time to process. I’m not suggesting that the Flex 1.x performance profiler is not useful. It needs you to know roughly where to optimize. In fact, thanks to the profiler, we were able to improve Flex 1.5 framework startup performance by over 30%. Yahoo! was able to speed up their Flash/Flex-based Yahoo! Maps before the debut. But the breakthrough came when Tom Reilly added support for sample-based profiling to the latest Player…

I’m making an assumption here that you all studied statistics when you were in college and know what sampling is. If not, ask the people around you about the purpose of national presidential polls you hear these days. Same idea. Of course, I’m very sure that Tom’s stuff for identifying performance bottlenecks in your code is a lot more accurate than those national polls for predicting the next president of the United States! 🙂

Unlike traced-based, with sample-based profiling, you don’t get everything. But your application runs just as fast (or as slow) when sampling is enabled. Because it’s sampling, you don’t get a notification every time your application enters or exits a function. But you still get a pretty accurate performance profile.

So far so good, but there are some negatives. For instance, it is pretty tricky to find, given a function that is getting called excessively, the time distribution from the list of callers of that function.

Other than performance profiling, the Player now also supports memory profiling. It reports object instantiations, object deletions and where objects were instantiated.

So far, I’ve talked quite a bit about the Player side of the Flex profiler story. Let’s turn to the profiler architecture. It is actually pretty simple. There are 4 pieces:

  1. The flash.sampler.* API support and the PreloadSwf support in the Player
  2. ProfilerAgent.swf as the PreloadSwf
  3. Java-based profiler client library
  4. Eclipse plugin + the graphical user interface

For performance profiling, the flash.sampler API returns sampling data as a stream of stack traces. So, it’s pretty easy to process. For memory profiling, the API returns object instantiation and deletion events and also stack traces indicating where objects were instantiated.

The PreloadSwf support is new in the latest Player. The idea is that, if you specify a local SWF in your mm.cfg, the Player will load/run the specified SWF in parallel to the target SWF. These two crucial Player features together provide the one-two punch we desperately needed against slow-running Flash movies.

Now anyone could write some AS3 codes to collect performance and memory data. For the Flex Builder profiling feature, we implemented a non-GUI-based AS3 program (ProfilerAgent.swf) that collects and sends performance/memory data to Flex Builder via socket connections.

On the client side, there are two pieces. The first piece is the Eclipse plugin and the graphical user interface. The “Flex Profiling” perspective and the associated views (a total of 11) are a major addition to Flex Builder 3. The user interface is aimed at:

  1. identifying performance bottlenecks
  2. exposing excessive object allocations
  3. finding loitering objects

The second piece is the profiler client library. Obviously, it’s for maintaining server socket connections; taking performance/memory data; processing them and archiving them. We need this library because we need a demarcation between the Eclipse code and the non-Eclipse code so that QA can use the Eclipse-free client library to write automated test cases for ProfilerAgent.swf.

If you want to know how to use the Flex Profiler, please check out the livedocs (http://livedocs.adobe.com/flex/3/html/help.html?content=profiler_3.html).

To Be Continued…

Written by Clement Wong

April 26, 2008 at 9:37 pm

Posted in profiler, Technology

Tagged with ,