scclib
Stable Cloud Computing C++ Library
Public Member Functions | List of all members
scc::util::ReadTimer Class Reference

Adds timer to a read stream. More...

#include <rwtimer.h>

Inheritance diagram for scc::util::ReadTimer:
Inheritance graph
[legend]
Collaboration diagram for scc::util::ReadTimer:
Collaboration graph
[legend]

Public Member Functions

 ReadTimer ()
 Reads return 0 until reset. More...
 
 ReadTimer (Reader &)
 Chain using a reference. More...
 
 ReadTimer (const std::shared_ptr< Reader > &)
 Chain using a shared pointer.
 
void read_reset (Reader &)
 Reset the chained reader.
 
virtual void read_reset (const std::shared_ptr< Reader > &)
 Reset the chained reader.
 
virtual std::shared_ptr< Readerread_shared () const
 
virtual size_t read (void *, size_t)
 Read and update time over underlying read.
 
std::chrono::nanoseconds read_dur () const
 
void read_dur (std::chrono::nanoseconds v)
 
void read_dur_reset ()
 
uint64_t read_calls () const
 
void read_calls_reset ()
 

Detailed Description

Adds timer to a read stream.

Example from scclib/util/unittest/iohelper.cc

using std::chrono::milliseconds;
using std::chrono::duration_cast;
struct Slow : public Reader, public Writer
{
Slow() {}
virtual ~Slow() {}
size_t read(void*, size_t l)
{
std::this_thread::sleep_for(milliseconds(50));
return l;
}
size_t write(const void*, size_t l)
{
std::this_thread::sleep_for(milliseconds(100));
return l;
}
};
Slow base;
RwCounter c(base, base);
RwTimer t(c, c);
t.read(0, 50);
t.write(0, 100);
cout << "read timer=" << t.read_dur().count() << endl;
cout << "write timer=" << t.write_dur().count() << endl;
cout << "read count=" << c.read_count() << endl;
cout << "write count=" << c.write_count() << endl;
ASSERT_EQ(duration_cast<milliseconds>(t.read_dur()).count(), 50);
ASSERT_EQ(duration_cast<milliseconds>(t.write_dur()).count(), 100);
ASSERT_EQ(c.read_count(), 50);
ASSERT_EQ(c.write_count(), 100);
virtual size_t read(void *, size_t)
Read and update time over underlying read.
Definition: iostream.cc:714

Definition at line 60 of file rwtimer.h.

Constructor & Destructor Documentation

◆ ReadTimer() [1/2]

ReadTimer::ReadTimer ( )

Reads return 0 until reset.

timers

Definition at line 700 of file iostream.cc.

◆ ReadTimer() [2/2]

ReadTimer::ReadTimer ( Reader r)

Chain using a reference.

Does not assume ownership.

Definition at line 704 of file iostream.cc.


The documentation for this class was generated from the following files: