一呼百應, "one call, a hundred responses"
Loading...
Searching...
No Matches
ein::profiling::profile< Mutex, Duration, Clock > Struct Template Reference

#include <profiling.hpp>

Public Types

using mutex = Mutex
 
using duration = Duration
 
using clock = Clock
 
using event = profile_event<Duration, Clock>
 

Public Member Functions

 profile (profile const &)=delete
 
 profile (profile &&)=delete
 
 profile () noexcept
 
 ~profile () noexcept
 
profileoperator= (profile const &)=delete
 
profileoperator= (profile &&)=delete
 
void log (event const &e) noexcept
 
void set_process_name (std::string name="") noexcept
 
void set_thread_name (std::string const &name) noexcept
 
void instant (static_string name, scope s) noexcept
 
void counter (static_string name, nlohmann::json args) noexcept
 
void flow_start (static_string name, static_string category, static_string id) noexcept
 
void flow_end (std::string name, static_string cat, static_string id) noexcept
 
void save (std::filesystem::path filename) noexcept
 

Public Attributes

Mutex events_mutex
 
std::vector< eventevents
 
nlohmann::json metadata
 
bool saved
 
std::filesystem::path filename
 

Friends

template<typename OStream >
OStream & operator<< (OStream &o, profile &p)
 

Detailed Description

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
struct ein::profiling::profile< Mutex, Duration, Clock >

Definition at line 114 of file profiling.hpp.

Member Typedef Documentation

◆ clock

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
using ein::profiling::profile< Mutex, Duration, Clock >::clock = Clock

Definition at line 117 of file profiling.hpp.

◆ duration

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
using ein::profiling::profile< Mutex, Duration, Clock >::duration = Duration

Definition at line 116 of file profiling.hpp.

◆ event

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
using ein::profiling::profile< Mutex, Duration, Clock >::event = profile_event<Duration, Clock>

Definition at line 118 of file profiling.hpp.

◆ mutex

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
using ein::profiling::profile< Mutex, Duration, Clock >::mutex = Mutex

Definition at line 115 of file profiling.hpp.

Constructor & Destructor Documentation

◆ profile() [1/3]

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
ein::profiling::profile< Mutex, Duration, Clock >::profile ( profile< Mutex, Duration, Clock > const & )
delete

◆ profile() [2/3]

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
ein::profiling::profile< Mutex, Duration, Clock >::profile ( profile< Mutex, Duration, Clock > && )
delete

◆ profile() [3/3]

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
ein::profiling::profile< Mutex, Duration, Clock >::profile ( )
inlinenoexcept

Definition at line 129 of file profiling.hpp.

130 : events_mutex()
131 , events()
132 , metadata(nlohmann::json{})
133 , saved(true) {
134 }
nlohmann::json metadata
std::vector< event > events

◆ ~profile()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
ein::profiling::profile< Mutex, Duration, Clock >::~profile ( )
inlinenoexcept

Definition at line 136 of file profiling.hpp.

136 {
137 // TODO: complain if not saved
138 if (!saved)
139 spdlog::warn("Warning: unsaved profile, discarding {} event(s)", events.size());
140 }

References ein::profiling::profile< Mutex, Duration, Clock >::events, and ein::profiling::profile< Mutex, Duration, Clock >::saved.

Member Function Documentation

◆ counter()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::counter ( static_string name,
nlohmann::json args )
inlinenoexcept[[always_inline]]

Definition at line 175 of file profiling.hpp.

175 {
176 log({.name = name, .ph = event_type::counter, .args = std::move(args) });
177 }
void log(event const &e) noexcept

References ein::profiling::counter, and ein::profiling::profile< Mutex, Duration, Clock >::log().

◆ flow_end()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::flow_end ( std::string name,
static_string cat,
static_string id )
inlinenoexcept[[always_inline]]

Definition at line 185 of file profiling.hpp.

185 {
186 log({.name = std::move(name), .cat = std::move(cat), .ph = event_type::flow_end, .id = std::move(id), .bp = "e"_ss});
187 }

