using aux::array in metrics array and aux::vector in session_stats_metrics (#1793)

using aux::array in metrics array and aux::vector in session_stats_metrics
This commit is contained in:
Alden Torres 2017-03-09 20:34:52 -05:00 committed by Arvid Norberg
parent a404673147
commit 6e9c54e69b
1 changed files with 14 additions and 10 deletions

View File

@ -31,10 +31,15 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/session_stats.hpp" // for stats_metric #include "libtorrent/session_stats.hpp" // for stats_metric
#include "libtorrent/aux_/session_interface.hpp" // for stats counter names #include "libtorrent/aux_/vector.hpp"
#include "libtorrent/performance_counters.hpp" // for counters #include "libtorrent/performance_counters.hpp" // for counters
#include <cstring>
#include <algorithm>
namespace libtorrent namespace libtorrent
{
namespace
{ {
struct stats_metric_impl struct stats_metric_impl
@ -44,8 +49,8 @@ namespace libtorrent
}; };
#define METRIC(category, name) { #category "." #name, counters:: name }, #define METRIC(category, name) { #category "." #name, counters:: name },
static const stats_metric_impl metrics[] = aux::array<stats_metric_impl, counters::num_counters> const metrics
{ ({{
// ``error_peers`` is the total number of peer disconnects // ``error_peers`` is the total number of peer disconnects
// caused by an error (not initiated by this client) and // caused by an error (not initiated by this client) and
// disconnected initiated by this client (``disconnected_peers``). // disconnected initiated by this client (``disconnected_peers``).
@ -545,15 +550,15 @@ namespace libtorrent
METRIC(sock_bufs, socket_recv_size20) METRIC(sock_bufs, socket_recv_size20)
// ... more // ... more
}; }});
#undef METRIC #undef METRIC
} // anonymous namespace
std::vector<stats_metric> session_stats_metrics() std::vector<stats_metric> session_stats_metrics()
{ {
std::vector<stats_metric> stats; aux::vector<stats_metric> stats;
int const num = sizeof(metrics) / sizeof(metrics[0]); stats.resize(metrics.size());
stats.resize(num); for (int i = 0; i < metrics.end_index(); ++i)
for (std::size_t i = 0; i < num; ++i)
{ {
stats[i].name = metrics[i].name; stats[i].name = metrics[i].name;
stats[i].value_index = metrics[i].value_index; stats[i].value_index = metrics[i].value_index;
@ -565,7 +570,7 @@ namespace libtorrent
int find_metric_idx(char const* name) int find_metric_idx(char const* name)
{ {
stats_metric_impl const* i = std::find_if(std::begin(metrics), std::end(metrics) auto const i = std::find_if(std::begin(metrics), std::end(metrics)
, [name](stats_metric_impl const& metr) , [name](stats_metric_impl const& metr)
{ return std::strcmp(metr.name, name) == 0; }); { return std::strcmp(metr.name, name) == 0; });
@ -574,4 +579,3 @@ namespace libtorrent
} }
} }