Author: soliton
Date: Tue Sep 16 20:49:43 2008
New Revision: 29495

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29495&view=rev
Log:
* split parts of the metrics command into games, samples and stats commands

Modified:
    trunk/src/server/metrics.cpp
    trunk/src/server/metrics.hpp
    trunk/src/server/server.cpp

Modified: trunk/src/server/metrics.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/metrics.cpp?rev=29495&r1=29494&r2=29495&view=diff
==============================================================================
--- trunk/src/server/metrics.cpp (original)
+++ trunk/src/server/metrics.cpp Tue Sep 16 20:49:43 2008
@@ -107,6 +107,42 @@
        terminations_[reason]++;
 }
 
+std::ostream& metrics::games(std::ostream& out)
+{
+       if (terminations_.empty()) return out;
+
+       size_t n = 0;
+       out << "Games have been terminated in the following ways: \n";
+       for(std::map<std::string,int>::const_iterator i = 
terminations_.begin(); i != terminations_.end(); ++i) {
+               out << i->first << ": " << i->second << "\n";
+               ++n;
+       }
+       out << "Total number of games = " << n;
+
+       return out;
+}
+
+std::ostream& metrics::samples(std::ostream& out)
+{
+       if (samples_.empty()) return out;
+
+       std::vector<metrics::sample> ordered_samples = samples_;
+       std::sort(ordered_samples.begin(), ordered_samples.end(), 
compare_samples_by_time());
+
+       out << "Request types:\n";
+
+       size_t n = 0;
+       for(std::vector<metrics::sample>::const_iterator s = 
ordered_samples.begin(); s != ordered_samples.end(); ++s) {
+               out << "'" << s->name << "' called " << s->nsamples << " times "
+                       << s->parsing_time << "("<< s->max_parsing_time <<") 
parsing time, "
+                       << s->processing_time << 
"("<<s->max_processing_time<<") processing time\n";
+               ++n;
+       }
+       out << "Total number of games = " << n;
+
+       return out;
+}
+
 std::ostream& operator<<(std::ostream& out, metrics& met)
 {
        const time_t time_up = time(NULL) - met.started_at_;
@@ -121,26 +157,7 @@
            << met.nrequests_ << " requests serviced. " << requests_immediate
            << " (" << percent_immediate << "%) "
            << " requests were serviced immediately\n"
-           << "longest burst of requests was " << 
met.most_consecutive_requests_ << "\n";
-
-       if(met.terminations_.empty() == false) {
-               out << "Games have been terminated in the following ways: \n";
-               for(std::map<std::string,int>::const_iterator i = 
met.terminations_.begin(); i != met.terminations_.end(); ++i) {
-                       out << i->first << ": " << i->second << "\n";
-               }
-       }
-
-       std::vector<metrics::sample> ordered_samples = met.samples_;
-       std::sort(ordered_samples.begin(), ordered_samples.end(), 
compare_samples_by_time());
-
-       out << "\n\nRequest types:\n";
-
-       for(std::vector<metrics::sample>::const_iterator s = 
ordered_samples.begin(); s != ordered_samples.end(); ++s) {
-               out << "'" << s->name 
-                       << "' called " << s->nsamples << " times " 
-                       << s->parsing_time << "("<< s->max_parsing_time <<") 
parsing time, " 
-                       << s->processing_time << 
"("<<s->max_processing_time<<") processing time\n";
-       }
+           << "longest burst of requests was " << 
met.most_consecutive_requests_;
 
        return out;
 }

Modified: trunk/src/server/metrics.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/metrics.hpp?rev=29495&r1=29494&r2=29495&view=diff
==============================================================================
--- trunk/src/server/metrics.hpp (original)
+++ trunk/src/server/metrics.hpp Tue Sep 16 20:49:43 2008
@@ -42,6 +42,8 @@
 
        void game_terminated(const std::string& reason);
 
+       std::ostream& games(std::ostream& out);
+       std::ostream& samples(std::ostream& out);
        friend std::ostream& operator<<(std::ostream& out, metrics& met);
 
        struct sample {

Modified: trunk/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/server.cpp?rev=29495&r1=29494&r2=29495&view=diff
==============================================================================
--- trunk/src/server/server.cpp (original)
+++ trunk/src/server/server.cpp Tue Sep 16 20:49:43 2008
@@ -1099,8 +1099,8 @@
        }
        const simple_wml::string_span& command(query["type"]);
        std::ostringstream response;
-       const std::string& help_msg = "Available commands are: help, metrics,"
-                       " motd, netstats [all], status, wml.";
+       const std::string& help_msg = "Available commands are: help, games, 
metrics,"
+                       " motd, netstats [all], samples, stats, status, wml.";
        if (admins_.count(sock) != 0) {
                LOG_SERVER << "Admin Command:" << "\ttype: " << command
                        << "\tIP: "<< network::ip_address(sock) 
@@ -1151,8 +1151,8 @@
        utils::strip(parameters);
        const std::string& help_msg = "Available commands are: ban <mask> 
[<time>] <reason>,"
                        " bans [deleted], kick <mask>, k(ick)ban <mask> 
[<time>] <reason>,"
-                       " help, metrics, netstats, (lobby)msg <message>, motd 
[<message>],"
-                       " status [<mask>], unban <ipmask>";
+                       " help, games, metrics, netstats, (lobby)msg <message>, 
motd [<message>],"
+                       " samples, stats, status [<mask>], unban <ipmask>";
        // Shutdown and restart commands can only be issued via the socket.
        if (command == "shut_down" && issuer_name == "*socket*") {
                if (parameters == "now") {
@@ -1185,11 +1185,17 @@
 #endif
        } else if (command == "help") {
                out << help_msg;
+       } else if (command == "stats") {
+               out << "Number of games = " << games_.size()
+                       << "\nTotal number of users = " << players_.size()
+                       << "\nNumber of ghost users = " << ghost_players_.size()
+                       << "\nNumber of users in the lobby = " << 
lobby_.nobservers();
        } else if (command == "metrics") {
-               out << metrics_ << "Current number of games = " << 
games_.size() << "\n"
-                 "Total number of users = " << players_.size() << "\n"
-                 "Total number of ghost users = " << ghost_players_.size() << 
"\n"
-                 "Number of users in the lobby = " << lobby_.nobservers() << 
"\n";
+               out << metrics_;
+       } else if (command == "samples") {
+               metrics_.samples(out);
+       } else if (command == "games") {
+               metrics_.games(out);
        } else if (command == "wml") {
                out << simple_wml::document::stats();
        } else if (command == "netstats") {


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to