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::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
 
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 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 ()
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

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

Member Typedef Documentation

◆ base_type

◆ ratio_t

Definition at line 467 of file components.hpp.

◆ storage_type

Definition at line 66 of file declaration.hpp.

◆ this_type

◆ value_type

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

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

521 {
522 if(wc && cc)
523 m_derive = true;
524 return m_derive;
525 }

◆ derive()

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

Definition at line 527 of file components.hpp.

528 {
529 if(m_derive && wc && cc)
530 {
531 value.first = cc->get_value();
532 value.second = wc->get_value();
533 accum += value;
534 return true;
535 }
536 return false;
537 }

◆ description()

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

Definition at line 473 of file components.hpp.

474 {
475 return "Percentage of CPU-clock time divided by wall-clock time for calling "
476 "thread";
477 }

◆ get()

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

Definition at line 482 of file components.hpp.

483 {
484 const auto& _data = load();
485 double denom = (_data.second > 0) ? _data.second : 1;
486 double numer = (_data.second > 0) ? _data.first : 0;
487 return 100.0 * static_cast<double>(numer) / static_cast<double>(denom);
488 }

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

Referenced by get_display().

◆ get_display()

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

Definition at line 490 of file components.hpp.

490{ return get(); }
double get() const noexcept
Definition: components.hpp:482

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::thread_cpu_util::is_derived ( ) const
inlinenoexcept

Definition at line 539 of file components.hpp.

539{ return m_derive; }

◆ label()

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

Definition at line 472 of file components.hpp.

472{ return "thread_cpu_util"; }

◆ operator+=()

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

Definition at line 506 of file components.hpp.

507 {
508 accum += rhs.accum;
509 value += rhs.value;
510 return *this;
511 }

◆ operator-=()

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

Definition at line 513 of file components.hpp.

514 {
515 accum -= rhs.accum;
516 value -= rhs.value;
517 return *this;
518 }

◆ record()

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

Definition at line 478 of file components.hpp.

479 {
481 }
static value_type record() noexcept
Definition: components.hpp:214
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:468
static value_type record() noexcept
Definition: wall_clock.hpp:55

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

Referenced by start(), and stop().

◆ serialization()

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

Definition at line 489 of file components.hpp.

489{ return get_display(); }
double get_display() const noexcept
Definition: components.hpp:490

References get_display().

◆ start()

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

Definition at line 491 of file components.hpp.

492 {
493 if(!m_derive)
494 value = record();
495 }
static value_type record()
Definition: components.hpp:478

References record().

◆ stop()

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

Definition at line 496 of file components.hpp.

497 {
498 using namespace tim::component::operators;
499 if(!m_derive)
500 {
501 value = (record() - value);
502 accum += value;
503 }
504 }

References record().


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