The Battle for Wesnoth  1.17.0-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 #pragma once
16 
18 
19 #include <ctime>
20 #include <iosfwd>
21 #include <map>
22 #include <string>
23 
24 class metrics
25 {
26 public:
27  metrics();
28  ~metrics();
29 
30  void service_request();
31  void no_requests();
32 
33  void record_sample(const simple_wml::string_span& name, clock_t parsing_time, clock_t processing_time);
34 
35  void game_terminated(const std::string& reason);
36 
37  std::ostream& games(std::ostream& out) const;
38  std::ostream& requests(std::ostream& out) const;
39  friend std::ostream& operator<<(std::ostream& out, metrics& met);
40 
41  struct sample
42  {
44  : name()
45  , nsamples(0)
46  , parsing_time(0)
47  , processing_time(0)
48  , max_parsing_time(0)
50  {
51  }
52 
54  int nsamples;
57 
58  operator const simple_wml::string_span&()
59  {
60  return name;
61  }
62  };
63 
64 private:
65  std::vector<sample> samples_;
66 
71  const std::time_t started_at_;
72  std::map<std::string, int> terminations_;
73 };
74 
75 std::ostream& operator<<(std::ostream& out, metrics& met);
metrics()
Definition: metrics.cpp:38
const std::time_t started_at_
Definition: metrics.hpp:71
std::ostream & games(std::ostream &out) const
Definition: metrics.cpp:105
std::map< std::string, int > terminations_
Definition: metrics.hpp:72
int current_requests_
Definition: metrics.hpp:68
clock_t max_parsing_time
Definition: metrics.hpp:56
void service_request()
Definition: metrics.cpp:58
std::vector< sample > samples_
Definition: metrics.hpp:65
~metrics()
Definition: metrics.cpp:49
std::ostream & requests(std::ostream &out) const
Definition: metrics.cpp:120
void no_requests()
Definition: metrics.cpp:71
clock_t max_processing_time
Definition: metrics.hpp:56
clock_t processing_time
Definition: metrics.hpp:55
int nrequests_
Definition: metrics.hpp:69
simple_wml::string_span name
Definition: metrics.hpp:53
void game_terminated(const std::string &reason)
Definition: metrics.cpp:100
int most_consecutive_requests_
Definition: metrics.hpp:67
clock_t parsing_time
Definition: metrics.hpp:55
void record_sample(const simple_wml::string_span &name, clock_t parsing_time, clock_t processing_time)
Definition: metrics.cpp:76
friend std::ostream & operator<<(std::ostream &out, metrics &met)
Definition: metrics.cpp:147
int nrequests_waited_
Definition: metrics.hpp:70