2003-10-23 01:00:57 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright (c) 2003, Arvid Norberg
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TORRENT_STAT_HPP_INCLUDED
|
|
|
|
#define TORRENT_STAT_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2004-01-16 04:58:24 +01:00
|
|
|
#include <assert.h>
|
2008-05-09 00:07:13 +02:00
|
|
|
#include <cstring>
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2004-01-18 02:58:33 +01:00
|
|
|
#include "libtorrent/size_type.hpp"
|
2004-01-25 19:18:36 +01:00
|
|
|
#include "libtorrent/invariant_check.hpp"
|
2005-11-01 19:30:39 +01:00
|
|
|
#include "libtorrent/config.hpp"
|
2007-09-10 08:12:41 +02:00
|
|
|
#include "libtorrent/assert.hpp"
|
2004-01-18 02:58:33 +01:00
|
|
|
|
2010-02-08 05:51:34 +01:00
|
|
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
|
|
|
#include "libtorrent/debug.hpp" // for logger
|
|
|
|
#endif
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
2008-05-04 19:57:06 +02:00
|
|
|
class TORRENT_EXPORT stat_channel
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
2004-01-25 19:18:36 +01:00
|
|
|
friend class invariant_access;
|
2003-10-23 01:00:57 +02:00
|
|
|
public:
|
2010-02-14 02:39:55 +01:00
|
|
|
enum { history = 5 };
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2010-02-08 05:51:34 +01:00
|
|
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
|
|
|
|
|
|
|
#define PRINT_SIZEOF(x) l << "sizeof(" #x "): " << sizeof(x) << "\n";
|
|
|
|
#define PRINT_OFFSETOF(x, y) l << " offsetof(" #x "," #y "): " << offsetof(x, y) << "\n";
|
|
|
|
|
|
|
|
static void print_size(logger& l)
|
|
|
|
{
|
|
|
|
PRINT_SIZEOF(stat_channel)
|
|
|
|
PRINT_OFFSETOF(stat_channel, m_rate_history)
|
|
|
|
PRINT_OFFSETOF(stat_channel, m_window)
|
|
|
|
PRINT_OFFSETOF(stat_channel, m_counter)
|
|
|
|
PRINT_OFFSETOF(stat_channel, m_total_counter)
|
|
|
|
PRINT_OFFSETOF(stat_channel, m_rate_sum)
|
|
|
|
}
|
|
|
|
#undef PRINT_SIZEOF
|
|
|
|
#undef PRINT_OFFSETOF
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
stat_channel()
|
2010-01-02 15:16:35 +01:00
|
|
|
: m_window(3)
|
|
|
|
, m_counter(0)
|
2008-05-04 19:57:06 +02:00
|
|
|
, m_total_counter(0)
|
|
|
|
, m_rate_sum(0)
|
2003-10-23 01:00:57 +02:00
|
|
|
{
|
2008-05-06 18:35:15 +02:00
|
|
|
std::memset(m_rate_history, 0, sizeof(m_rate_history));
|
2003-10-23 01:00:57 +02:00
|
|
|
}
|
|
|
|
|
2010-01-02 15:16:35 +01:00
|
|
|
void set_window(int w);
|
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
void operator+=(stat_channel const& s)
|
|
|
|
{
|
2009-07-27 01:36:55 +02:00
|
|
|
TORRENT_ASSERT(m_counter >= 0);
|
|
|
|
TORRENT_ASSERT(m_total_counter >= 0);
|
|
|
|
TORRENT_ASSERT(s.m_counter >= 0);
|
2008-05-04 19:57:06 +02:00
|
|
|
m_counter += s.m_counter;
|
|
|
|
m_total_counter += s.m_counter;
|
2009-07-27 01:36:55 +02:00
|
|
|
TORRENT_ASSERT(m_counter >= 0);
|
|
|
|
TORRENT_ASSERT(m_total_counter >= 0);
|
2008-05-04 19:57:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void add(int count)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(count >= 0);
|
|
|
|
|
|
|
|
m_counter += count;
|
2009-07-27 01:36:55 +02:00
|
|
|
TORRENT_ASSERT(m_counter >= 0);
|
2008-05-04 19:57:06 +02:00
|
|
|
m_total_counter += count;
|
2009-07-27 01:36:55 +02:00
|
|
|
TORRENT_ASSERT(m_total_counter >= 0);
|
2008-05-04 19:57:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// should be called once every second
|
2009-07-19 06:59:27 +02:00
|
|
|
void second_tick(int tick_interval_ms);
|
2010-01-02 15:16:35 +01:00
|
|
|
int rate() const { return int(m_rate_sum / m_window); }
|
2008-05-06 18:35:15 +02:00
|
|
|
size_type rate_sum() const { return m_rate_sum; }
|
2008-05-04 19:57:06 +02:00
|
|
|
size_type total() const { return m_total_counter; }
|
|
|
|
|
2010-03-06 08:16:39 +01:00
|
|
|
void offset(size_type c)
|
2008-05-04 19:57:06 +02:00
|
|
|
{
|
2010-03-06 08:16:39 +01:00
|
|
|
TORRENT_ASSERT(c >= 0);
|
2009-07-27 01:36:55 +02:00
|
|
|
TORRENT_ASSERT(m_total_counter >= 0);
|
2010-03-06 08:16:39 +01:00
|
|
|
m_total_counter += c;
|
2009-07-27 01:36:55 +02:00
|
|
|
TORRENT_ASSERT(m_total_counter >= 0);
|
2008-05-04 19:57:06 +02:00
|
|
|
}
|
|
|
|
|
2009-10-26 03:26:15 +01:00
|
|
|
int counter() const { return m_counter; }
|
2008-05-04 19:57:06 +02:00
|
|
|
|
2008-10-15 19:31:20 +02:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
std::memset(m_rate_history, 0, sizeof(m_rate_history));
|
|
|
|
m_counter = 0;
|
|
|
|
m_total_counter = 0;
|
|
|
|
m_rate_sum = 0;
|
|
|
|
}
|
|
|
|
|
2010-01-02 15:16:35 +01:00
|
|
|
int window() const { return m_window; }
|
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
private:
|
|
|
|
|
2008-11-29 22:33:21 +01:00
|
|
|
#ifdef TORRENT_DEBUG
|
2008-05-04 19:57:06 +02:00
|
|
|
void check_invariant() const
|
|
|
|
{
|
2009-07-27 01:36:55 +02:00
|
|
|
size_type sum = 0;
|
2010-01-02 15:16:35 +01:00
|
|
|
for (int i = 0; i < m_window; ++i) sum += m_rate_history[i];
|
2008-05-06 18:35:15 +02:00
|
|
|
TORRENT_ASSERT(m_rate_sum == sum);
|
2008-05-04 19:57:06 +02:00
|
|
|
TORRENT_ASSERT(m_total_counter >= 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// history of rates a few seconds back
|
2008-05-06 18:35:15 +02:00
|
|
|
int m_rate_history[history];
|
2008-05-04 19:57:06 +02:00
|
|
|
|
2010-01-02 15:16:35 +01:00
|
|
|
// averaging window (seconds). 'history' is the max size
|
|
|
|
int m_window;
|
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
// the accumulator for this second.
|
|
|
|
int m_counter;
|
|
|
|
|
|
|
|
// total counters
|
|
|
|
size_type m_total_counter;
|
|
|
|
|
|
|
|
// sum of all elements in m_rate_history
|
2008-05-06 18:35:15 +02:00
|
|
|
size_type m_rate_sum;
|
2008-05-04 19:57:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class TORRENT_EXPORT stat
|
|
|
|
{
|
|
|
|
friend class invariant_access;
|
|
|
|
public:
|
2003-12-07 06:53:04 +01:00
|
|
|
void operator+=(const stat& s)
|
|
|
|
{
|
2008-05-04 19:57:06 +02:00
|
|
|
for (int i = 0; i < num_channels; ++i)
|
|
|
|
m_stat[i] += s.m_stat[i];
|
2003-12-07 06:53:04 +01:00
|
|
|
}
|
|
|
|
|
2008-11-14 21:51:49 +01:00
|
|
|
void sent_syn(bool ipv6)
|
2008-09-26 08:10:21 +02:00
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-11-14 21:51:49 +01:00
|
|
|
m_stat[upload_ip_protocol].add(ipv6 ? 60 : 40);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-09-26 08:10:21 +02:00
|
|
|
}
|
|
|
|
|
2008-11-14 21:51:49 +01:00
|
|
|
void received_synack(bool ipv6)
|
2008-09-26 08:10:21 +02:00
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-26 08:10:21 +02:00
|
|
|
// we received SYN-ACK and also sent ACK back
|
2008-11-14 21:51:49 +01:00
|
|
|
m_stat[download_ip_protocol].add(ipv6 ? 60 : 40);
|
|
|
|
m_stat[upload_ip_protocol].add(ipv6 ? 60 : 40);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-09-26 08:10:21 +02:00
|
|
|
}
|
|
|
|
|
2008-09-20 19:42:25 +02:00
|
|
|
void received_dht_bytes(int bytes)
|
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-20 19:42:25 +02:00
|
|
|
TORRENT_ASSERT(bytes >= 0);
|
|
|
|
m_stat[download_dht_protocol].add(bytes);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-09-20 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sent_dht_bytes(int bytes)
|
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-20 19:42:25 +02:00
|
|
|
TORRENT_ASSERT(bytes >= 0);
|
|
|
|
m_stat[upload_dht_protocol].add(bytes);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-09-22 02:15:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void received_tracker_bytes(int bytes)
|
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-22 02:15:05 +02:00
|
|
|
TORRENT_ASSERT(bytes >= 0);
|
|
|
|
m_stat[download_tracker_protocol].add(bytes);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-09-22 02:15:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sent_tracker_bytes(int bytes)
|
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-22 02:15:05 +02:00
|
|
|
TORRENT_ASSERT(bytes >= 0);
|
|
|
|
m_stat[upload_tracker_protocol].add(bytes);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-09-20 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
2003-12-07 06:53:04 +01:00
|
|
|
void received_bytes(int bytes_payload, int bytes_protocol)
|
|
|
|
{
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(bytes_payload >= 0);
|
|
|
|
TORRENT_ASSERT(bytes_protocol >= 0);
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
m_stat[download_payload].add(bytes_payload);
|
|
|
|
m_stat[download_protocol].add(bytes_protocol);
|
2003-12-07 06:53:04 +01:00
|
|
|
}
|
2004-01-16 04:58:24 +01:00
|
|
|
|
2003-12-07 06:53:04 +01:00
|
|
|
void sent_bytes(int bytes_payload, int bytes_protocol)
|
|
|
|
{
|
2007-10-05 02:30:00 +02:00
|
|
|
TORRENT_ASSERT(bytes_payload >= 0);
|
|
|
|
TORRENT_ASSERT(bytes_protocol >= 0);
|
2004-01-25 19:18:36 +01:00
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
m_stat[upload_payload].add(bytes_payload);
|
|
|
|
m_stat[upload_protocol].add(bytes_protocol);
|
2003-12-07 06:53:04 +01:00
|
|
|
}
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2008-11-14 21:51:49 +01:00
|
|
|
// and IP packet was received or sent
|
|
|
|
// account for the overhead caused by it
|
|
|
|
void trancieve_ip_packet(int bytes_transferred, bool ipv6)
|
2008-05-05 19:08:14 +02:00
|
|
|
{
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-11-14 21:51:49 +01:00
|
|
|
// one TCP/IP packet header for the packet
|
|
|
|
// sent or received, and one for the ACK
|
|
|
|
// The IPv4 header is 20 bytes
|
|
|
|
// and IPv6 header is 40 bytes
|
|
|
|
const int header = (ipv6 ? 40 : 20) + 20;
|
|
|
|
const int mtu = 1500;
|
2008-12-10 23:54:49 +01:00
|
|
|
const int packet_size = mtu - header;
|
|
|
|
const int overhead = (std::max)(1, (bytes_transferred + packet_size - 1) / packet_size) * header;
|
2008-11-14 21:51:49 +01:00
|
|
|
m_stat[download_ip_protocol].add(overhead);
|
|
|
|
m_stat[upload_ip_protocol].add(overhead);
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-05-05 19:08:14 +02:00
|
|
|
}
|
|
|
|
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-05-05 19:08:14 +02:00
|
|
|
int upload_ip_overhead() const { return m_stat[upload_ip_protocol].counter(); }
|
|
|
|
int download_ip_overhead() const { return m_stat[download_ip_protocol].counter(); }
|
2008-09-20 19:42:25 +02:00
|
|
|
int upload_dht() const { return m_stat[upload_dht_protocol].counter(); }
|
|
|
|
int download_dht() const { return m_stat[download_dht_protocol].counter(); }
|
2008-09-22 02:15:05 +02:00
|
|
|
int download_tracker() const { return m_stat[download_tracker_protocol].counter(); }
|
|
|
|
int upload_tracker() const { return m_stat[upload_tracker_protocol].counter(); }
|
2010-02-08 06:43:54 +01:00
|
|
|
#else
|
|
|
|
int upload_ip_overhead() const { return 0; }
|
|
|
|
int download_ip_overhead() const { return 0; }
|
|
|
|
int upload_dht() const { return 0; }
|
|
|
|
int download_dht() const { return 0; }
|
|
|
|
int download_tracker() const { return 0; }
|
|
|
|
int upload_tracker() const { return 0; }
|
|
|
|
#endif
|
2008-05-05 19:08:14 +02:00
|
|
|
|
2010-01-02 15:16:35 +01:00
|
|
|
void set_window(int w)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num_channels; ++i)
|
|
|
|
m_stat[i].set_window(w);
|
|
|
|
}
|
|
|
|
|
2003-10-23 01:00:57 +02:00
|
|
|
// should be called once every second
|
2009-07-19 06:59:27 +02:00
|
|
|
void second_tick(int tick_interval_ms)
|
2008-05-04 19:57:06 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < num_channels; ++i)
|
2009-07-19 06:59:27 +02:00
|
|
|
m_stat[i].second_tick(tick_interval_ms);
|
2008-05-04 19:57:06 +02:00
|
|
|
}
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2009-07-19 06:59:27 +02:00
|
|
|
int upload_rate() const
|
2008-05-04 19:57:06 +02:00
|
|
|
{
|
2009-10-26 03:26:15 +01:00
|
|
|
return int((m_stat[upload_payload].rate_sum()
|
2008-05-06 18:35:15 +02:00
|
|
|
+ m_stat[upload_protocol].rate_sum()
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-20 19:42:25 +02:00
|
|
|
+ m_stat[upload_ip_protocol].rate_sum()
|
2010-02-08 06:43:54 +01:00
|
|
|
+ m_stat[upload_dht_protocol].rate_sum()
|
|
|
|
#endif
|
|
|
|
)
|
2010-01-02 15:16:35 +01:00
|
|
|
/ m_stat[0].window());
|
2008-05-04 19:57:06 +02:00
|
|
|
}
|
|
|
|
|
2009-07-19 06:59:27 +02:00
|
|
|
int download_rate() const
|
2008-05-04 19:57:06 +02:00
|
|
|
{
|
2009-10-26 03:26:15 +01:00
|
|
|
return int((m_stat[download_payload].rate_sum()
|
2008-05-06 18:35:15 +02:00
|
|
|
+ m_stat[download_protocol].rate_sum()
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-20 19:42:25 +02:00
|
|
|
+ m_stat[download_ip_protocol].rate_sum()
|
2010-02-08 06:43:54 +01:00
|
|
|
+ m_stat[download_dht_protocol].rate_sum()
|
|
|
|
#endif
|
|
|
|
)
|
2010-01-02 15:16:35 +01:00
|
|
|
/ m_stat[0].window());
|
2008-05-04 19:57:06 +02:00
|
|
|
}
|
|
|
|
|
2008-09-20 19:42:25 +02:00
|
|
|
size_type total_upload() const
|
|
|
|
{
|
|
|
|
return m_stat[upload_payload].total()
|
|
|
|
+ m_stat[upload_protocol].total()
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-20 19:42:25 +02:00
|
|
|
+ m_stat[upload_ip_protocol].total()
|
2008-09-22 02:15:05 +02:00
|
|
|
+ m_stat[upload_dht_protocol].total()
|
2010-02-08 06:43:54 +01:00
|
|
|
+ m_stat[upload_tracker_protocol].total()
|
|
|
|
#endif
|
|
|
|
;
|
2008-09-20 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
size_type total_download() const
|
|
|
|
{
|
|
|
|
return m_stat[download_payload].total()
|
|
|
|
+ m_stat[download_protocol].total()
|
2010-02-08 06:43:54 +01:00
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-09-20 19:42:25 +02:00
|
|
|
+ m_stat[download_ip_protocol].total()
|
2008-09-22 02:15:05 +02:00
|
|
|
+ m_stat[download_dht_protocol].total()
|
2010-02-08 06:43:54 +01:00
|
|
|
+ m_stat[download_tracker_protocol].total()
|
|
|
|
#endif
|
|
|
|
;
|
2008-09-20 19:42:25 +02:00
|
|
|
}
|
|
|
|
|
2009-07-19 06:59:27 +02:00
|
|
|
int upload_payload_rate() const
|
2008-05-04 19:57:06 +02:00
|
|
|
{ return m_stat[upload_payload].rate(); }
|
2009-07-19 06:59:27 +02:00
|
|
|
int download_payload_rate() const
|
2008-05-04 19:57:06 +02:00
|
|
|
{ return m_stat[download_payload].rate(); }
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
size_type total_payload_upload() const
|
|
|
|
{ return m_stat[upload_payload].total(); }
|
|
|
|
size_type total_payload_download() const
|
|
|
|
{ return m_stat[download_payload].total(); }
|
2003-12-22 08:14:35 +01:00
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
size_type total_protocol_upload() const
|
|
|
|
{ return m_stat[upload_protocol].total(); }
|
|
|
|
size_type total_protocol_download() const
|
|
|
|
{ return m_stat[download_protocol].total(); }
|
2003-10-23 01:00:57 +02:00
|
|
|
|
2008-09-20 19:42:25 +02:00
|
|
|
size_type total_transfer(int channel) const
|
|
|
|
{ return m_stat[channel].total(); }
|
2009-07-19 06:59:27 +02:00
|
|
|
int transfer_rate(int channel) const
|
2008-09-20 19:42:25 +02:00
|
|
|
{ return m_stat[channel].rate(); }
|
|
|
|
|
2004-02-26 01:27:06 +01:00
|
|
|
// this is used to offset the statistics when a
|
|
|
|
// peer_connection is opened and have some previous
|
|
|
|
// transfers from earlier connections.
|
2004-02-25 00:55:42 +01:00
|
|
|
void add_stat(size_type downloaded, size_type uploaded)
|
|
|
|
{
|
2008-05-04 19:57:06 +02:00
|
|
|
m_stat[download_payload].offset(downloaded);
|
|
|
|
m_stat[upload_payload].offset(uploaded);
|
2004-02-25 00:55:42 +01:00
|
|
|
}
|
|
|
|
|
2009-10-26 03:26:15 +01:00
|
|
|
int last_payload_downloaded() const
|
2008-05-04 19:57:06 +02:00
|
|
|
{ return m_stat[download_payload].counter(); }
|
2009-10-26 03:26:15 +01:00
|
|
|
int last_payload_uploaded() const
|
2008-05-04 19:57:06 +02:00
|
|
|
{ return m_stat[upload_payload].counter(); }
|
2009-10-26 03:26:15 +01:00
|
|
|
int last_protocol_downloaded() const
|
2008-09-21 19:12:26 +02:00
|
|
|
{ return m_stat[download_protocol].counter(); }
|
2009-10-26 03:26:15 +01:00
|
|
|
int last_protocol_uploaded() const
|
2008-09-21 19:12:26 +02:00
|
|
|
{ return m_stat[upload_protocol].counter(); }
|
2008-04-16 08:31:05 +02:00
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
// these are the channels we keep stats for
|
|
|
|
enum
|
2004-01-25 13:37:15 +01:00
|
|
|
{
|
2008-05-04 19:57:06 +02:00
|
|
|
upload_payload,
|
|
|
|
upload_protocol,
|
2010-02-08 06:43:54 +01:00
|
|
|
download_payload,
|
|
|
|
download_protocol,
|
|
|
|
#ifndef TORRENT_DISABLE_FULL_STATS
|
2008-05-05 19:08:14 +02:00
|
|
|
upload_ip_protocol,
|
2008-09-20 19:42:25 +02:00
|
|
|
upload_dht_protocol,
|
2008-09-22 02:15:05 +02:00
|
|
|
upload_tracker_protocol,
|
2008-05-05 19:08:14 +02:00
|
|
|
download_ip_protocol,
|
2008-09-20 19:42:25 +02:00
|
|
|
download_dht_protocol,
|
2008-09-22 02:15:05 +02:00
|
|
|
download_tracker_protocol,
|
2010-02-08 06:43:54 +01:00
|
|
|
#endif
|
2008-05-04 19:57:06 +02:00
|
|
|
num_channels
|
|
|
|
};
|
|
|
|
|
2008-10-15 19:31:20 +02:00
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < num_channels; ++i)
|
|
|
|
m_stat[i].clear();
|
|
|
|
}
|
|
|
|
|
2010-01-02 15:16:35 +01:00
|
|
|
stat_channel const& operator[](int i) const
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(i >= 0 && i < num_channels);
|
|
|
|
return m_stat[i];
|
|
|
|
}
|
|
|
|
|
2008-09-20 19:42:25 +02:00
|
|
|
private:
|
|
|
|
|
2008-05-04 19:57:06 +02:00
|
|
|
stat_channel m_stat[num_channels];
|
2003-10-23 01:00:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // TORRENT_STAT_HPP_INCLUDED
|
2008-05-04 19:57:06 +02:00
|
|
|
|