Profiling CPU in Flash and Flex Applications in IntelliJ IDEA

Hello guys! Just recently we’ve published an update to our Flash/Flex Profiler plugin that gives you a powerful and easy to use toolset for profiling of Flash-based applications in IntelliJ IDEA.

Let us give you a brief overview of what you can do with it.

Sure, the first thing to start with is installation. Nothing complex here—go to File menu, open Settings, then click Plugins and Browse repositories (if you’re on Mac OS, the path is slightly different—you should look in IntelliJ IDEA, then Preferences, Plugins, and then Browse repositories). After you’re there, find ActionScript Profiler and install it.

Let’s play with this extremely simple Flex component to set an example.

As you can see, it’s a rather heavy computation implemented in Task.calculateResult() method that is invoked 1000 times in a cycle from clickHandler() function that handles the mouse click.

To start the profiling we open context menu for the main class and click Profile:

Once the application is built and started, an empty Profiling window opens. Let’s tell profiler to start collecting CPU usage data by clicking Start CPU Profiling.

Now switch to our application, click Calculate and wait for resulting popup to appear. Then, we need to go back to IDE and click Stop CPU Profiling to compute the results—and here they are!

Invoked functions table shows the list of called functions, with child nodes representing points from which parent node was called:

We can easily compare timings by sorting the table by self time or cumulative time (just click column header for that).

Note: Edit source action is available for every item either via context menu or with F4 keyboard shortcut, so you can go to source code directly from profiling results.

Merged callees table at the bottom shows all the functions that were called (directly or indirectly) from the function selected in the upper table. You can sort this table as well to compare every detail and expand items to drill down through the call chains.

This concludes today’s post about CPU profiling. We hope you enjoyed it. In the next posts we are going to take a look at memory profiling capabilities and memory leaks hunting techniques. Please report any problems to the bug tracker. Stay tuned!

Plugin is compatible with IntelliJ IDEA 11.0 and 10.5. It was tested with 32-bit Flash Player 9, 10 and 11 on Windows (32- and 64-bit), Mac OS (32-bit and 64-bit) and Linux (32-bit).

Profile with pleasure!

This entry was posted in New Features and tagged , , , , , . Bookmark the permalink.

