Celeritas  0.5.0-56+6b053cd
Public Member Functions | List of all members
celeritas::ScopedMem Class Reference

Record the change in memory usage between construction and destruction. More...

#include <ScopedMem.hh>

Public Member Functions

 ScopedMem (std::string_view label, MemRegistry *registry)
 Construct with name and a pointer to the mem registry.
 
 ScopedMem (std::string_view label)
 Construct with name and default registry.
 
 ~ScopedMem ()
 Register data on destruction.
 
 CELER_DEFAULT_MOVE_DELETE_COPY (ScopedMem)
 Prevent copying but allow moving.
 

Detailed Description

Record the change in memory usage between construction and destruction.

{
ScopedMem record_mem("create objects");
this->create_stuff();
}

This class is not thread safe because it writes to a shared global index. In a multithreaded environment a "null" scoped memory can be used:

{
auto record_mem = (stream_id == StreamId{0} ? ScopedMem{"label"}
: ScopedMem{});
this->do_stuff();
}
OpaqueId< class Stream_ > StreamId
Unique ID for multithreading/multitasking.
Definition: ThreadId.hh:17
Note
The memory reported will likely only be valid if running a single task on the GPU, because the start and stop values are per GPU rather than per process. Be wary of the result.

The documentation for this class was generated from the following files: