deprecate direct access to array in session_stats_alert (#2033)
This commit is contained in:
parent
4cee8104d7
commit
660cdaf2d1
|
@ -123,11 +123,11 @@ dict session_stats_values(session_stats_alert const& alert)
|
||||||
{
|
{
|
||||||
std::vector<stats_metric> map = session_stats_metrics();
|
std::vector<stats_metric> map = session_stats_metrics();
|
||||||
dict d;
|
dict d;
|
||||||
|
auto counters = alert.counters();
|
||||||
|
|
||||||
for (std::vector<stats_metric>::const_iterator i = map.begin();
|
for (stats_metric const& m : map)
|
||||||
i != map.end(); ++i)
|
|
||||||
{
|
{
|
||||||
d[i->name] = alert.values[i->value_index];
|
d[m.name] = counters[m.value_index];
|
||||||
}
|
}
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,7 +764,7 @@ bool handle_alert(torrent_view& view, session_view& ses_view
|
||||||
|
|
||||||
if (session_stats_alert* s = alert_cast<session_stats_alert>(a))
|
if (session_stats_alert* s = alert_cast<session_stats_alert>(a))
|
||||||
{
|
{
|
||||||
ses_view.update_counters(s->values.data(), int(s->values.size())
|
ses_view.update_counters(s->counters()
|
||||||
, duration_cast<microseconds>(s->timestamp().time_since_epoch()).count());
|
, duration_cast<microseconds>(s->timestamp().time_since_epoch()).count());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <algorithm> // for std::max
|
#include <algorithm> // for std::max
|
||||||
|
|
||||||
|
using libtorrent::span;
|
||||||
|
|
||||||
session_view::session_view()
|
session_view::session_view()
|
||||||
: m_position(0)
|
: m_position(0)
|
||||||
, m_print_utp_stats(false)
|
, m_print_utp_stats(false)
|
||||||
|
@ -190,8 +192,8 @@ void session_view::render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_view::update_counters(std::int64_t const* stats_counters
|
void session_view::update_counters(span<std::int64_t const> stats_counters
|
||||||
, int num_cnt, std::uint64_t t)
|
, std::uint64_t const t)
|
||||||
{
|
{
|
||||||
// only update the previous counters if there's been enough
|
// only update the previous counters if there's been enough
|
||||||
// time since it was last updated
|
// time since it was last updated
|
||||||
|
@ -201,7 +203,7 @@ void session_view::update_counters(std::int64_t const* stats_counters
|
||||||
m_timestamp[1] = m_timestamp[0];
|
m_timestamp[1] = m_timestamp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cnt[0].assign(stats_counters, stats_counters + num_cnt);
|
m_cnt[0].assign(stats_counters.begin(), stats_counters.end());
|
||||||
m_timestamp[0] = t;
|
m_timestamp[0] = t;
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "libtorrent/session_stats.hpp"
|
#include "libtorrent/session_stats.hpp"
|
||||||
|
#include "libtorrent/span.hpp"
|
||||||
|
|
||||||
struct session_view
|
struct session_view
|
||||||
{
|
{
|
||||||
|
@ -53,8 +54,7 @@ struct session_view
|
||||||
void print_utp_stats(bool p) { m_print_utp_stats = p; }
|
void print_utp_stats(bool p) { m_print_utp_stats = p; }
|
||||||
bool print_utp_stats() const { return m_print_utp_stats; }
|
bool print_utp_stats() const { return m_print_utp_stats; }
|
||||||
|
|
||||||
void update_counters(std::int64_t const* stats_counters, int num_cnt
|
void update_counters(lt::span<std::int64_t const> stats_counters, std::uint64_t t);
|
||||||
, std::uint64_t t);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -1888,7 +1888,19 @@ namespace libtorrent {
|
||||||
struct TORRENT_EXPORT session_stats_alert final : alert
|
struct TORRENT_EXPORT session_stats_alert final : alert
|
||||||
{
|
{
|
||||||
session_stats_alert(aux::stack_allocator& alloc, counters const& cnt);
|
session_stats_alert(aux::stack_allocator& alloc, counters const& cnt);
|
||||||
|
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
TORRENT_DEFINE_ALERT_PRIO(session_stats_alert, 70)
|
TORRENT_DEFINE_ALERT_PRIO(session_stats_alert, 70)
|
||||||
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static const int static_category = alert::stats_notification;
|
static const int static_category = alert::stats_notification;
|
||||||
virtual std::string message() const override;
|
virtual std::string message() const override;
|
||||||
|
@ -1902,7 +1914,15 @@ namespace libtorrent {
|
||||||
// interpret these values throughout the process' runtime.
|
// interpret these values throughout the process' runtime.
|
||||||
//
|
//
|
||||||
// For more information, see the session-statistics_ section.
|
// For more information, see the session-statistics_ section.
|
||||||
|
span<std::int64_t const> counters() const;
|
||||||
|
|
||||||
|
#ifdef TORRENT_NO_DEPRECATE
|
||||||
|
private:
|
||||||
|
// TODO: allocate this on the alert_stack in the future
|
||||||
std::array<std::int64_t, counters::num_counters> const values;
|
std::array<std::int64_t, counters::num_counters> const values;
|
||||||
|
#else
|
||||||
|
std::array<std::int64_t, counters::num_counters> const TORRENT_DEPRECATED_MEMBER values;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
|
|
@ -1740,7 +1740,7 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
session_stats_alert::session_stats_alert(aux::stack_allocator&, counters const& cnt)
|
session_stats_alert::session_stats_alert(aux::stack_allocator&, struct counters const& cnt)
|
||||||
: values(counters_to_array(cnt))
|
: values(counters_to_array(cnt))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -1759,6 +1759,11 @@ namespace {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span<std::int64_t const> session_stats_alert::counters() const
|
||||||
|
{
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
dht_stats_alert::dht_stats_alert(aux::stack_allocator&
|
dht_stats_alert::dht_stats_alert(aux::stack_allocator&
|
||||||
, std::vector<dht_routing_bucket> table
|
, std::vector<dht_routing_bucket> table
|
||||||
, std::vector<dht_lookup> requests)
|
, std::vector<dht_lookup> requests)
|
||||||
|
|
|
@ -150,7 +150,7 @@ std::map<std::string, std::int64_t> get_counters(lt::session& s)
|
||||||
|
|
||||||
static std::vector<stats_metric> metrics = session_stats_metrics();
|
static std::vector<stats_metric> metrics = session_stats_metrics();
|
||||||
for (auto const& m : metrics)
|
for (auto const& m : metrics)
|
||||||
ret[m.name] = sa->values[static_cast<std::size_t>(m.value_index)];
|
ret[m.name] = sa->counters()[static_cast<std::size_t>(m.value_index)];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
namespace {
|
namespace {
|
||||||
|
|
Loading…
Reference in New Issue