mail[Wesnoth-commits] r25339 - in /trunk/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 dave on March 30, 2008 - 20:45:
Author: dave
Date: Sun Mar 30 20:02:36 2008
New Revision: 25339

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25339&view=rev
Log:
added 'netstats' query command to wesnothd to query for current network 
transfer info

Modified:
    trunk/src/network.cpp
    trunk/src/network.hpp
    trunk/src/network_worker.cpp
    trunk/src/network_worker.hpp
    trunk/src/server/server.cpp

Modified: trunk/src/network.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network.cpp?rev=25339&r1=25338&r2=25339&view=diff
==============================================================================
--- trunk/src/network.cpp (original)
+++ trunk/src/network.cpp Sun Mar 30 20:02:36 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: trunk/src/network.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network.hpp?rev=25339&r1=25338&r2=25339&view=diff
==============================================================================
--- trunk/src/network.hpp (original)
+++ trunk/src/network.hpp Sun Mar 30 20:02:36 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: trunk/src/network_worker.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.cpp?rev=25339&r1=25338&r2=25339&view=diff
==============================================================================
--- trunk/src/network_worker.cpp (original)
+++ trunk/src/network_worker.cpp Sun Mar 30 20:02:36 2008
@@ -100,7 +100,6 @@
 size_t min_threads = 0;
 size_t max_threads = 0;
 
-
 int get_shard(TCPsocket sock) { return intptr_t(sock)%NUM_SHARDS; }
 
 struct buffer {
@@ -637,6 +636,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;

Modified: trunk/src/network_worker.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/network_worker.hpp?rev=25339&r1=25338&r2=25339&view=diff
==============================================================================
--- trunk/src/network_worker.hpp (original)
+++ trunk/src/network_worker.hpp Sun Mar 30 20:02:36 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: trunk/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/server.cpp?rev=25339&r1=25338&r2=25339&view=diff
==============================================================================
--- trunk/src/server/server.cpp (original)
+++ trunk/src/server/server.cpp Sun Mar 30 20:02:36 2008
@@ -812,7 +812,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: "
@@ -838,7 +838,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");
@@ -850,6 +850,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:21:41 2008