Author: suokko
Date: Wed Sep 3 03:22:30 2008
New Revision: 29229
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29229&view=rev
Log:
Fixed metrics compilation and added max procesing times for types
Modified:
trunk/src/server/metrics.cpp
trunk/src/server/metrics.hpp
Modified: trunk/src/server/metrics.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/metrics.cpp?rev=29229&r1=29228&r2=29229&view=diff
==============================================================================
--- trunk/src/server/metrics.cpp (original)
+++ trunk/src/server/metrics.cpp Wed Sep 3 03:22:30 2008
@@ -23,17 +23,12 @@
#include <time.h>
#include <iostream>
-#ifndef _MSC_VER
-static bool operator<(const metrics::sample& s, const simple_wml::string_span&
name)
-{
- return s.name < name;
-}
-
-static bool operator<(const simple_wml::string_span& name, const
metrics::sample& s)
-{
- return name < s.name;
-}
-#endif
+struct compare_samples_to_stringspan {
+ bool operator()(const simple_wml::string_span& a, const
simple_wml::string_span& b)
+ {
+ return a < b;
+ }
+};
struct compare_samples_by_time {
bool operator()(const metrics::sample& a, const metrics::sample& b)
const {
@@ -84,28 +79,26 @@
void metrics::record_sample(const simple_wml::string_span& name,
clock_t parsing_time, clock_t processing_time)
{
- std::pair<std::vector<sample>::iterator,std::vector<sample>::iterator>
- range = std::equal_range(samples_.begin(), samples_.end(), name);
- if(range.first == range.second) {
+ std::vector<sample>::iterator isample =
std::lower_bound(samples_.begin(), samples_.end(),
name,compare_samples_to_stringspan());
+ if(isample->name != name) {
//protect against DoS with memory exhaustion
if(samples_.size() > 30) {
return;
}
- int index = range.first - samples_.begin();
+ int index = isample - samples_.begin();
simple_wml::string_span dup_name(name.duplicate());
sample new_sample;
new_sample.name = dup_name;
- new_sample.nsamples = 0;
- new_sample.parsing_time = 0;
- new_sample.processing_time = 0;
- samples_.insert(range.first, new_sample);
+ samples_.insert(isample, new_sample);
- range.first = samples_.begin() + index;
+ isample = samples_.begin() + index;
}
- range.first->nsamples++;
- range.first->parsing_time += parsing_time;
- range.first->processing_time += processing_time;
+ isample->nsamples++;
+ isample->parsing_time += parsing_time;
+ isample->processing_time += processing_time;
+ isample->max_parsing_time =
std::max(parsing_time,isample->max_parsing_time);
+ isample->max_processing_time =
std::max(processing_time,isample->max_processing_time);
}
void metrics::game_terminated(const std::string& reason)
@@ -142,7 +135,10 @@
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 << " parsing time, " << s->processing_time << " processing
time\n";
+ 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";
}
return out;
Modified: trunk/src/server/metrics.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/metrics.hpp?rev=29229&r1=29228&r2=29229&view=diff
==============================================================================
--- trunk/src/server/metrics.hpp (original)
+++ trunk/src/server/metrics.hpp Wed Sep 3 03:22:30 2008
@@ -50,23 +50,21 @@
name(),
nsamples(0),
parsing_time(0),
- processing_time(0)
+ processing_time(0),
+ max_parsing_time(0),
+ max_processing_time(0)
{
}
simple_wml::string_span name;
int nsamples;
clock_t parsing_time, processing_time;
-#ifdef _MSC_VER
- bool operator< (const simple_wml::string_span& n) const
- {
- return name < n;
- }
+ clock_t max_parsing_time, max_processing_time;
+
operator const simple_wml::string_span&()
{
return name;
}
-#endif
};
private:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits