Updated ana's implementation of get_bandwidth_stats()...
...to issue the string corresponding to network stats of the last hour only. This is the original intention, as is visible in the implementation in network.cpp, lines 961 through 969. Also added a parameter to ana_components' method get_stats to select the time period for which stats are requested and performed an analogous change in the network_manager's method by the same name.
This commit is contained in:
parent
41290b4498
commit
008acdc8dc
3 changed files with 30 additions and 9 deletions
|
@ -274,8 +274,27 @@ namespace network {
|
|||
|
||||
std::string get_bandwidth_stats()
|
||||
{
|
||||
//TODO: check if this is the intention
|
||||
return get_bandwidth_stats_all();
|
||||
std::cout << "DEBUG: get_bandwidth_stats() for "
|
||||
<< ana_manager.number_of_connections() << " components.\n";
|
||||
|
||||
//TODO: packet_type and widths should be modifiable
|
||||
const char* packet_type = "network";
|
||||
|
||||
const size_t field_width = 8;
|
||||
const size_t packet_width = 8;
|
||||
const size_t bytes_width = 8;
|
||||
|
||||
const ana::stats* stats = ana_manager.get_stats( 0, ana::HOURS );
|
||||
|
||||
|
||||
std::stringstream ss;
|
||||
ss << " " << std::setw(field_width) << packet_type << "| "
|
||||
<< std::setw(packet_width)<< stats->packets_out()<< "| "
|
||||
<< std::setw(bytes_width) << stats->bytes_out() /1024 << "| "
|
||||
<< std::setw(packet_width)<< stats->packets_in()<< "| "
|
||||
<< std::setw(bytes_width) << stats->bytes_in() /1024 << "\n";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string get_bandwidth_stats(int hour)
|
||||
|
|
|
@ -479,9 +479,9 @@ void ana_component::set_wesnoth_id( network::connection id )
|
|||
wesnoth_id_ = id;
|
||||
}
|
||||
|
||||
const ana::stats* ana_component::get_stats() const
|
||||
const ana::stats* ana_component::get_stats( ana::stat_type type ) const
|
||||
{
|
||||
return listener()->get_stats();
|
||||
return listener()->get_stats( type );
|
||||
}
|
||||
|
||||
void ana_component::add_buffer(ana::detail::read_buffer buffer, ana::net_id id)
|
||||
|
@ -715,7 +715,8 @@ network::connection ana_network_manager::new_connection_id( )
|
|||
// No new connection
|
||||
return 0;
|
||||
}
|
||||
const ana::stats* ana_network_manager::get_stats( network::connection connection_num )
|
||||
const ana::stats* ana_network_manager::get_stats( network::connection connection_num,
|
||||
ana::stat_type type)
|
||||
{
|
||||
ana::net_id id( connection_num );
|
||||
std::set<ana_component*>::iterator it;
|
||||
|
@ -725,7 +726,7 @@ const ana::stats* ana_network_manager::get_stats( network::connection connection
|
|||
if ( components_.size() > 0 )
|
||||
{
|
||||
it = components_.begin();
|
||||
return (*it)->get_stats();
|
||||
return (*it)->get_stats( type );
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
|
@ -736,7 +737,7 @@ const ana::stats* ana_network_manager::get_stats( network::connection connection
|
|||
boost::bind(&ana_component::get_id, _1) == id );
|
||||
|
||||
if ( it != components_.end())
|
||||
return (*it)->get_stats();
|
||||
return (*it)->get_stats( type );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ class ana_component
|
|||
void set_wesnoth_id( network::connection ) ;
|
||||
|
||||
/** Returns a pointer to the ana::stats object for accumulated network stats. */
|
||||
const ana::stats* get_stats() const;
|
||||
const ana::stats* get_stats( ana::stat_type type = ana::ACCUMULATED ) const;
|
||||
|
||||
/** Push a buffer to the queue of incoming messages. */
|
||||
void add_buffer(ana::detail::read_buffer buffer, ana::net_id id);
|
||||
|
@ -393,7 +393,8 @@ class ana_network_manager : public ana::listener_handler,
|
|||
*
|
||||
* @returns A pointer to an ana::stats object of the given component.
|
||||
*/
|
||||
const ana::stats* get_stats( network::connection connection_num = 0);
|
||||
const ana::stats* get_stats( network::connection connection_num = 0,
|
||||
ana::stat_type type = ana::ACCUMULATED);
|
||||
|
||||
/** Close all connections and clean up memory. */
|
||||
void close_connections_and_cleanup();
|
||||
|
|
Loading…
Add table
Reference in a new issue