add missing session stats functions to python bindings

This commit is contained in:
arvidn 2016-12-22 21:43:05 -05:00 committed by Arvid Norberg
parent ad7e796d05
commit 820fd29bff
3 changed files with 43 additions and 6 deletions

View File

@ -6,6 +6,7 @@
#include "libtorrent/address.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/session_stats.hpp"
using namespace boost::python;
namespace bp = boost::python;
@ -66,6 +67,20 @@ struct tuple_to_pair
}
};
template<class T>
struct vector_to_list
{
static PyObject* convert(const std::vector<T>& v)
{
list l;
for (int i = 0; i < int(v.size()); ++i)
{
l.append(v[i]);
}
return incref(l.ptr());
}
};
void bind_converters()
{
namespace lt = libtorrent;
@ -74,4 +89,6 @@ void bind_converters()
to_python_converter<lt::udp::endpoint, endpoint_to_tuple<lt::udp::endpoint> >();
to_python_converter<lt::address, address_to_tuple>();
tuple_to_pair<int, int>();
to_python_converter<std::vector<lt::stats_metric>, vector_to_list<lt::stats_metric>>();
}

View File

@ -17,6 +17,7 @@
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/kademlia/item.hpp> // for sign_mutable_item
#include <libtorrent/time.hpp>
#include <libtorrent/session_stats.hpp>
#ifndef TORRENT_NO_DEPRECATE
#include <libtorrent/extensions/lt_trackers.hpp>
@ -952,12 +953,6 @@ void bind_session()
.def("set_settings", &set_feed_settings)
.def("settings", &get_feed_settings)
;
#endif
typedef void (*mem_preset2)(settings_pack& s);
typedef void (*perf_preset2)(settings_pack& s);
#ifndef TORRENT_NO_DEPRECATE
typedef session_settings (*mem_preset1)();
typedef session_settings (*perf_preset1)();
@ -967,9 +962,21 @@ void bind_session()
scope().attr("create_metadata_plugin") = "metadata_transfer";
#endif
typedef void (*mem_preset2)(settings_pack& s);
typedef void (*perf_preset2)(settings_pack& s);
def("high_performance_seed", (perf_preset2)high_performance_seed);
def("min_memory_usage", (mem_preset2)min_memory_usage);
class_<stats_metric>("stats_metric")
.def_readonly("name", &stats_metric::name)
.def_readonly("value_index", &stats_metric::value_index)
.def_readonly("type", &stats_metric::type)
;
def("session_stats_metrics", session_stats_metrics);
def("find_metric_idx", find_metric_idx);
scope().attr("create_ut_metadata_plugin") = "ut_metadata";
scope().attr("create_ut_pex_plugin") = "ut_pex";
scope().attr("create_smart_ban_plugin") = "smart_ban";

View File

@ -22,6 +22,19 @@ class test_create_torrent(unittest.TestCase):
print(entry)
self.assertEqual(content, file_content)
class test_session_stats(unittest.TestCase):
def test_unique(self):
l = lt.session_stats_metrics()
self.assertTrue(len(l) > 40);
idx = set()
for m in l:
self.assertTrue(m.value_index not in idx)
idx.add(m.value_index)
def test_find_idx(self):
self.assertEqual(lt.find_metric_idx("peer.error_peers"), 0)
class test_torrent_handle(unittest.TestCase):
def test_torrent_handle(self):