RousselTMLEARNING

Observability

Profiling & Optimization in Dynatrace

Optimizing code with the Dynatrace Profiling & Optimization app: continuous CPU, memory and thread profiling, reading flame graphs, method hotspots, garbage collection, before-and-after comparison, and an optimization method.

1. Continuous profiling #

Seeing where time is spent.

The principle #

Good to know : Dynatrace SaaS, third-generation platform (Grail, AppEngine). The apps mentioned are in the app launcher; some depend on the licence (Dynatrace Platform Subscription).

OneAgent continuously samples process call stacks (Java, .NET, Node.js, Go, PHP… depending on technology). The Profiling & Optimization app aggregates these samples: you see which methods consume CPU, where memory is allocated and what threads are doing, in production, without restarting the application.

Profiling & Optimization

The analyses #

AnalysisAnswers
CPUwhich methods consume the processor?
Memory (allocations)which code allocates most, and why is the garbage collector working so hard?
Threadsare threads waiting on a lock, an I/O, a pool?
Service hotspotsin a slow request, which share goes to code, database, external calls?

2. Reading a flame graph #

Width = time, height = depth.

Reading rules #

  • Each rectangle is a method; its width is the share of samples where it was present.
  • The stack reads bottom to top: caller at the bottom, callee at the top.
  • Look for wide plateaus at the top of the stack: that is “self time”, where optimizing pays off.
  • Filter by service, process or period (before and after a release) to compare.
Best practice : Libraries (JSON serialization, regular expressions, logging) often show up on top: an overly verbose log level or a regex recompiled on each call are easy wins.

3. The method #

Measure, fix, compare.

Steps #

Optimization method
  1. Start from a measured symptom: high CPU, rising p95 latency, garbage collection pause time, infrastructure cost.
  2. Identify the most expensive process (query below), then open its profile.
  3. Spot the hotspots and form a hypothesis (algorithm, allocation, contention).
  4. Fix, deploy, then compare profiles and metrics before and after on comparable traffic.
// Most CPU-hungry processes over 1 h: where to start
timeseries cpu = avg(dt.process.cpu.usage), by: { dt.entity.process_group_instance }, from: now() - 1h
| fieldsAdd average = arrayAvg(cpu)
| sort average desc
| limit 10
Good to know : Check in the metrics browser the exact name of the process CPU metric in your environment.

4. Common cases #

What the profile reveals.

Symptoms and causes #

SymptomWhat you see in the profileLead
CPU at 100% with no traffic increasea loop or regex dominatesalgorithm, cache, precompiled regex
Frequent GC pausesmassive temporary object allocationsreuse, reduce copies, tune the heap
High latency, low CPUthreads waiting (lock, connection pool)pool size, contention, external calls
High cloud costexpensive serialization and loggingformats, log levels, sampling

Commands to know #

Commands to know
  • timeseries avg(dt.process.cpu.usage), by: { dt.entity.process_group_instance } : CPU per process
  • timeseries avg(dt.host.cpu.usage), by: { dt.entity.host } : CPU per host
  • Profiling & Optimization › CPU / Memory / Threads : open an analysis

Sources #

Based on the official Dynatrace documentation checked in November 2026: platform apps change every month, check labels, permissions and field names in your environment before relying on a detail.

Related articles

Time-based vs event-based SLO: understanding, computing and choosing (with the Qonto example)

Differences between time-based SLOs (time slices, uptime) and event-based SLOs (good events over total): defi…

The observability trilemma: cost, completeness and performance, and how solutions resolve it

Understanding the observability trilemma (cost, data completeness, query performance), its three trade-offs, …

Accessing the Dynatrace playground and getting started

The Dynatrace playground is a demo environment full of real data: how to access it, what it allows and does n…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!