83

I know that Netbeans has something of an "integrated" profiler, for instance you can run unit tests and use it to analyze and find what is slowing them down, where bottlenecks are. Is it possible to profile code within IntelliJ IDEA editor?

rogerdpack
  • 50,731
  • 31
  • 212
  • 332
  • 1
    As far as I know there is only one free profiler integration: [VisualVM](http://plugins.jetbrains.com/plugin/?idea&pluginId=7115). – CrazyCoder Apr 12 '13 at 17:01
  • Apparently there's a non-free JProfiler plugin, FWIW http://stackoverflow.com/a/21156875/32453 – rogerdpack Apr 28 '14 at 15:25
  • Today I have installed the plugin VisualVM in INtellij IDEA ... initially I faced some issue but when I followed instructions provided in http://blog.idrsolutions.com/2013/05/setting-up-visualvm-in-under-5-minutes/ I could easily configure visualVM – Shirishkumar Bari Jul 30 '14 at 05:11
  • 2
    Another question that's far too practical and useful to remain open. SO should support questions with answer sets {N} where good enough result(s) from set: [`X`, `Y`, `Z`] rise to the top via the community and the rest disappear/require extra action due to a natural falloff. Again via the community. "Do you really want to answer this? Cause there's already an answer voted pretty dang good?" "Yea, cause now there's a better best answer." I mean that never happens in software right? – P.Brian.Mackey May 11 '17 at 21:16
  • 1
    FYI: In IntelliJ IDEA v2018.3 Ultimate edition, the JVM Profiler is available as an experimental feature. See https://blog.jetbrains.com/idea/2018/09/intellij-idea-2018-3-eap-git-submodules-jvm-profiler-macos-and-linux-and-more/ – chipiik Feb 12 '19 at 16:03
  • For Windows profiler, use 2019.2 RC: https://blog.jetbrains.com/idea/2019/06/intellij-idea-2019-2-eap-4-profiling-tools-structural-search-preview-and-more/ – Det Jul 20 '19 at 16:24

2 Answers2

55

You can try the free VisualVM profiler integration via a plug-in.

CrazyCoder
  • 350,772
  • 137
  • 894
  • 800
  • Looks like if you buy IntelliJ "ultimate" it's said to include a built-in YourKit profiling agent, as well. Not free, but included, so I guess related to my original question :) – rogerdpack Apr 20 '13 at 17:55
  • 4
    No, YourKit agent will allow you to take CPU/Memory snapshot when contacting support with performance problems, it's not the profiler itself which will cost you additional $500+. – CrazyCoder Apr 20 '13 at 20:44
  • appears you're right thanks for the clarification. YourKit is apparently only for profiling the IDE itself, not your own apps. Guess I'll just turn to Netbeans for now when I need to profile, and do the rest of my programming in IntelliJ :) – rogerdpack Apr 22 '13 at 13:17
  • 1
    @rogerdpack why not just open VisualVM (you already have it installed through the jdk), select your app and press profile? – Matsemann Jul 14 '13 at 15:34
  • 3
    The problem with VisualVM launced by Krasa's VisualVM Launcher plugin: 1) at the time it starts your test has finished. 2) on-fly profiling creates hot spots and hard to read CPU time stats. There is a checkbox "edit configuration" in VisualVM but I don't see how to ask plugin to start test in right way - wait until VisualVM starts and ready - load test specific profiling config into VisualVM - run test code – smile-on Jan 15 '14 at 16:54
  • YourKit version 2013 is not free but definetly claims functionality of stand alone java profiler with IDE Integration, IntelliJ IDEA 13 supported. Look at [**YourKit version 2013 release note.**](http://www.yourkit.com/changes/#cpu) – smile-on Jan 15 '14 at 17:18
  • 1
    @smile-on Did you find a solution to the problem where your tests finish before VisualVM has launched? I am having the same problem myself. – Stephen Murby Jan 28 '14 at 18:19
27

As pointed by Stephen Murby "the problem where your tests finish before VisualVM has launched".

Yes, this VisualVMLauncher plug-in does not put your test case on hold until VisualVM has started. You may also need time to manually change profiling settings specific for the test. Solution is simple, your test case has to stop and wait until you manually tells it to continue. There are few ways of doing it:

1) put System.in.read(); as first line of test case and as VisualVM is ready press enter at console.

System.in.read();

2) If test case runner does not provide you with console, put wait until some magic file is created.

3) you can always play easy with sleep()

sleep(5 seconds);

This work around is not much of convenience but works for me as need to profile occasionally. The root cause of issue is in plug-in architecture of both IDEA and VisualVM are not thought to be collaborative. See discussion with plug-in author Hope that helps.

smile-on
  • 1,503
  • 17
  • 18