Skip to content

Commit

Permalink
Use string view in scoped profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Apr 28, 2024
1 parent 66e223f commit a3b6bbe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/celeritas/global/detail/ActionSequence.cc
Expand Up @@ -89,7 +89,7 @@ void ActionSequence<Params>::begin_run(Params const& params, State<M>& state)
{
for (auto const& sp_action : begin_run_)
{
ScopedProfiling profile_this{std::string{sp_action->label()}};
ScopedProfiling profile_this{sp_action->label()};
sp_action->begin_run(params, state);
}
}
Expand All @@ -113,7 +113,7 @@ void ActionSequence<Params>::execute(Params const& params, State<M>& state)
// Execute all actions and record the time elapsed
for (auto i : range(actions_.size()))
{
ScopedProfiling profile_this{std::string{actions_[i]->label()}};
ScopedProfiling profile_this{actions_[i]->label()};
Stopwatch get_time;
actions_[i]->execute(params, state);
if (M == MemSpace::device)
Expand All @@ -128,7 +128,7 @@ void ActionSequence<Params>::execute(Params const& params, State<M>& state)
// Just loop over the actions
for (auto const& sp_action : actions_)
{
ScopedProfiling profile_this{std::string{sp_action->label()}};
ScopedProfiling profile_this{sp_action->label()};
sp_action->execute(params, state);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/corecel/sys/ScopedProfiling.cuda.cc
Expand Up @@ -37,7 +37,7 @@ nvtxDomainHandle_t domain_handle()
*
* Insert it if it doesn't already exist.
*/
nvtxStringHandle_t message_handle_for(std::string const& message)
nvtxStringHandle_t message_handle_for(std::string_view message)
{
static std::unordered_map<std::string, nvtxStringHandle_t> registry;
static std::shared_mutex mutex;
Expand All @@ -53,15 +53,15 @@ nvtxStringHandle_t message_handle_for(std::string const& message)
}

// We did not find the handle; try to insert it
auto [iter, inserted] = [&message] {
auto [iter, inserted] = [message] {
std::unique_lock lock(mutex);
return registry.insert({message, {}});
return registry.insert({std::string{message}, {}});
}();
if (inserted)
{
// Register the domain
iter->second
= nvtxDomainRegisterStringA(domain_handle(), message.c_str());
= nvtxDomainRegisterStringA(domain_handle(), iter->first.c_str());
}
return iter->second;
}
Expand Down
8 changes: 4 additions & 4 deletions src/corecel/sys/ScopedProfiling.hh
Expand Up @@ -21,12 +21,12 @@ namespace celeritas
*/
struct ScopedProfilingInput
{
std::string name; //!< Name of the range
std::string_view name; //!< Name of the range
uint32_t color{}; //!< ARGB
int32_t payload{}; //!< User data
uint32_t category{}; //!< Category, used to group ranges together

ScopedProfilingInput(std::string const& name) : name{name} {}
ScopedProfilingInput(std::string_view n) : name{n} {}
};

//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -68,7 +68,7 @@ class ScopedProfiling
// Activate profiling with options
explicit inline ScopedProfiling(Input const& input);
// Activate profiling with just a name
explicit inline ScopedProfiling(std::string const& name);
explicit inline ScopedProfiling(std::string_view name);

// Deactivate profiling
inline ~ScopedProfiling();
Expand Down Expand Up @@ -104,7 +104,7 @@ ScopedProfiling::ScopedProfiling(Input const& input)
/*!
* Activate device profiling with just a name.
*/
ScopedProfiling::ScopedProfiling(std::string const& name)
ScopedProfiling::ScopedProfiling(std::string_view name)
: ScopedProfiling{Input{name}}
{
}
Expand Down
5 changes: 4 additions & 1 deletion src/corecel/sys/ScopedProfiling.hip.cc
Expand Up @@ -8,6 +8,8 @@
//---------------------------------------------------------------------------//
#include "ScopedProfiling.hh"

#include <string>

#include "celeritas_sys_config.h"
#include "corecel/io/Logger.hh"

Expand Down Expand Up @@ -56,7 +58,8 @@ void ScopedProfiling::activate(Input const& input) noexcept
{
int result = 0;
#if CELERITAS_HAVE_ROCTX
result = roctxRangePush(input.name.c_str());
std::string temp_name{input.name};
result = roctxRangePush(temp_name.c_str());
#endif
if (result < 0)
{
Expand Down

0 comments on commit a3b6bbe

Please sign in to comment.