diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index 4384c64a1..617cd25f4 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -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 \ diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 6a4991d0d..c37be35d9 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -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 diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 63d18c032..f430f983e 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -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& , 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 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 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 diff --git a/include/libtorrent/session_stats.hpp b/include/libtorrent/session_stats.hpp new file mode 100644 index 000000000..6333c0187 --- /dev/null +++ b/include/libtorrent/session_stats.hpp @@ -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 + +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 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 + diff --git a/src/session.cpp b/src/session.cpp index b9f1fe1be..93bd8f2d5 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -593,15 +593,6 @@ namespace libtorrent TORRENT_ASYNC_CALL1(post_torrent_updates, flags); } - std::vector session_stats_metrics() - { - std::vector ret; - // defined in session_stats.cpp - extern void get_stats_metric_map(std::vector& stats); - get_stats_metric_map(ret); - return ret; - } - void session::post_session_stats() { TORRENT_ASYNC_CALL(post_session_stats); diff --git a/src/session_stats.cpp b/src/session_stats.cpp index a67876f35..fbfabfb07 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -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 @@ -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) + std::vector session_stats_metrics() { + std::vector 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) diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 8bd12bb05..f4832ce97 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -34,21 +34,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#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 -#include -#include - -#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 +#include +#include + +#include "test.hpp" +#include "test_utils.hpp" +#include "setup_transfer.hpp" #ifdef TORRENT_USE_OPENSSL #include