Profiling CPU in Flash and Flex Applications in IntelliJ IDEA

Fedor Korotkov

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!

Comments below can no longer be edited.

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

  1. Simon Bailey says:

    January 11, 2012

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

  2. steven says:

    January 17, 2012

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

  3. fedor.korotkov says:

    January 18, 2012

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

  4. basti says:

    January 26, 2012

    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:

    February 1, 2012

    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:

    February 1, 2012

    Hi Danil!

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

  7. fedor.korotkov says:

    February 1, 2012

    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:

    February 1, 2012

    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:

    February 20, 2012

    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:

    April 24, 2012

    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:

    April 26, 2012

    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:

    April 27, 2012

    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:

    June 12, 2012

    @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:

    June 26, 2012

    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:

    September 5, 2012

    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:

    September 18, 2012

    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:

    October 27, 2012

    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:

    November 5, 2012

    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:

    November 5, 2012

    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:

    December 21, 2012

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

  21. fedor.korotkov says:

    December 24, 2012

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

  22. Alexey says:

    January 23, 2013

    @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:

    January 31, 2013

    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:

    February 1, 2013

    @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:

    February 13, 2013

    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:

    February 26, 2013

    >> “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:

    February 26, 2013

    @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:

    July 3, 2013

    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:

    July 12, 2013

    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:

    July 12, 2013

    Config: IDEA 12 and Apache SDK 4.9.1

  31. fedor.korotkov says:

    July 15, 2013

    @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:

    August 6, 2013

    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:

    August 21, 2013

    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:

    October 8, 2013

    Great plugin. Thanks!

  35. Valek says:

    December 5, 2013

    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!

    • Alexander Doroshko says:

      December 5, 2013

      Should work. Is it possible to attach a sample project? Use forum or issue tracker.

  36. Lyndon Fasanya says:

    January 27, 2014

    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:

    May 7, 2014

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

  38. Michel Comeau says:

    July 9, 2014

    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. Lorenzo Nuvoletta says:

    September 6, 2014

    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.

  40. Sebastian says:

    December 11, 2014

    When trying to use the profiler, an error appears:
    “SWF file was not added to local-trusted sandbox
    Couldn’t create intellij_idea.cfg file in FlashPlayerTrust folder: Permission denied”
    (IntelliJ IDEA 14, Flash Debug Player 15)

    How can I solve this problem?

  41. Artemix says:

    February 26, 2015

    They don’t seem to care about this profiler, it’s bugged in the current version at least. (14).

  42. unnamed says:

    May 27, 2015

    So if it won’t connect, first thing to try in the latest Intellij versions is to change the port in actionscript profiler settings. Seems that the default port may conflict with something, maybe with Chrome debug plugin because i experienced the similar connectivity problems. Be also aware that some ports can be changed automatically or ‘already in use’ if you have several instances of Intellij launched. I guess you can diagnose if you have the port problem by executing
    netstat -a | find “insert expected port number here”
    (for windows) and checking if the profiler port is used.

  43. Greg says:

    August 21, 2015

    Is this plugin compatibile with IntelliJ Idea 14 ?
    When I start profiling, on Profile Tab is displays “Waiting for profilling agent to connect …”.
    The mm.cfg file is exists in C:\Users\ folder and it contains

    PreloadSwf=C:\Users\Grzegorz\.IntelliJIdea14\config\plugins\ASProfiler\lib\profiler_agent_10.swf?port=1310&host=127.0.0.1

Subscribe

Subscribe for updates