1 #ifndef THROUGHPUT_COUNTER_CLASS
2 #define THROUGHPUT_COUNTER_CLASS
4 /*****************************************************************************\
6 * Name : throughput_counter *
7 * Author : Chris Koeritz *
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 \*****************************************************************************/
18 #include <timely/time_stamp.h>
22 //! Reports on average bandwidth of the transfers being measured.
24 Tracks the amount of data sent over a period of time and provides
25 statistics about the transfer rate.
28 class throughput_counter
32 throughput_counter(const throughput_counter &to_copy);
33 ~throughput_counter();
35 throughput_counter &operator =(const throughput_counter &to_copy);
38 //!< begins timing a run.
39 /*!< the current time is recorded and any data sent will be tracked until
40 stop() is invoked. results from previous runs will be merged with the
44 //!< ends the current run.
45 /*!< the report functions provide information about the speed achieved
46 over this and previous runs. */
49 //!< clears all statistics and starts over.
51 void combine(const throughput_counter &to_blend);
52 //!< incorporates the statistics from "to_blend" into this counter.
53 /*!< the stats in "to_blend" then no longer need to be considered,
54 since this object records its own plus the blended statistics. note
55 that makes the most sense if both this and "to_blend" are not currently
56 running a simulation, although combining running counters is not
57 prohibited. if either counter is running, those current runs are
58 ignored and only accumulated stats are combined. */
60 void send(double size_of_send);
61 //!< records a sending of "size_of_send" bytes.
62 /*!< this should only be called while a test run is being made; the send
63 will be ignored if a run is not occurring. */
65 void add_run(double size_of_send, double time_of_send,
66 double number_of_runs = 1.0);
67 //!< records a run without changing the state of the current run.
68 /*!< this supports adding a timed run to the counter without requiring that
69 start and stop be used. this will work whether a run is currently
70 being timed or not. */
72 bool running() const { return _running; }
73 //!< returns whether a test run is being worked on or not.
75 timely::time_stamp start_time() const;
76 //!< reports the time when this run started.
77 /*!< this and stop_time() report the timing information for the current
78 run, and so are only really relevant when a run is occurring. */
79 timely::time_stamp stop_time() const;
80 //!< reports the time when this run was stopped.
82 double bytes_sent() const { return _byte_count; }
83 //!< returns the number of bytes sent so far.
84 /*!< bytes_sent() and number_of_sends() work at any point during a test
85 run to provide an interim measurement. however after a test run, they
86 report the statistics for the entire history of testing. */
87 double number_of_sends() const { return _send_count; }
88 //!< returns the number of sends that have occurred.
90 double bytes_per_second() const;
91 //!< returns the number of bytes that transfers are getting per second.
92 double kilobytes_per_second() const;
93 //!< returns the number of kilobytes that transfers are getting per second.
94 double megabytes_per_second() const;
95 //!< returns the number of megabytes that transfers are getting per second.
97 double total_time() const;
98 //!< the run time so far, in milliseconds.
99 /*!< this also counts the time in the current run, if one is occurring. */
102 bool _running; //!< true if we're currently testing.
103 timely::time_stamp *_start; //!< when the current run was started.
104 timely::time_stamp *_end; //!< when the run was stopped.
105 double _time_overall; //!< how much time has been accumulated.
106 double _byte_count; //!< the amount of data sent so far.
107 double _send_count; //!< the number of times data has been sent.