5 Identifying resource consumption problems using profiling techniques

 

This chapter covers

  • Evaluating resource consumption
  • Identifying issues with resource consumption
  • Installing and configuring a profiling tool
  • Simplifying profiling techniques with AI assistance
“And for you, Frodo Baggins, I give you the light of Eärendil, our most beloved star. May it be a light to you in dark places when all other lights go out.”

—Galadriel (Lord of the Rings, by J.R.R. Tolkien)

In this chapter, we start with using a profiling tool. We’ll continue the discussion in chapter 6. A profiling tool (or profiler) may not be as powerful as the light of Eärendil, but this tool is definitely a light in dark cases when all the other lights go out. A profiler is a powerful tool that has helped me to understand the root cause of an app’s strange behavior in many difficult situations. I consider learning to use a profiler a must for all developers, as it can be a compass to guide you to the cause of a seemingly hopeless problem. As you’ll learn in this chapter, the profiler intercepts the executing JVM processes and offers extremely useful details:

  • How the app consumes resources such as the CPU and memory
  • The threads in execution and their current status
  • The code in execution and the resources spent by a given piece of code (e.g., the duration of each method’s execution)

5.1 Where would a profiler be useful?

5.1.1 Identifying abnormal usage of resources

5.1.2 Finding out what code executes

5.1.3 Identifying slowness in an app’s execution

5.2 Using a profiler

5.2.1 Installing and configuring VisualVM

5.2.2 Observing the CPU and memory usage

5.2.3 Identifying memory leaks

5.3 Using AI assistance

5.4 Summary