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