mail[Wesnoth-commits] r24902 - /trunk/src/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 20, 2008 - 15:08:
Author: dave
Date: Thu Mar 20 15:08:16 2008
New Revision: 24902

URL: http://svn.gna.org/viewcvs/wesnoth?rev=24902&view=rev
Log:
fixed CPU time calculations on server

Modified:
    trunk/src/server/server.cpp

Modified: trunk/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/server.cpp?rev=24902&r1=24901&r2=24902&view=diff
==============================================================================
--- trunk/src/server/server.cpp (original)
+++ trunk/src/server/server.cpp Thu Mar 20 15:08:16 2008
@@ -44,10 +44,32 @@
 #include <sstream>
 #include <vector>
 
-//#include <sys/times.h>
-#include <boost/timer.hpp>
-
 #include <csignal>
+
+#ifndef _WIN32
+#include <sys/times.h>
+
+namespace {
+
+clock_t get_cpu_time(bool active) {
+       if(!active) {
+               return 0;
+       }
+       struct tms buf;
+       times(&buf);
+       return buf.tms_utime + buf.tms_stime;
+}
+
+}
+
+#else
+
+// on Windows we don't calculate CPU time
+clock_t get_cpu_time(bool active) {
+       return 0;
+}
+
+#endif
 
 //! fatal and directly server related errors/warnings,
 //! ie not caused by erroneous client data
@@ -484,14 +506,7 @@
 
                                const bool sample = request_sample_frequency 
= 1 && (sample_counter++ % request_sample_frequency) == 0;
 
-                               boost::timer parsing_timer;
-                               double after_parsing, after_processing;
-//                             struct tms before_parsing, after_parsing, 
after_processing;
-
-                               if(sample) {
-                                   parsing_timer.restart();
-//                                     times(&before_parsing);
-                               }
+                               const clock_t before_parsing = 
get_cpu_time(sample);
 
                                char* buf_ptr = new char [buf.size()];
                                memcpy(buf_ptr, &buf[0], buf.size());
@@ -499,20 +514,14 @@
                                simple_wml::document data(compressed_buf);
                                std::vector<char>().swap(buf);
 
+                               const clock_t after_parsing = 
get_cpu_time(sample);
+
+                               process_data(sock, data);
+
                                if(sample) {
-                                       after_parsing = 
parsing_timer.elapsed();   
-//                                     times(&after_parsing);
-                               }
-
-                               process_data(sock, data);
-
-                               if(sample) {
-                                       after_processing = 
parsing_timer.elapsed();        
-//                                     times(&after_processing);
+                                       const clock_t after_processing = 
get_cpu_time(sample);
                                        
metrics_.record_sample(data.root().first_child(),
-//                                               after_parsing.tms_utime - 
before_parsing.tms_utime,
-                                                         after_parsing,
-//                                               after_processing.tms_utime 
- after_parsing.tms_utime);
+                                                 after_parsing - 
before_parsing,
                                                          after_processing - 
after_parsing);
                                }
                        }




Related Messages


Powered by MHonArc, Updated Thu Mar 20 17:41:24 2008