40 Responses to Profiling CPU in Flash and Flex Applications in IntelliJ IDEA

  1. Simon Bailey says:

    This is a much welcomed and awesome addition to IDEA, thanks @jetbrains!

  2. steven says:

    I only see “Waiting for profiling agent to connect…” — what am I doing wrong?

  3. fedor.korotkov says:

    It seems the problem is in mm.cfg file. Did you override home directory? Do you use debug player?

  4. basti says:

    looks very nice, but i got the same problem as already mentioned: “Waiting for profiling agent to connect …”

    I use DebugPlayer!
    Is there a special configuration in mm.cfg necessary?
    I just use the following three props.
    ErrorReportingEnable=1
    TraceOutputFileEnable=1
    TraceOutputFileName=C:Userss …

  5. Danil says:

    Hey guys!
    I see Sampling started in profile window, yet I don’t see any Calculate button. Where should it be?
    Also I don’t have admin rights on PC.
    What should I do to make it works properly?
    Thanks.

  6. fedor.korotkov says:

    Hi Danil!

    Calculate button is part of example code(look at second screenshot).

  7. fedor.korotkov says:

    basti, it’s very strange. There must be at least one more property:
    PreloadSwf=C:…

    When you start profiling application this property appears in mm.cfg. It disappears when you close the window.

  8. li says:

    I am still being unable to connect to the profiler with message “Waiting for profiling agent to connect…”
    Please, how to resolve this on a mac? What is mm.cfg?

  9. Antoine L says:

    I’m getting an HTTP Error 500 when trying to browse the plugins or download ActionScript Profiler. I’m on a Mac OS 10.6.4.

    Too bad, can’t wait to test it !

  10. Davem says:

    Profiler seems to be showing cumulative live objects, ie over several profile sessions. Is there any way to force the profiler to start without results from previous sessions?

  11. Christian says:

    I can capture CPU, run garbage collection, but no memory snapshots button available!?

    IDEA 11.1
    actionscript profiler
    Windows 7
    IE 9

  12. fedor.korotkov says:

    Hi, Christian!

    In version 0.2.6 we changed layout. In 0.2.5 there was only one memory snapshot with no information about object’s members. We renamed it to Live Object and made it real-time.

    You can vote here: http://youtrack.jetbrains.com/issue/IDEA-85348

  13. Thomas says:

    @steven, basti, fedor.korotkov

    the connection problem might result from the profile modifying %USERPROFILE%mm.cfg, but the FlashPlayer reading %HOMEDRIVE%%HOMEPATH%mm.cfg.

    In most cases, %USERPROFILE% and %HOMEDRIVE%%HOMEPATH% will be the same, but in my environment they are not: %USERPROFILE% is local and %HOMEDRIVE%%HOMEPATH% is a network mount.

  14. Jobe says:

    Hi,

    The CPU Profiling appears to be working, but when I click on the “Live Objects” in the Profile screen to get details I get a screen that shows “Loading…” which never returns.

    Any ideas how to get the Live Objects to work as well?

    Thanks,

    -jobe

  15. AleVys says:

    Hi, profiler is launched through time …. it works, then the message “Loading ….” In what could be the reason?

    I use FlashPlayer Debugger 11.4…. Thanks!

  16. Andreas says:

    Hi,

    to solve the problem with loading … i simply copy the mm.cfg from %USERPROFILE% to %HOMEDRIVE%%HOMEPATH% after the first failed start.
    Important:
    After the first start with profiling the mm.cfg contains on entry for PreloadSwf with your username (here xxxx):
    PreloadSwf=C:Usersxxxx.IntelliJIdea11configpluginsASProfilerlibprofiler_agent_10.swf?port=1310&host=127.0.0.1

  17. Henadzi Shutko says:

    After profiling has started, error appears:
    “Failed to connect to profiler agent. Please ensure that you have a debug version of Flash Player.” My mm.cfg file contains entry “PreloadSwf=C:UsersSony.IntelliJIdea11configpluginsASProfilerlibprofiler_agent_10.swf?port=1310&host=127.0.0.1″. What is the reason, if I test locally.

    Andreas,
    Could you be more specific about %HOMEDRIVE%%HOMEPATH% ? Thans in advance!

  18. Murray says:

    I copy my mm.cfg file to network mount %HOMEDRIVE%%HOMEPATH%, then in my Settings I change the location of the ActionScript Profiler to a Custom file location of H:mm.cfg as that is the location of %HOMEDRIVE%%HOMEPATH%. I then start the profiler and see a tab with a list of Live Instances in a grid which looks good, but the actual AIR application doesn’t appear. This is an AIR 3 app running on the flashplayer 10.3 projector. Anyone any ideas as to what’s going wrong?

  19. Murray says:

    After doing the above I will then see the message ‘ Failed to connect to profiler agent. Please ensure that you have a debug version of Flash Player.’ after a couple of minutes. I can confirm I have the debug player installed, and I can run the FlashBuilder profiler without problem.

  20. Alexey says:

    Sorry, I can’t find an info – is it compatible with Idea 12?

  21. fedor.korotkov says:

    @Alexey, yes, it is. Just follow the steps from this post to install the plugin.

  22. Alexey says:

    @fedor.korotkov. Thanks a lot – the plugin really works. The problem was with the port number – it should be unassigned before profiling start. And as I noticed – only one instance of an application can be started in the browser. Otherwise plugin will not be able to connect to flex app.

  23. Steven says:

    Sorry, I don’t seem to get it.

    “It seems the problem is in mm.cfg file. Did you override home directory? Do you use debug player?”

    The post above does not mention mm.cfg or overriding home or debug player. It would be great if the post, which says “it is really easy to do and these are all the steps”, in fact does give all the steps instead of omitting the tricky bits.

  24. Alexander Doroshko says:

    @Steven In most cases profiling works with a single click on ‘Profile’ button, so the blog post doesn’t concentrate on possible problems. Feedback is always welcome in the issue tracker [1], forum [2] and support service [3]. I have noticed your message to support team, so let’s continue discussion there.

    [1] http://youtrack.jetbrains.net
    [2] http://devnet.jetbrains.net/community/idea/ideacommunity
    [3] support@jetbrains.com

  25. steve3719 says:

    The plug-in works for me.
    But I need to find references that are causing an object to be kept in memory.
    Is this feature provided?
    Thanks,
    Steve

  26. Philip says:

    >> “In the next posts we are going to take a look at memory profiling capabilities and memory leaks hunting techniques.”

    Does anyone know where I can find this post? Was it ever written?

  27. fedor.korotkov says:

    @Philip, unfortunately it doesn’t exist. If you have any problems/questions feel free to mail me at fedor.korotkov at jetbrains.com

  28. Vladimir says:

    Does the profiler work with AIR Mobile?
    I’m getting “Failed to connect to profiler agent. Please ensure that you have a debug version of Flash Player.” error. Undortunately I didn’t find any tutorials about how to make it work.

  29. Maurice Amsellem says:

    Hi, I have tried CPU Profiling but the methods list keeps empty. This is what I did:
    - run an application in Profile mode
    - clicked on “Start CPU Profiling”
    - played with the app
    - clicked on “Stop CPU Profiling”
    - opened the itemp CPU HH:MM (the one with glasses and clock).
    - the methods list stays empty
    - I also tried with the various options (Filter flash, Scope) at no avail.

    What’s wrong ?

  30. Maurice Amsellem says:

    Config: IDEA 12 and Apache SDK 4.9.1

  31. fedor.korotkov says:

    @Vladimir, I tried it with a regular AIR. I think it should work. Could you please create an isuue? http://youtrack.jetbrains.com/

    @Maurice Could you please create an isuue? http://youtrack.jetbrains.com/ I’ll ask you about your configuration there.

  32. Gabrielius says:

    Thanks @Thomas! Wouldn’t have figured that out in ages myself.

    However, my %USERPROFILE% and %HOMEDRIVE%%HOMEPATH% are the same (C:Usersxxx), the profiler must have written the mm.cfg to %APPDATA%…. , because my %APPDATA% is D:UsersxxxAppdataRoaming and I found the mm.cfg with the “PreloadSwf=” parameter in D:Usersxxx

    It works though!

  33. Jack says:

    I’m getting the same “failed to connect… debugger?” error message. Mac, Apache Flex 4.10, IDEA 12. Anyone have any updated thoughts?

  34. Amma says:

    Great plugin. Thanks!

  35. Valek says:

    Hi there
    Thanks for the long-awaited profiler in IDEA!
    I have some problem…

    I use IDEA 12 and Debug Flash Player 11.1.102… local and in all browsers…
    I comile debug .swf file on sdk 4.6(11.1 player) or sdk 4(10 player) and I launch profiler as described above. Profiler writes Connected. But in window (after press F4) I have Loading… and no more! May need something else? Or what am I doing wrong?
    In mm.cfg your PreloadSwf=С:/…/profiler_agent_10.swf?host=localhost&port=8813

    Thanks!

  36. I can’t see any references to flex modules that are loaded at runtime although I can see classes within the modules in the Live Objects. Is there any way to see these?

    To clarify I’ve an air application that loads in modules at runtime, eg. module.swf, The class that represents this module is not listed in the live instances although classes within this module are. Is there a way I can see these module classes such as declaring the class’s type in the main air application?

  37. hayesmaker says:

    so where exactly is the memory profiling article promised 2 years ago?

  38. I can’t see any options to take memory snapshots so I can compare 2 memory snapshots. This would be a great feature because that could tell what new objects were created and how many of them.
    Maybe if you could give us info on the location and structure of the live memory file (assuming there is one), or just an option to save the current live profile, that would already be a big step.

  39. I can only see the total count of objects created, that number doesn’t update after the garbage collector.

    How do I see the current count of an object? instead of the max count.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">