separate out session_stats into its own header. silences warning and cleans up

This commit is contained in:
Arvid Norberg 2015-04-25 02:12:02 +00:00
parent 8e08cd7639
commit f7e4f83469
7 changed files with 96 additions and 58 deletions

View File

@ -107,6 +107,7 @@ nobase_include_HEADERS = \
rss.hpp \
session.hpp \
session_settings.hpp \
session_stats.hpp \
session_status.hpp \
settings_pack.hpp \
sha1.hpp \

View File

@ -35,6 +35,16 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/config.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/disk_buffer_holder.hpp"
#ifndef TORRENT_DISABLE_DHT
#include "libtorrent/socket.hpp"
#endif
#include "libtorrent/socket.hpp" // for tcp::endpoint
#include "libtorrent/aux_/disable_warnings_push.hpp"
@ -51,16 +61,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/aux_/disable_warnings_pop.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/disk_buffer_holder.hpp"
#ifndef TORRENT_DISABLE_DHT
#include "libtorrent/socket.hpp"
#endif
#include "libtorrent/socket.hpp" // for tcp::endpoint
namespace libtorrent
{
class peer_connection;
@ -102,6 +102,8 @@ namespace libtorrent
namespace libtorrent { namespace aux
{
struct session_settings;
#if !defined TORRENT_DISABLE_LOGGING || TORRENT_USE_ASSERTS
// This is the basic logging and debug interface offered by the session.
// a release build with logging disabled (which is the default) will

View File

@ -86,16 +86,6 @@ namespace libtorrent
struct session_status;
#endif
// describes one statistics metric from the session. For more information,
// see the session-statistics_ section.
struct TORRENT_EXPORT stats_metric
{
char const* name;
int value_index;
enum { type_counter, type_gauge };
int type;
};
typedef boost::function<void(sha1_hash const&, std::vector<char>&
, error_code&)> user_load_function_t;
@ -136,12 +126,6 @@ namespace libtorrent
#error TORRENT_CFG is not defined!
#endif
// given a name of a metric, this function returns the counter index of it,
// or -1 if it could not be found. The counter index is the index into the
// values array returned by session_stats_alert.
// TODO: 3 move this declaration into its own header (session_stats.hpp)
TORRENT_EXPORT int find_metric_idx(char const* name);
void TORRENT_EXPORT TORRENT_CFG();
namespace aux
@ -168,13 +152,6 @@ namespace libtorrent
boost::shared_ptr<aux::session_impl> m_impl;
};
// This free function returns the list of available metrics exposed by
// libtorrent's statistics API. Each metric has a name and a *value index*.
// The value index is the index into the array in session_stats_alert where
// this metric's value can be found when the session stats is sampled (by
// calling post_session_stats()).
TORRENT_EXPORT std::vector<stats_metric> session_stats_metrics();
// The session holds all state that spans multiple torrents. Among other
// things it runs the network loop and manages all torrents. Once it's
// created, the session object will spawn the main thread that will do all

View File

@ -0,0 +1,68 @@
/*
Copyright (c) 2012-2015, 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_SESSION_STATS_HPP_INCLUDED
#define TORRENT_SESSION_STATS_HPP_INCLUDED
#include "libtorrent/config.hpp"
#include <vector>
namespace libtorrent
{
// describes one statistics metric from the session. For more information,
// see the session-statistics_ section.
struct TORRENT_EXPORT stats_metric
{
char const* name;
int value_index;
enum { type_counter, type_gauge };
int type;
};
// This free function returns the list of available metrics exposed by
// libtorrent's statistics API. Each metric has a name and a *value index*.
// The value index is the index into the array in session_stats_alert where
// this metric's value can be found when the session stats is sampled (by
// calling post_session_stats()).
TORRENT_EXPORT std::vector<stats_metric> session_stats_metrics();
// given a name of a metric, this function returns the counter index of it,
// or -1 if it could not be found. The counter index is the index into the
// values array returned by session_stats_alert.
TORRENT_EXPORT int find_metric_idx(char const* name);
}
#endif

View File

@ -593,15 +593,6 @@ namespace libtorrent
TORRENT_ASYNC_CALL1(post_torrent_updates, flags);
}
std::vector<stats_metric> session_stats_metrics()
{
std::vector<stats_metric> ret;
// defined in session_stats.cpp
extern void get_stats_metric_map(std::vector<stats_metric>& stats);
get_stats_metric_map(ret);
return ret;
}
void session::post_session_stats()
{
TORRENT_ASYNC_CALL(post_session_stats);

View File

@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/
#include "libtorrent/session.hpp" // for stats_metric
#include "libtorrent/session_stats.hpp" // for stats_metric
#include "libtorrent/aux_/session_interface.hpp" // for stats counter names
#include "libtorrent/performance_counters.hpp" // for counters
#include <boost/bind.hpp>
@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent
{
struct TORRENT_EXPORT stats_metric_impl
struct stats_metric_impl
{
char const* name;
int value_index;
@ -518,10 +518,9 @@ namespace libtorrent
};
#undef METRIC
// TODO: 3 create a header for this file and declare these two functions.
// currently this is externed into session.cpp
void get_stats_metric_map(std::vector<stats_metric>& stats)
std::vector<stats_metric> session_stats_metrics()
{
std::vector<stats_metric> stats;
const int num = sizeof(metrics)/sizeof(metrics[0]);
stats.resize(num);
for (int i = 0; i < num; ++i)
@ -531,6 +530,7 @@ namespace libtorrent
stats[i].type = metrics[i].value_index >= counters::num_stats_counters
? stats_metric::type_gauge : stats_metric::type_counter;
}
return stats;
}
int find_metric_idx(char const* name)

View File

@ -34,21 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
#include <deque>
#include <map>
#include "setup_transfer.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/http_parser.hpp"
#include "libtorrent/thread.hpp"
#include "libtorrent/thread.hpp"
#include <boost/tuple/tuple.hpp>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include "test.hpp"
#include "test_utils.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/alert_types.hpp"
#include "libtorrent/create_torrent.hpp"
@ -56,6 +45,16 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/socket_type.hpp"
#include "libtorrent/instantiate_connection.hpp"
#include "libtorrent/ip_filter.hpp"
#include "libtorrent/session_stats.hpp"
#include "libtorrent/thread.hpp"
#include <boost/tuple/tuple.hpp>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp>
#include "test.hpp"
#include "test_utils.hpp"
#include "setup_transfer.hpp"
#ifdef TORRENT_USE_OPENSSL
#include <boost/asio/ssl/stream.hpp>