mail[Wesnoth-commits] r25322 - /branches/1.4/src/server/server.cpp


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

Header


Content

Posted by soliton . de on March 30, 2008 - 14:26:
Author: soliton
Date: Sun Mar 30 14:26:19 2008
New Revision: 25322

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25322&view=rev
Log:
* don't do CPU time calculations on windows (merged r24902 from trunk)

Modified:
    branches/1.4/src/server/server.cpp

Modified: branches/1.4/src/server/server.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/branches/1.4/src/server/server.cpp?rev=25322&r1=25321&r2=25322&view=diff
==============================================================================
--- branches/1.4/src/server/server.cpp (original)
+++ branches/1.4/src/server/server.cpp Sun Mar 30 14:26:19 2008
@@ -44,9 +44,32 @@
 #include <sstream>
 #include <vector>
 
+#include <csignal>
+
+#ifndef _WIN32
 #include <sys/times.h>
 
-#include <csignal>
+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
@@ -494,11 +517,7 @@
 
                                const bool sample = request_sample_frequency 
= 1 && (sample_counter++ % request_sample_frequency) == 0;
 
-                               struct tms before_parsing, after_parsing, 
after_processing;
-
-                               if(sample) {
-                                       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());
@@ -507,17 +526,15 @@
                                data.take_ownership_of_buffer(buf_ptr);
                                std::vector<char>().swap(buf);
 
+                               const clock_t after_parsing = 
get_cpu_time(sample);
+
+                               process_data(sock, data);
+
                                if(sample) {
-                                       times(&after_parsing);
-                               }
-
-                               process_data(sock, data);
-
-                               if(sample) {
-                                       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_processing.tms_utime 
- after_parsing.tms_utime);
+                                                 after_parsing - 
before_parsing,
+                                                         after_processing - 
after_parsing);
                                }
                        }
 




Related Messages


Powered by MHonArc, Updated Sun Mar 30 14:41:42 2008