forked from premiere/premiere-libtorrent
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();
|
||||
dict d;
|
||||
auto counters = alert.counters();
|
||||
|
||||
for (std::vector<stats_metric>::const_iterator i = map.begin();
|
||||
i != map.end(); ++i)
|
||||
for (stats_metric const& m : map)
|
||||
{
|
||||
d[i->name] = alert.values[i->value_index];
|
||||
d[m.name] = counters[m.value_index];
|
||||
}
|
||||
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))
|
||||
{
|
||||
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());
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <algorithm> // for std::max
|
||||
|
||||
using libtorrent::span;
|
||||
|
||||
session_view::session_view()
|
||||
: m_position(0)
|
||||
, m_print_utp_stats(false)
|
||||
|
@ -190,8 +192,8 @@ void session_view::render()
|
|||
}
|
||||
}
|
||||
|
||||
void session_view::update_counters(std::int64_t const* stats_counters
|
||||
, int num_cnt, std::uint64_t t)
|
||||
void session_view::update_counters(span<std::int64_t const> stats_counters
|
||||
, std::uint64_t const t)
|
||||
{
|
||||
// only update the previous counters if there's been enough
|
||||
// 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_cnt[0].assign(stats_counters, stats_counters + num_cnt);
|
||||
m_cnt[0].assign(stats_counters.begin(), stats_counters.end());
|
||||
m_timestamp[0] = t;
|
||||
render();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <vector>
|
||||
|
||||
#include "libtorrent/session_stats.hpp"
|
||||
#include "libtorrent/span.hpp"
|
||||
|
||||
struct session_view
|
||||
{
|
||||
|
@ -53,8 +54,7 @@ struct session_view
|
|||
void print_utp_stats(bool p) { m_print_utp_stats = p; }
|
||||
bool print_utp_stats() const { return m_print_utp_stats; }
|
||||
|
||||
void update_counters(std::int64_t const* stats_counters, int num_cnt
|
||||
, std::uint64_t t);
|
||||
void update_counters(lt::span<std::int64_t const> stats_counters, std::uint64_t t);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -1888,7 +1888,19 @@ namespace libtorrent {
|
|||
struct TORRENT_EXPORT session_stats_alert final : alert
|
||||
{
|
||||
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)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static const int static_category = alert::stats_notification;
|
||||
virtual std::string message() const override;
|
||||
|
@ -1902,7 +1914,15 @@ namespace libtorrent {
|
|||
// interpret these values throughout the process' runtime.
|
||||
//
|
||||
// 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;
|
||||
#else
|
||||
std::array<std::int64_t, counters::num_counters> const TORRENT_DEPRECATED_MEMBER values;
|
||||
#endif
|
||||
};
|
||||
|
||||
#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))
|
||||
{}
|
||||
|
||||
|
@ -1759,6 +1759,11 @@ namespace {
|
|||
return ret;
|
||||
}
|
||||
|
||||
span<std::int64_t const> session_stats_alert::counters() const
|
||||
{
|
||||
return values;
|
||||
}
|
||||
|
||||
dht_stats_alert::dht_stats_alert(aux::stack_allocator&
|
||||
, std::vector<dht_routing_bucket> table
|
||||
, 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();
|
||||
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;
|
||||
}
|
||||
namespace {
|
||||
|
|
Loading…
Reference in New Issue