3. Sampling-based profilingΒΆ

To enable sampling-based profiling, run the application with the NANOS6 environment variable set to profile.

The profile instrumentation uses the following environment variables:

  • NANOS6_PROFILE_NS_RESOLUTION: (default value: 1000), sampling interval in nanoseconds
  • NANOS6_PROFILE_BACKTRACE_DEPTH: (default value: 4), number of stack frames to collect (excluding inlines) in each sample.
  • NANOS6_PROFILE_BUFFER_SIZE: (default value: 1000000000), number of sampling events to preallocate together in a chunk. The default value corresponds to 1 second of samples.

At the end of the execution, the runtime generates four files that contain entries sorted by decreasing frequency. Their first column contains the sample count, and the rest, the actual entry values. Their contents are the following:

line-profile-PID.txt: Source code lines

function-profile-PID.txt: Function names

inline-profile-PID.txt: Function names and source code lines including inlines > Since the sampling is performed over the return addresses in the stack, if the compiler performs inlining, a given address can correspond to several functions. This file shows for the number of samples that have the same associated source code lines.

backtrace-profile-by-line-PID.txt: Function names and source code lines including inlines of a full backtrace > Shows the number of samples that have a full backtrace that corresponds to the same exact source code lines.

backtrace-profile-by-address-PID.txt: Function names and source code lines including inlines of a full backtrace > Shows the number of samples that have a full backtrace with the same exact return addresses.

When compiling, Mercurium performs transformations to the original source code. At this time, Mercurium cannot preserve the original source code lines and function names. Hence, the outputs of the profiler are based on the transformed code. However, the transformed source code can be preserved by passing the -keep parameter to Mercurium.

Mercurium generates additional functions that wrap the task code. These appear in the backtraces and their names begin with nanos6_ol_ and nanos6_unpack_ followed by a number.