fixed CPU time calculations on server

This commit is contained in:
David White 2008-03-20 14:08:16 +00:00
parent 074746f3e3
commit dedcf6543b

View file

@ -44,11 +44,33 @@
#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
#define ERR_SERVER LOG_STREAM(err, mp_server)
@ -484,14 +506,7 @@ void server::run() {
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 @@ void server::run() {
simple_wml::document data(compressed_buf);
std::vector<char>().swap(buf);
if(sample) {
after_parsing = parsing_timer.elapsed();
// times(&after_parsing);
}
const clock_t after_parsing = get_cpu_time(sample);
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);
}
}