In this tutorial, we will use the flame graph. There are several views available for the collected data. Use the menu in the top-right corner of the tool window. To analyze memory allocations we need, to switch to that mode Switch between CPU and allocation data Open the profiler reportĬlick the balloon that appears near the Profiler tool window button.īy default, IntelliJ Profiler shows CPU samples data. This data is then aggregated in a human-readable form to give us an idea of what the application was doing when allocating these objects.Īfter running the profiler for some time, let’s open the report and see what’s there. While running, the profiler records the application state when objects are placed on the heap. Select Parrot | Profile with 'IntelliJ Profiler'. Since we know our application never gets enough memory, we might want to analyze its memory usage. The only visible effect of extra memory was that we delayed the end of the “party”. Alas, regardless of the available memory, the parrot runs out of memory anyway. This will increase the memory heap to 1024 megabytes. In the VM options field, enter -Xmx1024M. Hold Shift and click the run configuration on the main toolbar. Since there is not enough memory, a naïve solution would be to just add more memory. This supports our hypothesis that there are no objects eligible for garbage collection. Memory usage does not go down after it reaches the plateau. If you need to test how garbage collection works under specific conditions, you can request it from CPU and Memory Live Charts. We can test whether garbage collection yields any results right in CPU and memory live charts. If we see a plateau, it means the garbage collector can’t free up any. If the saw teeth become too frequent, it means that a lot of objects are being created and the garbage collector is called often to reclaim the memory. You can see an example of this in the picture below: Usually, the memory usage curve is saw-shaped: the chart goes up when new objects are allocated and periodically goes down when the memory is reclaimed by the garbage collector. This is precisely the moment when the animation hangs, and there seems to be no way out of this. Indeed, we see that the memory usage is going up continually before reaching a plateau. Right-click the necessary process in the Profiler tool window and select CPU and Memory Live Charts.Ī new tab opens in which you can see the amount of resources the selected process consumes. Open CPU and memory live chartsįrom the main menu, select View | Tool Windows | Profiler. Let’s open the charts for our parrot app and see if we can spot anything when the animation freezes. They allow us to visualize real-time resources usage for the processes that are running. Since we are getting an OutOfMemoryError, a good starting point for analysis is CPU and Memory Live Charts. Clearly, we need to try another approach. We don’t even know if the threads are waiting for a lock or have just finished their current work. Unfortunately, this did not tell us much because all the threads involved in the parrot party are in the waiting state. We get the list of threads with their current stack traces. From the main menu, select Run | Debugging Actions | Pause Program. Let’s try using the debugger! Pause an appįirst we need to run the app in debug mode. The result may differ on other JVMs or even on Corretto 11 if it uses a custom configuration. The interesting thing about the animation freeze is that we can still use the rest of the UI. There is no reliable way of telling how exactly the problem will manifest itself. There can also be a OutOfMemoryError, whose stack trace doesn’t tell us anything about the origin of the problem. However, it’s not long before things start going wrong.Īfter working for some time, the animation freezes with no indication of what the cause is. The app seems to work well: you can tweak the animation color and speed. Īfter that, launch the application using the Parrot run configuration included with the project. Let’s start with cloning the following repository. Most of the tools in this tutorial are available in Community Edition, but for profiling tools you need Ultimate. In this tutorial, we’ll look at how we can use some of IntelliJ IDEA's built-in tools to investigate a runtime problem. They can point you in the right direction. A smarter approach would be to use the tools you have at hand. We often find ourselves in situations where code is not working properly, and we have no idea where to even begin investigating.Ĭan’t we just stare at the code until the solution eventually comes to us? Sure, but this method probably won’t work without deep knowledge of the project and a lot of mental effort.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |