liveBook · Manning

Profiler

As explained in Troubleshooting Java, Second Edition

A profiler is a software tool that measures and records runtime behavior such as execution time, resource usage, and call activity.

A profiler observes a running application to reveal which code executes, how long methods run, and how the application uses CPU, memory, threads, and database connections. It narrows an investigation before you open a debugger, especially when the codebase is unfamiliar or debugging would disturb multithreaded behavior. section 1.2.1 section 5.4

Use profiling to ask focused investigative questions:

  • Which methods and threads are actually running when a capability is triggered? section 5.1.2
  • Which code consumes excessive CPU or memory, and could zombie threads or memory leaks explain the symptom? section 5.1.1
  • Where does execution spend time, and which methods are invoked unusually often? section 6.4
  • Which SQL queries reach the database, how often do they run, and which application code issued them? section 6.3

From abnormal CPU use to a concurrency defect

A producer-consumer application starts two producer and two consumer threads that concurrently modify an ArrayList without synchronization. VisualVM shows substantial CPU use, active threads, and exceptions; the evidence points toward a race condition and zombie-thread behavior. Synchronizing access to the shared list changes the resource profile: CPU use falls and the threads’ execution becomes visibly coordinated. The profiler identifies the symptom and narrows the code requiring correction; source inspection or a thread dump can continue the diagnosis. section 5.2.2

Start with sampling because it consumes fewer resources and provides the execution big picture. If necessary, focus detailed profiling on selected packages or classes to measure method duration, CPU time, invocation counts, locks, or JDBC queries. Profiling is investigative evidence, not a single-cause answer: follow the results with code reading, debugging, SQL analysis, lock profiling, or a thread dump. section 6.4 section 7.4 section 8.1.1

Figure 1.5 Identifying code in execution with a profiler. If you don’t know where to start debugging, the profiler can help you to identify the code that is running and give you an idea of where you can use the debugger.

Shows how a profiler identifies executing code and guides the placement of debugger breakpoints. section 1.2.1

How Troubleshooting Java, Second Edition covers it

How deep it goes
Explains sampling, detailed profiling, resource monitoring, SQL interception, lock profiling, and thread dumps, while requiring follow-up diagnosis.
Examples
Uses VisualVM, producer-consumer threads, memory leaks, generated SQL, cross joins, locks, deadlocks, and thread dumps.
What it assumes
Assumes a running Java application and basic awareness of CPU, memory, threads, and database calls; teaches profiling from installation and configuration.
What you can do after
Diagnose/debug with VisualVM by sampling execution, narrowing code, measuring methods, inspecting resources, retrieving SQL, and escalating to lock or thread-dump analysis.
How it connects
Connects sampling and instrumentation with debugging, thread dumps, garbage collection, synchronization, JDBC, SQL, and persistence frameworks.

Also explained in

Compare how 3 books explain profiler →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.