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

I/O counter for bytes read. Attempt to count the number of bytes which this process really did cause to be fetched from the storage layer. Done at the submit_bio() level, so it is accurate for block-backed filesystems. More...

#include "timemory/components/io/components.hpp"

+ Collaboration diagram for tim::component::read_bytes:

Public Types

using this_type = read_bytes
 
using value_type = std::pair< int64_t, int64_t >
 
using base_type = base< this_type, value_type >
 
using result_type = std::pair< double, double >
 
using unit_type = typename trait::units< this_type >::type
 
using display_unit_type = typename trait::units< this_type >::display_type
 
using storage_type = empty_storage
 

Public Member Functions

std::string get_display () const
 
result_type get () const
 
void start ()
 
void stop ()
 
void sample ()
 sample a measurement More...
 
void sample (const cache_type &_cache)
 sample a measurement from cached data More...
 
void start (const cache_type &_cache)
 start a measurement using the cached data More...
 
void stop (const cache_type &_cache)
 stop a measurement using the cached data More...
 

Static Public Member Functions

static std::string label ()
 
static std::string description ()
 
static std::pair< double, double > unit ()
 
static std::vector< std::string > display_unit_array ()
 
static std::vector< std::string > label_array ()
 
static display_unit_type display_unit ()
 
static std::pair< double, double > unit_array ()
 
static std::vector< std::string > description_array ()
 
static auto get_timestamp ()
 
static value_type record ()
 
static auto get_timing_unit ()
 
static unit_type get_unit ()
 
static display_unit_type get_display_unit ()
 
static value_type record (const cache_type &_cache)
 read the value from the cache More...
 
template<typename... Args>
static opaque get_opaque (Args &&...)
 

Detailed Description

I/O counter for bytes read. Attempt to count the number of bytes which this process really did cause to be fetched from the storage layer. Done at the submit_bio() level, so it is accurate for block-backed filesystems.

Definition at line 465 of file components.hpp.

Member Typedef Documentation

◆ base_type

◆ display_unit_type

◆ result_type

using tim::component::read_bytes::result_type = std::pair<double, double>

Definition at line 470 of file components.hpp.

◆ storage_type

Definition at line 66 of file declaration.hpp.

◆ this_type

◆ unit_type

◆ value_type

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

Definition at line 468 of file components.hpp.

Member Function Documentation

◆ description()

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

Definition at line 475 of file components.hpp.

476 {
477 return "Number of bytes which this process really did cause to be fetched from "
478 "the storage layer";
479 }

◆ description_array()

static std::vector< std::string > tim::component::read_bytes::description_array ( )
inlinestatic

Definition at line 506 of file components.hpp.

507 {
508 return std::vector<std::string>{ "Number of bytes read", "Rate of bytes read" };
509 }

◆ display_unit()

static display_unit_type tim::component::read_bytes::display_unit ( )
inlinestatic

Definition at line 499 of file components.hpp.

500 {
501 return display_unit_type{ "MB", "MB/sec" };
502 }
typename trait::units< this_type >::display_type display_unit_type
Definition: components.hpp:472

Referenced by get_display_unit().

◆ display_unit_array()

static std::vector< std::string > tim::component::read_bytes::display_unit_array ( )
inlinestatic

Definition at line 488 of file components.hpp.

489 {
490 return std::vector<std::string>{ std::get<0>(get_display_unit()),
491 std::get<1>(get_display_unit()) };
492 }
static display_unit_type get_display_unit()
Definition: components.hpp:609

References get_display_unit().

◆ get()

result_type tim::component::read_bytes::get ( ) const
inline

Definition at line 550 of file components.hpp.

551 {
552 auto val = base_type::load();
553
554 double data = std::get<0>(val);
555 double delta = std::get<1>(val);
556
557 delta /= static_cast<double>(std::nano::den);
558 delta *= get_timing_unit();
559
560 double rate = 0.0;
561 if(delta != 0.0)
562 rate = data / delta;
563
564 if(laps > 0)
565 rate *= laps;
566
567 data /= std::get<0>(get_unit());
568 rate /= std::get<0>(get_unit());
569
570 if(!std::isfinite(rate))
571 rate = 0.0;
572
573 return result_type(data, rate);
574 }
bool isfinite(const Tp &arg)
Definition: utility.hpp:104
decltype(auto) load()
static unit_type get_unit()
Definition: components.hpp:586
static auto get_timing_unit()
Definition: components.hpp:515
std::pair< double, double > result_type
Definition: components.hpp:470

References get_timing_unit(), get_unit(), tim::isfinite(), tim::component::base< read_bytes, std::pair< int64_t, int64_t > >::laps, and tim::component::base< Tp, Value >::load().

Referenced by get_display().

◆ get_display()

std::string tim::component::read_bytes::get_display ( ) const
inline

Definition at line 523 of file components.hpp.

524 {
525 std::stringstream ss;
526 std::stringstream ssv;
527 std::stringstream ssr;
528 auto _prec = base_type::get_precision();
529 auto _width = base_type::get_width();
530 auto _flags = base_type::get_format_flags();
531 auto _disp = get_display_unit();
532
533 auto _val = get();
534
535 ssv.setf(_flags);
536 ssv << std::setw(_width) << std::setprecision(_prec) << std::get<0>(_val);
537 if(!std::get<0>(_disp).empty())
538 ssv << " " << std::get<0>(_disp);
539
540 ssr.setf(_flags);
541 ssr << std::setw(_width) << std::setprecision(_prec) << std::get<1>(_val);
542 if(!std::get<1>(_disp).empty())
543 ssr << " " << std::get<1>(_disp);
544
545 ss << ssv.str() << ", " << ssr.str();
546 ss << " read_bytes";
547 return ss.str();
548 }
static short get_precision()
static short get_width()
static fmtflags get_format_flags()
result_type get() const
Definition: components.hpp:550

References get(), get_display_unit(), tim::component::base< Tp, Value >::get_format_flags(), tim::component::base< Tp, Value >::get_precision(), and tim::component::base< Tp, Value >::get_width().

◆ get_display_unit()

static display_unit_type tim::component::read_bytes::get_display_unit ( )
inlinestatic

Definition at line 609 of file components.hpp.

610 {
611 static display_unit_type _instance = this_type::display_unit();
612 static auto& _mem = std::get<0>(_instance);
613 static auto& _rate = std::get<1>(_instance);
614
615 if(settings::memory_units().length() > 0)
616 _mem = std::get<0>(units::get_memory_unit(settings::memory_units()));
617
618 if(settings::timing_units().length() > 0)
619 {
620 auto _tval = std::get<0>(units::get_timing_unit(settings::timing_units()));
621 _rate = mpl::apply<std::string>::join('/', _mem, _tval);
622 }
623 else if(settings::memory_units().length() > 0)
624 {
625 _rate = mpl::apply<std::string>::join('/', _mem, "sec");
626 }
627
628 return _instance;
629 }
std::tuple< std::string, int64_t > get_timing_unit(std::string _unit)
Definition: units.hpp:229
std::tuple< std::string, int64_t > get_memory_unit(std::string _unit)
Definition: units.hpp:188
memory_units
Definition: settings.cpp:1657
timing_units
Definition: settings.cpp:1650
static display_unit_type display_unit()
Definition: components.hpp:499
static string_t join(SepT &&separator, Tuple &&__tup, index_sequence< Idx... >) noexcept
Definition: apply.hpp:408

References display_unit(), tim::units::get_memory_unit(), tim::units::get_timing_unit(), tim::mpl::apply< Ret >::join(), tim::memory_units, and tim::timing_units.

Referenced by display_unit_array(), and get_display().

◆ 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 }

◆ get_timestamp()

static auto tim::component::read_bytes::get_timestamp ( )
inlinestatic

Definition at line 511 of file components.hpp.

511{ return tim::get_clock_real_now<int64_t, std::nano>(); }

Referenced by record().

◆ get_timing_unit()

static auto tim::component::read_bytes::get_timing_unit ( )
inlinestatic

Definition at line 515 of file components.hpp.

516 {
517 static auto _value = units::sec;
518 if(settings::timing_units().length() > 0)
519 _value = std::get<1>(units::get_timing_unit(settings::timing_units()));
520 return _value;
521 }

References tim::units::get_timing_unit(), and tim::timing_units.

Referenced by get().

◆ get_unit()

static unit_type tim::component::read_bytes::get_unit ( )
inlinestatic

Definition at line 586 of file components.hpp.

587 {
588 static auto _instance = this_type::unit();
589 static auto& _mem = std::get<0>(_instance);
590 static auto& _rate = std::get<1>(_instance);
591
592 if(settings::memory_units().length() > 0)
593 _mem = std::get<1>(units::get_memory_unit(settings::memory_units()));
594
595 if(settings::timing_units().length() > 0)
596 {
597 auto _timing_val =
599 _rate = _mem / (_timing_val);
600 }
601
602 static const auto factor = static_cast<double>(std::nano::den);
603 unit_type _tmp = _instance;
604 std::get<1>(_tmp) *= factor;
605
606 return _tmp;
607 }
static std::pair< double, double > unit()
Definition: components.hpp:481
typename trait::units< this_type >::type unit_type
Definition: components.hpp:471

References tim::units::get_memory_unit(), tim::units::get_timing_unit(), tim::memory_units, tim::timing_units, and unit().

Referenced by get().

◆ label()

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

Definition at line 474 of file components.hpp.

474{ return "read_bytes"; }

Referenced by label_array().

◆ label_array()

static std::vector< std::string > tim::component::read_bytes::label_array ( )
inlinestatic

Definition at line 494 of file components.hpp.

495 {
496 return std::vector<std::string>{ label(), "read_rate" };
497 }
static std::string label()
Definition: components.hpp:474

References label().

◆ record() [1/2]

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

Definition at line 513 of file components.hpp.

513{ return value_type(get_bytes_read(), get_timestamp()); }
std::pair< int64_t, int64_t > value_type
Definition: components.hpp:468

References get_timestamp().

Referenced by start(), and stop().

◆ record() [2/2]

static value_type tim::component::read_bytes::record ( const cache_type _cache)
inlinestatic

read the value from the cache

Definition at line 646 of file components.hpp.

647 {
648 return value_type{ _cache.get_bytes_read(), get_timestamp() };
649 }

References get_timestamp().

◆ sample() [1/2]

void tim::component::read_bytes::sample ( )
inline

sample a measurement

Definition at line 632 of file components.hpp.

633 {
634 std::get<0>(accum) = std::get<0>(value) =
635 std::max<int64_t>(std::get<0>(value), get_bytes_read());
636 }

◆ sample() [2/2]

void tim::component::read_bytes::sample ( const cache_type _cache)
inline

sample a measurement from cached data

Definition at line 639 of file components.hpp.

640 {
641 std::get<0>(accum) = std::get<0>(value) =
642 std::max<int64_t>(std::get<0>(value), _cache.get_bytes_read());
643 }

◆ start() [1/2]

void tim::component::read_bytes::start ( )
inline

Definition at line 576 of file components.hpp.

576{ value = record(); }
static value_type record()
Definition: components.hpp:513

References record().

◆ start() [2/2]

void tim::component::read_bytes::start ( const cache_type _cache)
inline

start a measurement using the cached data

Definition at line 652 of file components.hpp.

652{ value = record(_cache); }

References record().

◆ stop() [1/2]

void tim::component::read_bytes::stop ( )
inline

Definition at line 578 of file components.hpp.

579 {
580 using namespace tim::component::operators;
581 auto diff = (record() - value);
582 std::get<0>(diff) = std::abs(std::get<0>(diff));
583 accum += (value = diff);
584 }
type_list abs(type_list<>)
Definition: fwd.hpp:405

References tim::math::abs, and record().

◆ stop() [2/2]

void tim::component::read_bytes::stop ( const cache_type _cache)
inline

stop a measurement using the cached data

Definition at line 655 of file components.hpp.

656 {
657 using namespace tim::component::operators;
658 auto diff = (record(_cache) - value);
659 std::get<0>(diff) = std::abs(std::get<0>(diff));
660 accum += (value = diff);
661 }

References tim::math::abs, and record().

◆ unit()

static std::pair< double, double > tim::component::read_bytes::unit ( )
inlinestatic

Definition at line 481 of file components.hpp.

482 {
483 return std::pair<double, double>{
484 units::megabyte, static_cast<double>(units::megabyte) / units::sec
485 };
486 }

Referenced by get_unit(), and unit_array().

◆ unit_array()

static std::pair< double, double > tim::component::read_bytes::unit_array ( )
inlinestatic

Definition at line 504 of file components.hpp.

504{ return unit(); }

References unit().


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