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

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

Member Typedef Documentation

◆ base_type

◆ ratio_t

Definition at line 381 of file components.hpp.

◆ storage_type

Definition at line 66 of file declaration.hpp.

◆ this_type

◆ value_type

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

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

435 {
436 if(wc && cc)
437 m_derive = true;
438 return m_derive;
439 }

◆ derive()

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

Definition at line 441 of file components.hpp.

442 {
443 if(m_derive && wc && cc)
444 {
445 value.first = cc->get_value();
446 value.second = wc->get_value();
447 accum += value;
448 return true;
449 }
450 return false;
451 }

◆ description()

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

Definition at line 387 of file components.hpp.

388 {
389 return "Percentage of CPU-clock time divided by wall-clock time for calling "
390 "process (all threads)";
391 }

◆ get()

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

Definition at line 396 of file components.hpp.

397 {
398 const auto& _data = load();
399 double denom = (_data.second > 0) ? _data.second : 1;
400 double numer = (_data.second > 0) ? _data.first : 0;
401 return 100.0 * static_cast<double>(numer) / static_cast<double>(denom);
402 }

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

Referenced by get_display().

◆ get_display()

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

Definition at line 404 of file components.hpp.

404{ return get(); }
double get() const noexcept
Definition: components.hpp:396

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

Definition at line 453 of file components.hpp.

453{ return m_derive; }

◆ label()

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

Definition at line 386 of file components.hpp.

386{ return "proc_cpu_util"; }

◆ operator+=()

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

Definition at line 420 of file components.hpp.

421 {
422 accum += rhs.accum;
423 value += rhs.value;
424 return *this;
425 }

◆ operator-=()

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

Definition at line 427 of file components.hpp.

428 {
429 accum -= rhs.accum;
430 value -= rhs.value;
431 return *this;
432 }

◆ record()

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

Definition at line 392 of file components.hpp.

393 {
395 }
static value_type record() noexcept
Definition: components.hpp:248
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:382
static value_type record() noexcept
Definition: wall_clock.hpp:55

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

Referenced by start(), and stop().

◆ serialization()

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

Definition at line 403 of file components.hpp.

403{ return get_display(); }
double get_display() const noexcept
Definition: components.hpp:404

References get_display().

◆ start()

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

Definition at line 405 of file components.hpp.

406 {
407 if(!m_derive)
408 value = record();
409 }

References record().

◆ stop()

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

Definition at line 410 of file components.hpp.

411 {
412 using namespace tim::component::operators;
413 if(!m_derive)
414 {
415 value = (record() - value);
416 accum += value;
417 }
418 }

References record().


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