Chapter 8: Using advanced visualization tools for profiled data
This introduction describes call graphs and flame graphs as investigation views and explains why the chapter uses JProfiler alongside prior VisualVM techniques.
After this chapter you will be able to
- Call graph representation. Explain what call graphs represent and why they can help when investigating unfamiliar code.
- Flame graph perspective. Describe what a flame graph focuses on and why its different view can help identify performance problems.
- Connection leaks and limits. Explain how unclosed JDBC connections can prevent an app from connecting to its database, even when a framework manages connections in other situations.
- Connection failure diagnosis. Trace how the request pattern, logs, and sampling lead to a suspected connection leak in the example.
- JProfiler JDBC leak investigation. Describe how to attach JProfiler, start JDBC profiling, and recognize the example's connection leak.
- Leaking connection creation trace. Explain how CPU profiling helps locate the code that creates a leaking connection.
- Connection fix and verification. Describe the example's connection fix and how profiling and repeated requests verify it.
- Call graphs and stack traces. Explain how call graphs complement execution stack traces when investigating an application’s design.
- JProfiler call graph generation. Describe how to generate a call graph from a recorded execution in JProfiler.
- Call graph navigation and details. Explain what JProfiler initially shows around the selected method and what else can be explored in the call graph.
- Flame graph stack structure. Explain how a flame graph represents a thread’s execution and why it can help identify potential latencies.
- Relative method execution times. Explain how to compare execution times of methods called by the same method in a flame graph.
- MongoDB event recording workflow. Describe how to set up the example and record its MongoDB events in JProfiler.
- Intercepted event investigation details. Explain what JProfiler shows for the intercepted NoSQL events and how that helps investigate application behavior.
What it builds on
- Sampling to observe executing code (chapter 7) · Sampling and visualizing an app’s execution as discussed in the preceding chapter.
- What is the execution stack trace, and how do I use it? (chapter 2) · Execution stack traces as a way to inspect execution.
Section by section
Introduction
This introduction describes call graphs and flame graphs as investigation views and explains why the chapter uses JProfiler alongside prior VisualVM techniques.
- Call graph representation: Explain what call graphs represent and why they can help when investigating unfamiliar code.
Why it matters: This view can make an unfamiliar codebase easier to understand. - Flame graph perspective: Describe what a flame graph focuses on and why its different view can help identify performance problems.
Why it matters: Another view of execution data can make performance problems easier to spot. - Profiler tool choice: Explain why the chapter uses JProfiler rather than relying only on VisualVM.
Why it matters: The choice of profiler determines which investigation capabilities are available.
Key terms: call graphs, dependencies, flame graph, execution stack, execution time, latencies, VisualVM, JProfiler, licensed profiler, trial period
8.1 Detecting problems with JDBC connections
This section investigates a JDBC connection leak with JProfiler, locates its source, and verifies a fix.
- Connection leaks and limits: Explain how unclosed JDBC connections can prevent an app from connecting to its database, even when a framework manages connections in other situations.
Why it matters: A connection leak can exhaust the available connections even in an app that normally relies on a framework. - Connection failure diagnosis: Trace how the request pattern, logs, and sampling lead to a suspected connection leak in the example.
Why it matters: The visible failure can point toward a leak without identifying the code responsible for it. - JProfiler JDBC leak investigation: Describe how to attach JProfiler, start JDBC profiling, and recognize the example's connection leak.
Why it matters: JDBC profiling lets you check whether connections actually remain open rather than guessing from their count. - Leaking connection creation trace: Explain how CPU profiling helps locate the code that creates a leaking connection.
Why it matters: Finding an open connection is only the first step; its creation trace can lead you to the code to inspect. - Connection fix and verification: Describe the example's connection fix and how profiling and repeated requests verify it.
Why it matters: A fix is more convincing when a repeat investigation and functional test both show the problem has disappeared. - Early profiling practice: State why the author recommends profiling after an implementation or bug fix.
Why it matters: Regular profiling can expose performance problems before they become harder to investigate.
Key terms: JDBC connection, DBMS, connection leak, sampling, exception stack trace, JProfiler, Quick Attach, instrumentation, JDBC profiling, Connections
8.2 Understanding the app’s code design using call graphs
This section explains how to generate and interpret JProfiler call graphs to understand an application’s execution and class design.
- Call graphs and stack traces: Explain how call graphs complement execution stack traces when investigating an application’s design.
Why it matters: This helps you choose a useful starting point when unfamiliar or messy code is hard to follow. - JProfiler call graph generation: Describe how to generate a call graph from a recorded execution in JProfiler.
Why it matters: These steps turn collected CPU profiling data into a view of the execution’s calls. - Call graph navigation and details: Explain what JProfiler initially shows around the selected method and what else can be explored in the call graph.
Why it matters: Knowing what the graph shows lets you follow an execution beyond the method you first selected.
Key terms: call graph, execution stack trace, class design, CPU profiling, call tree, Show Call Graph, JProfiler, call chain, execution time, number of invocations
8.3 Using flame graphs to spot performance problems
This section explains how to create and read JProfiler flame graphs to identify potential latencies and use colorization to navigate complex graphs.
- Flame graph stack structure: Explain how a flame graph represents a thread’s execution and why it can help identify potential latencies.
Why it matters: The layers let you follow the execution while looking for potential latency. - Relative method execution times: Explain how to compare execution times of methods called by the same method in a flame graph.
Why it matters: Comparing lengths helps you spot which calls may contribute more to latency. - JProfiler flame graph creation: Describe how to turn an existing call tree into a flame graph in JProfiler.
Why it matters: This gives you another view of an already generated call tree. - Flame graph colorization rules: Describe how JProfiler colorization makes a complex flame graph easier to navigate.
Why it matters: Color highlights make relevant layers easier to find in a complicated graph.
Key terms: flame graph, execution tree, execution stack, latencies, length, execution time, caller, layer, call tree, Analyze
8.4 Analyzing queries on NoSQL databases
This section demonstrates how to record and inspect a MongoDB application's database events using JProfiler.
- MongoDB event recording workflow: Describe how to set up the example and record its MongoDB events in JProfiler.
Why it matters: This workflow lets you capture the database activity you want to investigate. - Intercepted event investigation details: Explain what JProfiler shows for the intercepted NoSQL events and how that helps investigate application behavior.
Why it matters: The event details connect database activity to application calls and help you inspect how often and how long those calls run.
Key terms: MongoDB, JProfiler, Databases, recording, endpoints, NoSQL, Cassandra, events, stack traces, call trees
8.5 Summary
Concepts explained in this chapter
- JProfilerJProfiler is a commercial profiling tool for Java applications.
- connection leakA condition in which a database connection is not closed or released after use, leaving it unavailable for other operations.
- flame graphA visualization of an execution stack in which methods are arranged by call level and their widths indicate relative execution time.
- call graphA visual representation of execution data that shows relationships between objects and method calls.
- NoSQL databaseA database that uses a nonrelational data model rather than the relational model.
- instrumentationA technique that inserts or applies probes to program execution to collect runtime information.
- jdbc profilingProfiling that intercepts database queries sent through the Java Database Connectivity API.
- method invocation countThe number of times a method is called during program execution.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
