Fully featured low overhead profiler for Java EE and Java SE platforms.
Easy-to-use performance and memory .NET profiler for Windows, Linux and macOS.
Secure and easy profiling in cloud, containers and clustered environments.
Performance monitoring and profiling of Jenkins, Bamboo, TeamCity, Gradle, Maven, Ant and JUnit.

CPU sampling

How CPU sampling works

CPU sampling works by taking periodic stack snapshots of the application's call stack to identify which functions are currently executing. Over time, a pattern emerges as certain functions are seen to be executing more frequently than others. The frequency with which a function appears in the sampled call stacks indicates its relative contribution to the total CPU time. By focusing on the functions that appear most often, developers can pinpoint performance bottlenecks.

It's important to note that because CPU sampling takes periodic stack snapshots, it doesn't capture every method invocation. This means that it can't provide an exact count of how many times a specific method was called. The data is statistical in nature and is meant to give an overall view of where the application spends most of its CPU time.

Advantages

  • Lower performance overhead
  • Easier data analysis

Disadvantages

  • Less detailed than tracing
  • May miss short-lived or rare events

Performance overhead

The performance impact of CPU sampling is generally low. It adds some overhead to the application, but the impact is often minimal because the sampling frequency is typically low. It is a lightweight method and is usually suitable for use in production environments. Please read this article if you want to learn more about how to reduce or avoid the impact of the profiler.

Use CPU sampling when you want a lightweight method to identify performance bottlenecks with minimal impact on the application. CPU sampling is suitable for use in production environments or when a high-level overview of the application's performance is sufficient.

Options

You can configure some CPU sampling aspects with the following options.

sampling options

Measured time

Specify whether CPU or wall time will be measured for profiled methods.

Sampling period

Interval between thread stack samples.

YourKit uses cookies and other technologies to improve your browsing experience on our website, to show you personalized content, to analyze our website traffic, and to understand where our visitors are coming from.

By browsing our website, you consent to our use of cookies and other tracking technologies in accordance with the YourKit privacy policy.