Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:54:10

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file corecel/sys/TraceCounter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cstddef>
0010 #include <cstdint>
0011 #include <type_traits>
0012 
0013 #include "corecel/Config.hh"
0014 
0015 #include "ScopedProfiling.hh"
0016 
0017 #include "detail/TraceCounterImpl.hh"
0018 
0019 namespace celeritas
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Simple performance tracing counter.
0024  * \tparam T Arithmetic counter type
0025  *
0026  * Records a named value at the current timestamp which
0027  * can then be displayed on a timeline. This is implemented for Perfetto and
0028  * CUDA NVTX.
0029  *
0030  * See https://perfetto.dev/docs/instrumentation/track-events#counters
0031  */
0032 template<class T>
0033 inline void trace_counter(char const* name, T value)
0034 {
0035     static_assert(std::is_arithmetic_v<T>,
0036                   "Only numeric counters are supported");
0037     if ((CELERITAS_USE_PERFETTO || CELERITAS_USE_CUDA) && use_profiling())
0038     {
0039         using counter_type = detail::trace_counter_type<T>;
0040         detail::trace_counter_impl<counter_type>(name, value);
0041     }
0042 }
0043 
0044 //---------------------------------------------------------------------------//
0045 }  // namespace celeritas