timemory  3.2.1
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
 

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 ()
 

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 286 of file components.hpp.

Member Typedef Documentation

◆ base_type

◆ ratio_t

Definition at line 288 of file components.hpp.

◆ this_type

Definition at line 291 of file components.hpp.

◆ value_type

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

Definition at line 289 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 342 of file components.hpp.

343  {
344  if(wc && cc)
345  m_derive = true;
346  return m_derive;
347  }

◆ 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 349 of file components.hpp.

351  {
352  if(wc && uc && sc)
353  m_derive = true;
354  return m_derive;
355  }

◆ derive() [1/2]

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

Definition at line 357 of file components.hpp.

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

◆ 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 369 of file components.hpp.

371  {
372  if(m_derive && wc && uc && sc)
373  {
374  value.first = uc->get_value() + sc->get_value();
375  value.second = wc->get_value();
376  accum += value;
377  return true;
378  }
379  return false;
380  }

◆ description()

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

Definition at line 294 of file components.hpp.

295  {
296  return "Percentage of CPU-clock time divided by wall-clock time";
297  }

◆ get()

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

Definition at line 302 of file components.hpp.

303  {
304  const auto& _data = load();
305  double denom = (_data.second > 0) ? _data.second : 1;
306  double numer = (_data.second > 0) ? _data.first : 0;
307  return 100.0 * static_cast<double>(numer) / static_cast<double>(denom);
308  }

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

Referenced by get_display(), tim::component::process_cpu_util::get_display(), and tim::component::thread_cpu_util::get_display().

◆ get_display()

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

Definition at line 310 of file components.hpp.

310 { return get(); }
double get() const noexcept
Definition: components.hpp:302

References get().

Referenced by serialization(), tim::component::process_cpu_util::serialization(), and tim::component::thread_cpu_util::serialization().

◆ is_derived()

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

Definition at line 382 of file components.hpp.

382 { return m_derive; }

◆ label()

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

Definition at line 293 of file components.hpp.

293 { return "cpu_util"; }

◆ operator+=()

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

Definition at line 328 of file components.hpp.

329  {
330  accum += rhs.accum;
331  value += rhs.value;
332  return *this;
333  }

◆ operator-=()

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

Definition at line 335 of file components.hpp.

336  {
337  accum -= rhs.accum;
338  value -= rhs.value;
339  return *this;
340  }

◆ record()

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

◆ serialization()

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

Definition at line 309 of file components.hpp.

309 { return get_display(); }
double get_display() const noexcept
Definition: components.hpp:310

References get_display().

◆ start()

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

Definition at line 312 of file components.hpp.

313  {
314  if(!m_derive)
315  value = record();
316  }
static value_type record()
Definition: components.hpp:298

References record().

◆ stop()

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

Definition at line 318 of file components.hpp.

319  {
320  using namespace tim::component::operators;
321  if(!m_derive)
322  {
323  value = (record() - value);
324  accum += value;
325  }
326  }

References record().


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