Removed bandwidth monitor perprocessor test, It is now included allways
This commit is contained in:
parent
c32e2f7d68
commit
527a8f0486
6 changed files with 21 additions and 136 deletions
|
@ -231,12 +231,7 @@ wesnothd_SOURCES = \
|
|||
time.cpp \
|
||||
loadscreen_empty.cpp
|
||||
|
||||
wesnothd_compilerflags = $(AM_CXXFLAGS)
|
||||
if BANDWIDTH_MONITOR
|
||||
wesnothd_compilerflags += -DBANDWIDTH_MONITOR
|
||||
endif
|
||||
|
||||
wesnothd_CXXFLAGS = $(wesnothd_compilerflags)
|
||||
wesnothd_LDADD = -L. -lwesnoth-core $(BOOST_IOSTREAMS_LIBS) @SDL_NET_LIBS@ @SDL_LIBS@ $(LIBINTL)
|
||||
wesnothd_DEPENDENCIES=libwesnoth-core.a
|
||||
|
||||
|
|
|
@ -647,19 +647,11 @@ void queue_disconnect(network::connection sock)
|
|||
disconnection_queue.push_back(sock);
|
||||
}
|
||||
|
||||
connection receive_data(config& cfg, connection connection_num, unsigned int timeout
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, bandwidth_in_ptr* bandwidth_in
|
||||
#endif
|
||||
)
|
||||
connection receive_data(config& cfg, connection connection_num, unsigned int timeout, bandwidth_in_ptr* bandwidth_in)
|
||||
{
|
||||
unsigned int start_ticks = SDL_GetTicks();
|
||||
while(true) {
|
||||
const connection res = receive_data(cfg,connection_num
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
,(bool*)0 , bandwidth_in
|
||||
#endif
|
||||
);
|
||||
const connection res = receive_data(cfg,connection_num,(bool*)0 , bandwidth_in);
|
||||
if(res != 0) {
|
||||
return res;
|
||||
}
|
||||
|
@ -677,11 +669,7 @@ connection receive_data(config& cfg, connection connection_num, unsigned int tim
|
|||
return 0;
|
||||
}
|
||||
|
||||
connection receive_data(config& cfg, connection connection_num, bool* gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, bandwidth_in_ptr* bandwidth_in
|
||||
#endif
|
||||
)
|
||||
connection receive_data(config& cfg, connection connection_num, bool* gzipped, bandwidth_in_ptr* bandwidth_in)
|
||||
{
|
||||
if(!socket_set) {
|
||||
return 0;
|
||||
|
@ -736,18 +724,12 @@ connection receive_data(config& cfg, connection connection_num, bool* gzipped
|
|||
|
||||
TCPsocket sock = connection_num == 0 ? 0 : get_socket(connection_num);
|
||||
TCPsocket s = sock;
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
bandwidth_in_ptr temp;
|
||||
if (!bandwidth_in)
|
||||
{
|
||||
bandwidth_in = &temp;
|
||||
}
|
||||
#endif
|
||||
sock = network_worker_pool::get_received_data(sock,cfg, gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, *bandwidth_in
|
||||
#endif
|
||||
);
|
||||
sock = network_worker_pool::get_received_data(sock,cfg, gzipped, *bandwidth_in);
|
||||
if (sock == NULL) {
|
||||
if (!is_server() && last_ping != 0 && ping_timeout != 0)
|
||||
{
|
||||
|
@ -797,11 +779,7 @@ connection receive_data(config& cfg, connection connection_num, bool* gzipped
|
|||
return result;
|
||||
}
|
||||
|
||||
connection receive_data(std::vector<char>& buf
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, bandwidth_in_ptr* bandwidth_in
|
||||
#endif
|
||||
)
|
||||
connection receive_data(std::vector<char>& buf, bandwidth_in_ptr* bandwidth_in)
|
||||
{
|
||||
if(!socket_set) {
|
||||
return 0;
|
||||
|
@ -859,7 +837,6 @@ connection receive_data(std::vector<char>& buf
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
{
|
||||
bandwidth_in_ptr temp;
|
||||
if (!bandwidth_in)
|
||||
|
@ -869,7 +846,6 @@ connection receive_data(std::vector<char>& buf
|
|||
const int headers = 4;
|
||||
bandwidth_in->reset(new network::bandwidth_in(buf.size() + headers));
|
||||
}
|
||||
#endif
|
||||
|
||||
int set_res = SDLNet_TCP_AddSocket(socket_set,sock);
|
||||
|
||||
|
@ -891,7 +867,6 @@ connection receive_data(std::vector<char>& buf
|
|||
waiting_sockets.insert(result);
|
||||
return result;
|
||||
}
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
struct bandwidth_stats {
|
||||
int out_packets;
|
||||
int out_bytes;
|
||||
|
@ -1021,14 +996,7 @@ void add_bandwidth_in(const std::string& packet_type, size_t len)
|
|||
add_bandwidth_in(type_, len_);
|
||||
}
|
||||
|
||||
#endif
|
||||
void send_file(const std::string& filename, connection connection_num,
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
const std::string& packet_type
|
||||
#else
|
||||
const std::string&
|
||||
#endif
|
||||
)
|
||||
void send_file(const std::string& filename, connection connection_num, const std::string& packet_type)
|
||||
{
|
||||
assert(connection_num > 0);
|
||||
if(bad_sockets.count(connection_num) || bad_sockets.count(0)) {
|
||||
|
@ -1042,10 +1010,8 @@ void send_file(const std::string& filename, connection connection_num,
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
const int packet_headers = 5;
|
||||
const int packet_headers = 4;
|
||||
add_bandwidth_out(packet_type, file_size(filename) + packet_headers);
|
||||
#endif
|
||||
network_worker_pool::queue_file(info->second.sock, filename);
|
||||
|
||||
}
|
||||
|
@ -1053,13 +1019,7 @@ void send_file(const std::string& filename, connection connection_num,
|
|||
//! @todo Note the gzipped parameter should be removed later, we want to send
|
||||
//! all data gzipped. This can be done once the campaign server is also updated
|
||||
//! to work with gzipped data.
|
||||
size_t send_data(const config& cfg, connection connection_num, const bool gzipped,
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
const std::string& packet_type
|
||||
#else
|
||||
const std::string&
|
||||
#endif
|
||||
)
|
||||
size_t send_data(const config& cfg, connection connection_num, const bool gzipped, const std::string& packet_type)
|
||||
{
|
||||
DBG_NW << "in send_data()...\n";
|
||||
|
||||
|
@ -1078,11 +1038,7 @@ size_t send_data(const config& cfg, connection connection_num, const bool gzippe
|
|||
for(sockets_list::const_iterator i = sockets.begin();
|
||||
i != sockets.end(); ++i) {
|
||||
DBG_NW << "server socket: " << server_socket << "\ncurrent socket: " << *i << "\n";
|
||||
size = send_data(cfg,*i, gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, packet_type
|
||||
#endif
|
||||
);
|
||||
size = send_data(cfg,*i, gzipped, packet_type);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
@ -1095,11 +1051,7 @@ size_t send_data(const config& cfg, connection connection_num, const bool gzippe
|
|||
}
|
||||
|
||||
LOG_NW << "SENDING to: " << connection_num << ": " << cfg;
|
||||
return network_worker_pool::queue_data(info->second.sock, cfg, gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, packet_type
|
||||
#endif
|
||||
);
|
||||
return network_worker_pool::queue_data(info->second.sock, cfg, gzipped, packet_type);
|
||||
}
|
||||
|
||||
void send_raw_data(const char* buf, int len, connection connection_num, const std::string& packet_type)
|
||||
|
@ -1126,10 +1078,8 @@ void send_raw_data(const char* buf, int len, connection connection_num, const st
|
|||
<< "\tnot found in connection_map. Not sending...\n";
|
||||
return;
|
||||
}
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
const int packet_headers = 5;
|
||||
const int packet_headers = 4;
|
||||
add_bandwidth_out(packet_type, len + packet_headers);
|
||||
#endif
|
||||
|
||||
network_worker_pool::queue_raw_data(info->second.sock, buf, len);
|
||||
}
|
||||
|
@ -1140,24 +1090,14 @@ void process_send_queue(connection, size_t)
|
|||
}
|
||||
|
||||
//! @todo Note the gzipped parameter should be removed later.
|
||||
void send_data_all_except(const config& cfg, connection connection_num, const bool gzipped,
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
const std::string& packet_type
|
||||
#else
|
||||
const std::string&
|
||||
#endif
|
||||
)
|
||||
void send_data_all_except(const config& cfg, connection connection_num, const bool gzipped, const std::string& packet_type)
|
||||
{
|
||||
for(sockets_list::const_iterator i = sockets.begin(); i != sockets.end(); ++i) {
|
||||
if(*i == connection_num) {
|
||||
continue;
|
||||
}
|
||||
|
||||
send_data(cfg,*i, gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, packet_type
|
||||
#endif
|
||||
);
|
||||
send_data(cfg,*i, gzipped, packet_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
/**
|
||||
* Enable bandwidth stats
|
||||
**/
|
||||
//#define BANDWIDTH_MONITOR
|
||||
|
||||
class config;
|
||||
|
||||
|
@ -128,7 +127,6 @@ bool disconnect(connection connection_num=0, bool force=false);
|
|||
//! on the given connection (and presumably then the handling of the error
|
||||
//! will include closing the connection).
|
||||
void queue_disconnect(connection connection_num);
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
|
||||
std::string get_bandwidth_stats();
|
||||
std::string get_bandwidth_stats_all();
|
||||
|
@ -139,9 +137,6 @@ void add_bandwidth_in(const std::string& packet_type, size_t len);
|
|||
struct bandwidth_in {
|
||||
bandwidth_in(int len) : len_(len), type_("unknown") {}
|
||||
~bandwidth_in();
|
||||
// {
|
||||
// network::add_bandwidth_in(type_, len_);
|
||||
// }
|
||||
|
||||
void set_type(const std::string& type)
|
||||
{
|
||||
|
@ -155,7 +150,6 @@ struct bandwidth_in {
|
|||
|
||||
typedef boost::shared_ptr<bandwidth_in> bandwidth_in_ptr;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//! Function to receive data from either a certain connection,
|
||||
|
@ -165,21 +159,9 @@ typedef boost::shared_ptr<bandwidth_in> bandwidth_in_ptr;
|
|||
//! Returns the connection that data was received from,
|
||||
//! or 0 if timeout occurred.
|
||||
//! Throws error if an error occurred.
|
||||
connection receive_data(config& cfg, connection connection_num=0, bool* gzipped = 0
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, bandwidth_in_ptr* b = 0
|
||||
#endif
|
||||
);
|
||||
connection receive_data(config& cfg, connection connection_num, unsigned int timeout
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, bandwidth_in_ptr* b = 0
|
||||
#endif
|
||||
);
|
||||
connection receive_data(std::vector<char>& buf
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, bandwidth_in_ptr* = 0
|
||||
#endif
|
||||
);
|
||||
connection receive_data(config& cfg, connection connection_num=0, bool* gzipped = 0, bandwidth_in_ptr* b = 0);
|
||||
connection receive_data(config& cfg, connection connection_num, unsigned int timeout, bandwidth_in_ptr* b = 0);
|
||||
connection receive_data(std::vector<char>& buf, bandwidth_in_ptr* = 0);
|
||||
|
||||
void send_file(const std::string&, connection, const std::string& packet_type = "unknown");
|
||||
|
||||
|
|
|
@ -883,11 +883,7 @@ void receive_data(TCPsocket sock)
|
|||
}
|
||||
}
|
||||
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
,network::bandwidth_in_ptr& bandwidth_in
|
||||
#endif
|
||||
)
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped,network::bandwidth_in_ptr& bandwidth_in)
|
||||
{
|
||||
assert(!raw_data_only);
|
||||
const threading::lock lock_received(*received_mutex);
|
||||
|
@ -918,9 +914,7 @@ TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped
|
|||
if (gzipped)
|
||||
*gzipped = buf->gzipped;
|
||||
received_data_queue.erase(itor);
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
bandwidth_in.reset(new network::bandwidth_in((*itor)->raw_buffer.size()));
|
||||
#endif
|
||||
delete buf;
|
||||
return res;
|
||||
}
|
||||
|
@ -970,11 +964,7 @@ void queue_file(TCPsocket sock, const std::string& filename)
|
|||
queue_buffer(sock, queued_buf);
|
||||
}
|
||||
|
||||
size_t queue_data(TCPsocket sock,const config& buf, const bool gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, const std::string& packet_type
|
||||
#endif
|
||||
)
|
||||
size_t queue_data(TCPsocket sock,const config& buf, const bool gzipped, const std::string& packet_type)
|
||||
{
|
||||
DBG_NW << "queuing data...\n";
|
||||
|
||||
|
@ -983,9 +973,7 @@ size_t queue_data(TCPsocket sock,const config& buf, const bool gzipped
|
|||
queued_buf->gzipped = gzipped;
|
||||
const size_t size = queued_buf->stream.str().size();
|
||||
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
network::add_bandwidth_out(packet_type, size);
|
||||
#endif
|
||||
queue_buffer(sock, queued_buf);
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -53,22 +53,14 @@ void set_use_system_sendfile(bool);
|
|||
/** Function to asynchronously received data to the given socket. */
|
||||
void receive_data(TCPsocket sock);
|
||||
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, network::bandwidth_in_ptr&
|
||||
#endif
|
||||
);
|
||||
TCPsocket get_received_data(TCPsocket sock, config& cfg, bool* gzipped, network::bandwidth_in_ptr&);
|
||||
|
||||
TCPsocket get_received_data(std::vector<char>& buf);
|
||||
|
||||
void queue_file(TCPsocket sock, const std::string&);
|
||||
|
||||
void queue_raw_data(TCPsocket sock, const char* buf, int len);
|
||||
size_t queue_data(TCPsocket sock, const config& buf, const bool gzipped
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, const std::string& packet_type
|
||||
#endif
|
||||
);
|
||||
size_t queue_data(TCPsocket sock, const config& buf, const bool gzipped, const std::string& packet_type);
|
||||
bool is_locked(const TCPsocket sock);
|
||||
bool close_socket(TCPsocket sock, bool force=false);
|
||||
TCPsocket detect_error();
|
||||
|
|
|
@ -634,7 +634,6 @@ void server::run() {
|
|||
clean_user_handler(now);
|
||||
}
|
||||
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
// Send network stats every hour
|
||||
static size_t prev_hour = localtime(&now)->tm_hour;
|
||||
if (prev_hour != localtime(&now)->tm_hour)
|
||||
|
@ -643,7 +642,6 @@ void server::run() {
|
|||
LOG_SERVER << network::get_bandwidth_stats();
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
// send a 'ping' to all players to detect ghosts
|
||||
DBG_SERVER << "Pinging inactive players.\n" ;
|
||||
|
@ -696,14 +694,8 @@ void server::run() {
|
|||
static int sample_counter = 0;
|
||||
|
||||
std::vector<char> buf;
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
network::bandwidth_in_ptr bandwidth_type;
|
||||
#endif
|
||||
while ((sock = network::receive_data(buf
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
, &bandwidth_type
|
||||
#endif
|
||||
)) != network::null_connection) {
|
||||
while ((sock = network::receive_data(buf, &bandwidth_type)) != network::null_connection) {
|
||||
metrics_.service_request();
|
||||
|
||||
if(buf.empty()) {
|
||||
|
@ -739,9 +731,7 @@ void server::run() {
|
|||
|
||||
process_data(sock, data);
|
||||
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
bandwidth_type->set_type("command");
|
||||
#endif
|
||||
if(sample) {
|
||||
const clock_t after_processing = get_cpu_time(sample);
|
||||
metrics_.record_sample(data.root().first_child(),
|
||||
|
@ -1208,12 +1198,10 @@ std::string server::process_command(const std::string& query, const std::string&
|
|||
out << "Network stats:\nPending send buffers: "
|
||||
<< stats.npending_sends << "\nBytes in buffers: "
|
||||
<< stats.nbytes_pending_sends << "\n";
|
||||
#ifdef BANDWIDTH_MONITOR
|
||||
if (parameters == "all")
|
||||
out << network::get_bandwidth_stats_all();
|
||||
else
|
||||
out << network::get_bandwidth_stats(); // stats from previuos hour
|
||||
#endif
|
||||
} else if (command == "msg" || command == "lobbymsg") {
|
||||
if (parameters == "") {
|
||||
return "You must type a message.";
|
||||
|
|
Loading…
Add table
Reference in a new issue