NvtxRange#

public class NvtxRange implements AutoCloseable#

This class supports push/pop NVTX profiling ranges, or “scoped” ranges.

The constructor pushes an NVTX range and the close method pops off the most recent range that was pushed. Therefore instances of this class should always be used in a try-with-resources block to guarantee that ranges are always closed in the proper order. For example:

  try (NvtxRange a = new NvtxRange("a", NvtxColor.RED)) {
    ...
    try (NvtxRange b = new NvtxRange("b", NvtxColor.BLUE)) {
      ...
    }
    ...
  }

Instances should be associated with a single thread to avoid pushing an NVTX range in one thread and then trying to pop the range in a different thread.

Push/pop ranges show a stacking behavior in tools such as Nsight, where newly pushed ranges are correlated and enclosed by the prior pushed range (in the example above, “b” is enclosed by “a”).

Constructor Summary

Method Summary

Constructors

public NvtxRange(String name, NvtxColor color)#
public NvtxRange(String name, int colorBits)#

Methods

public void close()#

Static Methods

public static void pushRange(String name, NvtxColor color)#
public static void popRange()#