chapter five

5 Identifying resource consumption problems using profiling techniques

 

This chapter covers

  • Evaluating resource consumption
  • Identifying problems 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 (The Fellowship of the Ring, by J.R.R. Tolkien)

This chapter introduces a profiling tool, and 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 it is definitely a source of light in dark cases when all the other lights go out. A profiler is a powerful tool that has helped me 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 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, such as:

  • 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

Summary