35 return a.processing_time <
b.processing_time;
41 , most_consecutive_requests_(0)
42 , current_requests_(0)
44 , nrequests_waited_(0)
45 , started_at_(std::time(nullptr))
53 delete[]
s.name.begin();
80 if(isample ==
samples_.end() || isample->name != name) {
88 new_sample.
name = dup_name;
89 samples_.insert(isample, new_sample);
95 isample->parsing_time += parsing_time;
96 isample->processing_time += processing_time;
97 isample->max_parsing_time = std::max(parsing_time,isample->max_parsing_time);
98 isample->max_processing_time = std::max(processing_time,isample->max_processing_time);
108 if (
terminations_.empty())
return out <<
"No game ended so far.";
111 out <<
"Games have been terminated in the following ways:\n";
113 out <<
t.first <<
": " <<
t.second <<
"\n";
116 out <<
"Total number of games = " <<
n;
125 std::vector<metrics::sample> ordered_samples =
samples_;
128 out <<
"\nSampled request types:\n";
133 for(
const auto&
s : ordered_samples) {
134 out <<
"'" <<
s.name <<
"' called " <<
s.nsamples <<
" times "
135 <<
s.parsing_time <<
"("<<
s.max_parsing_time <<
") parsing time, "
136 <<
s.processing_time <<
"("<<
s.max_processing_time<<
") processing time\n";
138 pa +=
s.parsing_time;
139 pr +=
s.processing_time;
141 out <<
"Total number of request samples = " <<
n <<
"\n"
142 <<
"Total parsing time = " << pa <<
"\n"
143 <<
"Total processing time = " << pr;
150 const std::time_t time_up = std::time(
nullptr) - met.
started_at_;
151 const int seconds = time_up%60;
152 const int minutes = (time_up/60)%60;
153 const int hours = (time_up/(60*60))%24;
154 const int days = time_up/(60*60*24);
156 const int percent_immediate = (requests_immediate*100)/(met.
nrequests_ > 0 ? met.
nrequests_ : 1);
157 out <<
"METRICS\nUp " << days <<
" days, " << hours <<
" hours, "
158 << minutes <<
" minutes, " << seconds <<
" seconds\n"
159 << met.
nrequests_ <<
" requests serviced. " << requests_immediate
160 <<
" (" << percent_immediate <<
"%) "
161 <<
"requests were serviced immediately.\n"
std::map< std::string, int > terminations_
std::ostream & requests(std::ostream &out) const
std::ostream & games(std::ostream &out) const
std::vector< sample > samples_
void record_sample(const simple_wml::string_span &name, clock_t parsing_time, clock_t processing_time)
int most_consecutive_requests_
const std::time_t started_at_
void game_terminated(const std::string &reason)
std::ostream & operator<<(std::ostream &out, metrics &met)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
bool operator()(const metrics::sample &a, const metrics::sample &b) const
bool operator()(const simple_wml::string_span &a, const simple_wml::string_span &b) const
simple_wml::string_span name
static map_location::DIRECTION n
static map_location::DIRECTION s