timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::component::cpu_util Struct Reference

this computes the CPU utilization percentage for the calling process and child processes. Only relevant as a time when a different is computed Do not use a single CPU time as an amount of time; it doesn't work that way. More...

#include "timemory/components/timing/components.hpp"

+ Collaboration diagram for tim::component::cpu_util:

Public Types

using ratio_t = std::nano
 
using value_type = std::pair< int64_t, int64_t >
 
using base_type = base< cpu_util, value_type >
 
using this_type = cpu_util
 
using storage_type = empty_storage
 

Public Member Functions

double get () const noexcept
 
double serialization () const noexcept
 
double get_display () const noexcept
 
void start () noexcept
 
void stop () noexcept
 
this_typeoperator+= (const this_type &rhs) noexcept
 
this_typeoperator-= (const this_type &rhs) noexcept
 
bool assemble (const wall_clock *wc, const cpu_clock *cc) noexcept
 
bool assemble (const wall_clock *wc, const user_clock *uc, const system_clock *sc) noexcept
 
bool derive (const wall_clock *wc, const cpu_clock *cc) noexcept
 
bool derive (const wall_clock *wc, const user_clock *uc, const system_clock *sc) noexcept
 
bool is_derived () const noexcept
 

Static Public Member Functions

static std::string label ()
 
static std::string description ()
 
static value_type record ()
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

Detailed Description

this computes the CPU utilization percentage for the calling process and child processes. Only relevant as a time when a different is computed Do not use a single CPU time as an amount of time; it doesn't work that way.

Definition at line 271 of file components.hpp.

Member Typedef Documentation

◆ base_type

◆ ratio_t

Definition at line 273 of file components.hpp.

◆ storage_type

Definition at line 66 of file declaration.hpp.

◆ this_type

Definition at line 276 of file components.hpp.

◆ value_type

using tim::component::cpu_util::value_type = std::pair<int64_t, int64_t>

Definition at line 274 of file components.hpp.

Member Function Documentation

◆ assemble() [1/2]

bool tim::component::cpu_util::assemble ( const wall_clock wc,
const cpu_clock cc 
)
inlinenoexcept

Definition at line 327 of file components.hpp.

328 {
329 if(wc && cc)
330 m_derive = true;
331 return m_derive;
332 }

◆ assemble() [2/2]

bool tim::component::cpu_util::assemble ( const wall_clock wc,
const user_clock uc,
const system_clock sc 
)
inlinenoexcept

Definition at line 334 of file components.hpp.

336 {
337 if(wc && uc && sc)
338 m_derive = true;
339 return m_derive;
340 }

◆ derive() [1/2]

bool tim::component::cpu_util::derive ( const wall_clock wc,
const cpu_clock cc 
)
inlinenoexcept

Definition at line 342 of file components.hpp.

343 {
344 if(m_derive && wc && cc)
345 {
346 value.first = cc->get_value();
347 value.second = wc->get_value();
348 accum += value;
349 return true;
350 }
351 return false;
352 }

◆ derive() [2/2]

bool tim::component::cpu_util::derive ( const wall_clock wc,
const user_clock uc,
const system_clock sc 
)
inlinenoexcept

Definition at line 354 of file components.hpp.

356 {
357 if(m_derive && wc && uc && sc)
358 {
359 value.first = uc->get_value() + sc->get_value();
360 value.second = wc->get_value();
361 accum += value;
362 return true;
363 }
364 return false;
365 }

◆ description()

static std::string tim::component::cpu_util::description ( )
inlinestatic

Definition at line 279 of file components.hpp.

280 {
281 return "Percentage of CPU-clock time divided by wall-clock time";
282 }

◆ get()

double tim::component::cpu_util::get ( ) const
inlinenoexcept

Definition at line 287 of file components.hpp.

288 {
289 const auto& _data = load();
290 double denom = (_data.second > 0) ? _data.second : 1;
291 double numer = (_data.second > 0) ? _data.first : 0;
292 return 100.0 * static_cast<double>(numer) / static_cast<double>(denom);
293 }

References tim::component::base< cpu_util, std::pair< int64_t, int64_t > >::load().

Referenced by get_display().

◆ get_display()

double tim::component::cpu_util::get_display ( ) const
inlinenoexcept

Definition at line 295 of file components.hpp.

295{ return get(); }
double get() const noexcept
Definition: components.hpp:287

References get().

Referenced by serialization().

◆ get_opaque()

template<typename... Args>
static opaque tim::component::empty_base::get_opaque ( Args &&  ...)
inlinestaticinherited

Definition at line 72 of file declaration.hpp.

73 {
74 return opaque{};
75 }

◆ is_derived()

bool tim::component::cpu_util::is_derived ( ) const
inlinenoexcept

Definition at line 367 of file components.hpp.

367{ return m_derive; }

◆ label()

static std::string tim::component::cpu_util::label ( )
inlinestatic

Definition at line 278 of file components.hpp.

278{ return "cpu_util"; }

◆ operator+=()

this_type & tim::component::cpu_util::operator+= ( const this_type rhs)
inlinenoexcept

Definition at line 313 of file components.hpp.

314 {
315 accum += rhs.accum;
316 value += rhs.value;
317 return *this;
318 }

◆ operator-=()

this_type & tim::component::cpu_util::operator-= ( const this_type rhs)
inlinenoexcept

Definition at line 320 of file components.hpp.

321 {
322 accum -= rhs.accum;
323 value -= rhs.value;
324 return *this;
325 }

◆ record()

static value_type tim::component::cpu_util::record ( )
inlinestatic

Definition at line 283 of file components.hpp.

284 {
286 }
static value_type record() noexcept
Definition: components.hpp:116
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:274
static value_type record() noexcept
Definition: wall_clock.hpp:55

References tim::component::cpu_clock::record(), and tim::component::wall_clock::record().

Referenced by start(), and stop().

◆ serialization()

double tim::component::cpu_util::serialization ( ) const
inlinenoexcept

Definition at line 294 of file components.hpp.

294{ return get_display(); }
double get_display() const noexcept
Definition: components.hpp:295

References get_display().

◆ start()

void tim::component::cpu_util::start ( )
inlinenoexcept

Definition at line 297 of file components.hpp.

298 {
299 if(!m_derive)
300 value = record();
301 }
static value_type record()
Definition: components.hpp:283

References record().

◆ stop()

void tim::component::cpu_util::stop ( )
inlinenoexcept

Definition at line 303 of file components.hpp.

304 {
305 using namespace tim::component::operators;
306 if(!m_derive)
307 {
308 value = (record() - value);
309 accum += value;
310 }
311 }

References record().


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