Profiling::ScopedRegion#

Defined in header <Kokkos_Profiling_ScopedRegion.hpp>

Usage#

Kokkos::Profiling::ScopedRegion region("label");  // (since 4.1)

The class ScopedRegion is a RAII wrapper that “pushes” a user-defined profiling region when an object is created and properly “pops” that region upon destruction when the scope is exited. This is useful in particular to profile code that has non-trivial control flow (e.g. early return).

The ScopedRegion class is non-copyable.

ScopedRegion(std::string const &regionName);#

Starts a user-defined region with provided label. Calls Profiling::pushRegion(regionName)

~ScopedRegion();#

Ends the region. Calls Profiling::popRegion()

Example#

#include <Kokkos_Profiling_ScopedRegion.hpp>

void do_work_v1() {
  Kokkos::Profiling::pushRegion("MyApp::do_work");
  // <code>
  if (cond) {
    Kokkos::Profiling::popRegion();  // must remember to pop here as well
    return;
  }
  // <more code>
  Kokkos::Profiling::popRegion();
}

void do_work_v2() {
  Kokkos::Profiling::ScopedRegion region("MyApp::do_work");
  // <code>
  if (cond) return;
  // <more code>
}

See also

ProfilingSection: Implements a scope-based section ownership wrapper