43 , most_consecutive_requests_(0)
44 , current_requests_(0)
46 , nrequests_waited_(0)
47 , started_at_(std::
chrono::steady_clock::now())
55 delete[]
s.name.begin();
80 const std::chrono::steady_clock::duration& parsing_time,
81 const std::chrono::steady_clock::duration& processing_time)
84 if(isample ==
samples_.end() || isample->name != name) {
92 new_sample.
name = dup_name;
93 samples_.insert(isample, new_sample);
99 isample->parsing_time += parsing_time;
100 isample->processing_time += processing_time;
101 isample->max_parsing_time = std::max(parsing_time,isample->max_parsing_time);
102 isample->max_processing_time = std::max(processing_time,isample->max_processing_time);
112 if (
terminations_.empty())
return out <<
"No game ended so far.";
115 out <<
"Games have been terminated in the following ways:\n";
117 out <<
t.first <<
": " <<
t.second <<
"\n";
120 out <<
"Total number of games = " <<
n;
129 std::vector<metrics::sample> ordered_samples =
samples_;
132 out <<
"\nSampled request types:\n";
135 std::chrono::steady_clock::duration pa{0};
136 std::chrono::steady_clock::duration pr{0};
137 for(
const auto&
s : ordered_samples) {
138 out <<
"'" <<
s.name <<
"' called " <<
s.nsamples <<
" times "
139 <<
s.parsing_time.count() <<
"(" <<
s.max_parsing_time.count() <<
") parsing time, "
140 <<
s.processing_time.count() <<
"(" <<
s.max_processing_time.count() <<
") processing time\n";
142 pa +=
s.parsing_time;
143 pr +=
s.processing_time;
145 out <<
"Total number of request samples = " <<
n <<
"\n"
146 <<
"Total parsing time = " << pa.count() <<
"\n"
147 <<
"Total processing time = " << pr.count();
154 const auto time_up = std::chrono::steady_clock::now() - met.
started_at_;
158 const int percent_immediate = (requests_immediate*100)/(met.
nrequests_ > 0 ? met.
nrequests_ : 1);
159 out <<
"METRICS\nUp " <<
days.count() <<
" days, " << hours.count() <<
" hours, "
160 << minutes.count() <<
" minutes, " << seconds.count() <<
" seconds\n"
161 << met.
nrequests_ <<
" requests serviced. " << requests_immediate
162 <<
" (" << percent_immediate <<
"%) "
163 <<
"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_
int most_consecutive_requests_
const std::chrono::steady_clock::time_point started_at_
void game_terminated(const std::string &reason)
void record_sample(const simple_wml::string_span &name, const std::chrono::steady_clock::duration &parsing_time, const std::chrono::steady_clock::duration &processing_time)
std::ostream & operator<<(std::ostream &out, metrics &met)
std::chrono::duration< int, std::ratio< 86400 > > days
constexpr auto deconstruct_duration(const std::chrono::duration< Rep, Period > &span)
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
std::chrono::steady_clock::duration processing_time
simple_wml::string_span name
static map_location::direction n
static map_location::direction s