References ein::profiling::flow_end, and ein::profiling::profile< Mutex, Duration, Clock >::log().

◆ flow_start()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::flow_start ( static_string name,
static_string category,
static_string id )
inlinenoexcept[[always_inline]]

Definition at line 180 of file profiling.hpp.

180 {
181 log({.name = name, .id = id, .ph = event_type::flow_start, .cat = category});
182 }

References ein::profiling::flow_start, and ein::profiling::profile< Mutex, Duration, Clock >::log().

◆ instant()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::instant ( static_string name,
scope s )
inlinenoexcept[[always_inline]]

Definition at line 170 of file profiling.hpp.

170 {
171 log({.name = name, .ph = event_type::instant, .s = s});
172 }

References ein::profiling::instant, and ein::profiling::profile< Mutex, Duration, Clock >::log().

◆ log()

◆ operator=() [1/2]

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
profile & ein::profiling::profile< Mutex, Duration, Clock >::operator= ( profile< Mutex, Duration, Clock > && )
delete

◆ operator=() [2/2]

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
profile & ein::profiling::profile< Mutex, Duration, Clock >::operator= ( profile< Mutex, Duration, Clock > const & )
delete

◆ save()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::save ( std::filesystem::path filename)
inlinenoexcept[[always_inline]]

Definition at line 190 of file profiling.hpp.

190 {
191 spdlog::info("Saving profile: {}",filename.c_str());
192 std::ofstream o(filename);
193 o << *this;
194 }
std::filesystem::path filename

References ein::profiling::profile< Mutex, Duration, Clock >::filename.

Referenced by ein::profiling::profile_scope< Mutex, Duration, Clock >::~profile_scope().

Here is the caller graph for this function:

◆ set_process_name()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::set_process_name ( std::string name = "")
inlinenoexcept[[always_inline]]

Definition at line 153 of file profiling.hpp.

153 {
154#if defined(__APPLE__)
155 if (name.empty())
156 name = getprogname();
157#elif defined(__linux__)
158 if (name.empty())
159 name = program_invocation_short_name;
160#endif
161 log({.name = "process_name"_ss, .ph = event_type::metadata, .args = { {"name",name}}});
162 }

References ein::profiling::profile< Mutex, Duration, Clock >::log(), and ein::profiling::metadata.

◆ set_thread_name()

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
void ein::profiling::profile< Mutex, Duration, Clock >::set_thread_name ( std::string const & name)
inlinenoexcept[[always_inline]]

Definition at line 165 of file profiling.hpp.

165 {
166 log({.name = "thread_name"_ss, .ph = event_type::metadata, .args = { {"name",name}}});
167 }

References ein::profiling::profile< Mutex, Duration, Clock >::log(), and ein::profiling::metadata.

Friends And Related Symbol Documentation

◆ operator<<

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
template<typename OStream >
OStream & operator<< ( OStream & o,
profile< Mutex, Duration, Clock > & p )
friend[[always_inline]]

Definition at line 199 of file profiling.hpp.

199 {
200 o << std::setw(2) << nlohmann::json(p) << std::endl;
201 p.saved = true;
202 return o;
203 }

Member Data Documentation

◆ events

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
std::vector<event> ein::profiling::profile< Mutex, Duration, Clock >::events

◆ events_mutex

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
Mutex ein::profiling::profile< Mutex, Duration, Clock >::events_mutex

◆ filename

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
std::filesystem::path ein::profiling::profile< Mutex, Duration, Clock >::filename

◆ metadata

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
nlohmann::json ein::profiling::profile< Mutex, Duration, Clock >::metadata

Definition at line 122 of file profiling.hpp.

◆ saved

template<typename Mutex = std::mutex, typename Duration = std::chrono::nanoseconds, typename Clock = std::chrono::high_resolution_clock>
bool ein::profiling::profile< Mutex, Duration, Clock >::saved

The documentation for this struct was generated from the following file: