The Battle for Wesnoth  1.15.2+dev
metrics.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /** @file */
16 
17 #pragma once
18 
19 #include <iosfwd>
20 
21 #include <map>
22 #include <string>
23 #include <ctime>
24 
25 #include "server/simple_wml.hpp"
26 
27 class metrics
28 {
29 public:
30  metrics();
31  ~metrics();
32 
33  void service_request();
34  void no_requests();
35 
36  void record_sample(const simple_wml::string_span& name,
37  clock_t parsing_time, clock_t processing_time);
38 
39  void game_terminated(const std::string& reason);
40 
41  std::ostream& games(std::ostream& out) const;
42  std::ostream& requests(std::ostream& out) const;
43  friend std::ostream& operator<<(std::ostream& out, metrics& met);
44 
45  struct sample {
46 
47  sample() :
48  name(),
49  nsamples(0),
50  parsing_time(0),
51  processing_time(0),
54  {
55  }
56 
58  int nsamples;
61 
62  operator const simple_wml::string_span&()
63  {
64  return name;
65  }
66  };
67 
68 private:
69  std::vector<sample> samples_;
70 
75  const std::time_t started_at_;
76  std::map<std::string,int> terminations_;
77 };
78 
79 std::ostream& operator<<(std::ostream& out, metrics& met);
metrics()
Definition: metrics.cpp:39
const std::time_t started_at_
Definition: metrics.hpp:75
std::ostream & games(std::ostream &out) const
Definition: metrics.cpp:109
int current_requests_
Definition: metrics.hpp:72
clock_t max_parsing_time
Definition: metrics.hpp:60
void service_request()
Definition: metrics.cpp:60
std::vector< sample > samples_
Definition: metrics.hpp:69
~metrics()
Definition: metrics.cpp:49
std::ostream & requests(std::ostream &out) const
Definition: metrics.cpp:124
void no_requests()
Definition: metrics.cpp:73
clock_t max_processing_time
Definition: metrics.hpp:60
clock_t processing_time
Definition: metrics.hpp:59
int nrequests_
Definition: metrics.hpp:73
simple_wml::string_span name
Definition: metrics.hpp:57
void game_terminated(const std::string &reason)
Definition: metrics.cpp:104
std::map< std::string, int > terminations_
Definition: metrics.hpp:76
int most_consecutive_requests_
Definition: metrics.hpp:71
clock_t parsing_time
Definition: metrics.hpp:59
void record_sample(const simple_wml::string_span &name, clock_t parsing_time, clock_t processing_time)
Definition: metrics.cpp:78
friend std::ostream & operator<<(std::ostream &out, metrics &met)
Definition: metrics.cpp:151
int nrequests_waited_
Definition: metrics.hpp:74