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::process_cpu_util Struct Reference

this computes the CPU utilization percentage for ONLY the calling process (excludes 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::process_cpu_util:

Public Types

using ratio_t = std::nano
 
using value_type = std::pair< int64_t, int64_t >
 
using base_type = base< process_cpu_util, value_type >
 
using this_type = process_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 process_cpu_clock *cc) noexcept
 
bool derive (const wall_clock *wc, const process_cpu_clock *cc) 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 ONLY the calling process (excludes 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 394 of file components.hpp.

Member Typedef Documentation

◆ base_type

◆ ratio_t

Definition at line 396 of file components.hpp.

◆ this_type

◆ value_type

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

Definition at line 397 of file components.hpp.

Member Function Documentation

◆ assemble()

bool tim::component::process_cpu_util::assemble ( const wall_clock wc,
const process_cpu_clock cc 
)
inlinenoexcept

Definition at line 449 of file components.hpp.

450  {
451  if(wc && cc)
452  m_derive = true;
453  return m_derive;
454  }

◆ derive()

bool tim::component::process_cpu_util::derive ( const wall_clock wc,
const process_cpu_clock cc 
)
inlinenoexcept

Definition at line 456 of file components.hpp.

457  {
458  if(m_derive && wc && cc)
459  {
460  value.first = cc->get_value();
461  value.second = wc->get_value();
462  accum += value;
463  return true;
464  }
465  return false;
466  }

◆ description()

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

Definition at line 402 of file components.hpp.

403  {
404  return "Percentage of CPU-clock time divided by wall-clock time for calling "
405  "process (all threads)";
406  }

◆ get()

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

Definition at line 411 of file components.hpp.

412  {
413  const auto& _data = load();
414  double denom = (_data.second > 0) ? _data.second : 1;
415  double numer = (_data.second > 0) ? _data.first : 0;
416  return 100.0 * static_cast<double>(numer) / static_cast<double>(denom);
417  }

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

◆ get_display()

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

Definition at line 419 of file components.hpp.

419 { return get(); }
double get() const noexcept
Definition: components.hpp:411

References tim::component::cpu_util::get().

◆ is_derived()

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

Definition at line 468 of file components.hpp.

468 { return m_derive; }

◆ label()

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

Definition at line 401 of file components.hpp.

401 { return "proc_cpu_util"; }

◆ operator+=()

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

Definition at line 435 of file components.hpp.

436  {
437  accum += rhs.accum;
438  value += rhs.value;
439  return *this;
440  }

◆ operator-=()

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

Definition at line 442 of file components.hpp.

443  {
444  accum -= rhs.accum;
445  value -= rhs.value;
446  return *this;
447  }

◆ record()

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

Definition at line 407 of file components.hpp.

408  {
410  }
static value_type record() noexcept
Definition: components.hpp:261
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:397
static value_type record() noexcept
Definition: wall_clock.hpp:55

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

◆ serialization()

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

Definition at line 418 of file components.hpp.

418 { return get_display(); }
double get_display() const noexcept
Definition: components.hpp:419

References tim::component::cpu_util::get_display().

◆ start()

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

Definition at line 420 of file components.hpp.

421  {
422  if(!m_derive)
423  value = record();
424  }

References tim::component::cpu_util::record().

◆ stop()

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

Definition at line 425 of file components.hpp.

426  {
427  using namespace tim::component::operators;
428  if(!m_derive)
429  {
430  value = (record() - value);
431  accum += value;
432  }
433  }

References tim::component::cpu_util::record().


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