feisty meow concerns codebase 2.140
throughput_counter.cpp
Go to the documentation of this file.
1
2
3
4/*****************************************************************************\
5* *
6* Name : throughput_counter *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2000-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include "throughput_counter.h"
19
20#include <basis/functions.h>
21
22using namespace basis;
23using namespace timely;
24
25namespace sockets {
26
28: _running(false),
29 _start(new time_stamp),
30 _end(new time_stamp),
31 _time_overall(0),
32 _byte_count(0),
33 _send_count(0)
34{}
35
37: _start(new time_stamp),
38 _end(new time_stamp)
39{
40 *this = to_copy;
41}
42
44{
45 _running = false;
46 WHACK(_start);
47 WHACK(_end);
48}
49
50throughput_counter &throughput_counter::operator =
51 (const throughput_counter &to_copy)
52{
53 if (this == &to_copy) return *this; // bail on copying to self.
54 _running = to_copy._running;
55 *_start = *to_copy._start;
56 *_end = *to_copy._end;
57 _time_overall = to_copy._time_overall;
58 _byte_count = to_copy._byte_count;
59 _send_count = to_copy._send_count;
60 return *this;
61}
62
64{
65 if (this == &to_blend) return; // no, we don't like that.
66 _time_overall += to_blend._time_overall;
67 _byte_count += to_blend._byte_count;
68 _send_count += to_blend._send_count;
69}
70
72{
73 if (running()) return; // can't start if already started.
74 *_start = time_stamp();
75 *_end = time_stamp(); // just to clear.
76 _running = true;
77}
78
80{
81 if (!running()) return; // better have been started before stopping.
82 *_end = time_stamp();
83 _time_overall += _end->value() - _start->value();
84 _running = false;
85}
86
88{
89 _running = false;
90 _start->reset();
91 _end->reset();
92 _time_overall = 0;
93 _byte_count = 0;
94 _send_count = 0;
95}
96
97void throughput_counter::send(double size_of_send)
98{
99 if (!running()) return; // can't add if we're not in a run.
100 _send_count++;
101 _byte_count += size_of_send;
102}
103
104void throughput_counter::add_run(double size_of_send, double time_of_send,
105 double number_of_runs)
106{
107 _send_count += number_of_runs;
108 _byte_count += size_of_send;
109 _time_overall += time_of_send;
110}
111
113
115
117{
118 double extra_time = running()? time_stamp().value() - _start->value() : 0;
119 return _time_overall + extra_time;
120}
121
123{
124 double total = total_time() / SECOND_ms;
125 return double(bytes_sent()) / total;
126}
127
130
133
134} //namespace.
135
Reports on average bandwidth of the transfers being measured.
double kilobytes_per_second() const
returns the number of kilobytes that transfers are getting per second.
double bytes_sent() const
returns the number of bytes sent so far.
void reset()
clears all statistics and starts over.
void stop()
ends the current run.
double total_time() const
the run time so far, in milliseconds.
bool running() const
returns whether a test run is being worked on or not.
void send(double size_of_send)
records a sending of "size_of_send" bytes.
double bytes_per_second() const
returns the number of bytes that transfers are getting per second.
timely::time_stamp stop_time() const
reports the time when this run was stopped.
timely::time_stamp start_time() const
reports the time when this run started.
double megabytes_per_second() const
returns the number of megabytes that transfers are getting per second.
void start()
begins timing a run.
void combine(const throughput_counter &to_blend)
incorporates the statistics from "to_blend" into this counter.
void add_run(double size_of_send, double time_of_send, double number_of_runs=1.0)
records a run without changing the state of the current run.
Represents a point in time relative to the operating system startup time.
Definition time_stamp.h:38
void reset()
sets the stamp time back to now.
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition time_stamp.h:61
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition functions.h:121
const int SECOND_ms
Number of milliseconds in a second.
const int KILOBYTE
Number of bytes in a kilobyte.
Provides access to the operating system's socket methods.
#include <time.h>