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

this computes the CPU utilization percentage for ONLY the calling thread (excludes sibling and child threads). 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::thread_cpu_util:

Public Types

using ratio_t = std::nano
 
using value_type = std::pair< int64_t, int64_t >
 
using base_type = base< thread_cpu_util, value_type >
 
using this_type = thread_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 thread_cpu_clock *cc) noexcept
 
bool derive (const wall_clock *wc, const thread_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 thread (excludes sibling and child threads). 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 480 of file components.hpp.

Member Typedef Documentation

◆ base_type

◆ ratio_t

Definition at line 482 of file components.hpp.

◆ this_type

◆ value_type

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

Definition at line 483 of file components.hpp.

Member Function Documentation

◆ assemble()

bool tim::component::thread_cpu_util::assemble ( const wall_clock wc,
const thread_cpu_clock cc 
)
inlinenoexcept

Definition at line 535 of file components.hpp.

536  {
537  if(wc && cc)
538  m_derive = true;
539  return m_derive;
540  }

◆ derive()

bool tim::component::thread_cpu_util::derive ( const wall_clock wc,
const thread_cpu_clock cc 
)
inlinenoexcept

Definition at line 542 of file components.hpp.

543  {
544  if(m_derive && wc && cc)
545  {
546  value.first = cc->get_value();
547  value.second = wc->get_value();
548  accum += value;
549  return true;
550  }
551  return false;
552  }

◆ description()

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

Definition at line 488 of file components.hpp.

489  {
490  return "Percentage of CPU-clock time divided by wall-clock time for calling "
491  "thread";
492  }

◆ get()

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

Definition at line 497 of file components.hpp.

498  {
499  const auto& _data = load();
500  double denom = (_data.second > 0) ? _data.second : 1;
501  double numer = (_data.second > 0) ? _data.first : 0;
502  return 100.0 * static_cast<double>(numer) / static_cast<double>(denom);
503  }

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

◆ get_display()

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

Definition at line 505 of file components.hpp.

505 { return get(); }
double get() const noexcept
Definition: components.hpp:497

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

◆ is_derived()

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

Definition at line 554 of file components.hpp.

554 { return m_derive; }

◆ label()

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

Definition at line 487 of file components.hpp.

487 { return "thread_cpu_util"; }

◆ operator+=()

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

Definition at line 521 of file components.hpp.

522  {
523  accum += rhs.accum;
524  value += rhs.value;
525  return *this;
526  }

◆ operator-=()

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

Definition at line 528 of file components.hpp.

529  {
530  accum -= rhs.accum;
531  value -= rhs.value;
532  return *this;
533  }

◆ record()

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

Definition at line 493 of file components.hpp.

494  {
496  }
static value_type record() noexcept
Definition: components.hpp:225
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:483
static value_type record() noexcept
Definition: wall_clock.hpp:55

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

◆ serialization()

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

Definition at line 504 of file components.hpp.

504 { return get_display(); }
double get_display() const noexcept
Definition: components.hpp:505

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

◆ start()

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

Definition at line 506 of file components.hpp.

507  {
508  if(!m_derive)
509  value = record();
510  }
static value_type record()
Definition: components.hpp:493

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

◆ stop()

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

Definition at line 511 of file components.hpp.

512  {
513  using namespace tim::component::operators;
514  if(!m_derive)
515  {
516  value = (record() - value);
517  accum += value;
518  }
519  }

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


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