mail[Wesnoth-commits] r25340 - in /branches/1.4/src: network.cpp network.hpp network_worker.cpp network_worker.hpp server/server.cpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by martinxyz on March 30, 2008 - 20:45:
Author: martinxyz
Date: Sun Mar 30 20:36:18 2008
New Revision: 25340

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25340&view=rev
Log:
merged r25339 from trunk (added 'netstats' query command to wesnothd to query 
for current network transfer info)

Modified:
    branches/1.4/src/network.cpp
    branches/1.4/src/network.hpp
    branches/1.4/src/network_worker.cpp
    branches/1.4/src/network_worker.hpp
    branches/1.4/src/server/server.cpp

Modified: branches/1.4/src/network.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/network.cpp?rev=25340&r1=25339&r2=25340&view=diff
==============================================================================
--- branches/1.4/src/network.cpp (original)
+++ branches/1.4/src/network.cpp Sun Mar 30 20:36:18 2008
@@ -223,6 +223,11 @@
        if(socket) network::disconnect(socket);
 }
 
+pending_statistics get_pending_stats()
+{
+       return network_worker_pool::get_pending_stats();
+}
+
 manager::manager(size_t min_threads, size_t max_threads) : free_(true)
 {
        // If the network is already being managed

Modified: branches/1.4/src/network.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/network.hpp?rev=25340&r1=25339&r2=25340&view=diff
==============================================================================
--- branches/1.4/src/network.hpp (original)
+++ branches/1.4/src/network.hpp Sun Mar 30 20:36:18 2008
@@ -33,6 +33,13 @@
 // This module wraps the network interface.
 
 namespace network {
+
+struct pending_statistics {
+       int npending_sends;
+       int nbytes_pending_sends;
+};
+
+pending_statistics get_pending_stats();
 
 // A network manager must be created before networking can be used.
 // It must be destroyed only after all networking activity stops.

Modified: branches/1.4/src/network_worker.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/network_worker.cpp?rev=25340&r1=25339&r2=25340&view=diff
==============================================================================
--- branches/1.4/src/network_worker.cpp (original)
+++ branches/1.4/src/network_worker.cpp Sun Mar 30 20:36:18 2008
@@ -101,7 +101,6 @@
 size_t min_threads = 0;
 size_t max_threads = 0;
 
-
 int get_shard(TCPsocket sock) { return intptr_t(sock)%NUM_SHARDS; }
 
 struct buffer {
@@ -130,7 +129,7 @@
 
 bool managed = false, raw_data_only = false;
 typedef std::vector< buffer* > buffer_set;
-buffer_set bufs[NUM_SHARDS];
+buffer_set outgoing_bufs[NUM_SHARDS];
 
 struct schema_pair
 {
@@ -439,7 +438,7 @@
                        waiting_threads[shard]++;
                        for(;;) {
 
-                               buffer_set::iterator itor = 
bufs[shard].begin(), itor_end = bufs[shard].end();
+                               buffer_set::iterator itor = 
outgoing_bufs[shard].begin(), itor_end = outgoing_bufs[shard].end();
                                for(; itor != itor_end; ++itor) {
                                        socket_state_map::iterator lock_it = 
sockets_locked[shard].find((*itor)->sock);
                                        assert(lock_it != 
sockets_locked[shard].end());
@@ -447,7 +446,7 @@
                                                lock_it->second = 
SOCKET_LOCKED;
                                                sent_buf = *itor;
                                                sock = sent_buf->sock;
-                                               bufs[shard].erase(itor);
+                                               
outgoing_bufs[shard].erase(itor);
                                                break;
                                        }
                                }
@@ -625,6 +624,22 @@
        }
 }
 
+network::pending_statistics get_pending_stats()
+{
+       network::pending_statistics stats;
+       stats.npending_sends = 0;
+       stats.nbytes_pending_sends = 0;
+       for(int shard = 0; shard != NUM_SHARDS; ++shard) {
+               const threading::lock lock(*shard_mutexes[shard]);
+               stats.npending_sends += outgoing_bufs[shard].size();
+               for(buffer_set::const_iterator i = 
outgoing_bufs[shard].begin(); i != outgoing_bufs[shard].end(); ++i) {
+                       stats.nbytes_pending_sends += (*i)->raw_buffer.size();
+               }
+       }
+
+       return stats;
+}
+
 void set_raw_data_only()
 {
        raw_data_only = true;
@@ -698,7 +713,7 @@
        make_network_buffer(buf, len, queued_buf->raw_buffer);
        const int shard = get_shard(sock);
        const threading::lock lock(*shard_mutexes[shard]);
-       bufs[shard].push_back(queued_buf);
+       outgoing_bufs[shard].push_back(queued_buf);
        socket_state_map::const_iterator i = 
sockets_locked[shard].insert(std::pair<TCPsocket,SOCKET_STATE>(sock,SOCKET_READY)).first;
        if(i->second == SOCKET_READY || i->second == SOCKET_ERRORED) {
                cond[shard]->notify_one();
@@ -717,7 +732,7 @@
                const int shard = get_shard(sock);
                const threading::lock lock(*shard_mutexes[shard]);
 
-               bufs[shard].push_back(queued_buf);
+               outgoing_bufs[shard].push_back(queued_buf);
 
                socket_state_map::const_iterator i = 
sockets_locked[shard].insert(std::pair<TCPsocket,SOCKET_STATE>(sock,SOCKET_READY)).first;
                if(i->second == SOCKET_READY || i->second == SOCKET_ERRORED) {
@@ -735,11 +750,11 @@
 {
        {
                const int shard = get_shard(sock);
-               for(buffer_set::iterator i = bufs[shard].begin(); i != 
bufs[shard].end();) {
+               for(buffer_set::iterator i = outgoing_bufs[shard].begin(); i 
!= outgoing_bufs[shard].end();) {
                        if ((*i)->sock == sock)
                        {
                                buffer* buf = *i;
-                               i = bufs[shard].erase(i);
+                               i = outgoing_bufs[shard].erase(i);
                                delete buf;
                        }
                        else

Modified: branches/1.4/src/network_worker.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/network_worker.hpp?rev=25340&r1=25339&r2=25340&view=diff
==============================================================================
--- branches/1.4/src/network_worker.hpp (original)
+++ branches/1.4/src/network_worker.hpp Sun Mar 30 20:36:18 2008
@@ -36,6 +36,8 @@
        bool active_;
 };
 
+network::pending_statistics get_pending_stats();
+
 void set_raw_data_only();
 
 //! Function to asynchronously received data to the given socket.

Modified: branches/1.4/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/server/server.cpp?rev=25340&r1=25339&r2=25340&view=diff
==============================================================================
--- branches/1.4/src/server/server.cpp (original)
+++ branches/1.4/src/server/server.cpp Sun Mar 30 20:36:18 2008
@@ -816,7 +816,7 @@
        } else if (command == "status") {
                response << process_command(command.to_string() + " " + 
pl->second.name());
        } else if (command == "status " + pl->second.name() || command == 
"metrics"
-       || command == "motd" || command == "wml") {
+       || command == "motd" || command == "wml" || command == "netstats") {
                response << process_command(command.to_string());
        } else if (command == admin_passwd_) {
                LOG_SERVER << "New Admin recognized:" << "\tIP: "
@@ -842,7 +842,7 @@
        std::string parameters = (i == query.end() ? "" : 
std::string(i+1,query.end()));
        utils::strip(parameters);
        const std::string& help_msg = "Available commands are: (k)ban(s) 
[<mask>],"
-                       "kick <mask>, help, metrics, (lobby)msg <message>, 
motd [<message>],"
+                       "kick <mask>, help, metrics, netstats, (lobby)msg 
<message>, motd [<message>],"
                        "status [<mask>], unban <ipmask>";
        if (command == "shut_down") {
                throw network::error("shut down");
@@ -854,6 +854,11 @@
                "Number of users in the lobby = " << lobby_.nobservers() << 
"\n";
        } else if (command == "wml") {
                out << simple_wml::document::stats();
+       } else if (command == "netstats") {
+               network::pending_statistics stats = 
network::get_pending_stats();
+               out << "Network stats:\nPending send buffers: "
+                   << stats.npending_sends << "\nBytes in buffers: "
+                       << stats.nbytes_pending_sends << "\n";
        } else if (command == "msg" || command == "lobbymsg") {
                if (parameters == "") {
                        return "You must type a message.";




Related Messages


Powered by MHonArc, Updated Sun Mar 30 21:02:00 2008