The Battle for Wesnoth  1.19.5+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 <chrono>
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  /** @todo: Currently unused. Use for something? */
35  void record_sample(const simple_wml::string_span& name,
36  const std::chrono::steady_clock::duration& parsing_time,
37  const std::chrono::steady_clock::duration& 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  {
48  int nsamples = 0;
49  std::chrono::steady_clock::duration parsing_time{0};
50  std::chrono::steady_clock::duration processing_time{0};
51  std::chrono::steady_clock::duration max_parsing_time{0};
52  std::chrono::steady_clock::duration max_processing_time{0};
53 
54  operator const simple_wml::string_span&()
55  {
56  return name;
57  }
58  };
59 
60 private:
61  std::vector<sample> samples_;
62 
67  const std::chrono::steady_clock::time_point started_at_;
68  std::map<std::string, int> terminations_;
69 };
70 
71 std::ostream& operator<<(std::ostream& out, metrics& met);
std::map< std::string, int > terminations_
Definition: metrics.hpp:68
void service_request()
Definition: metrics.cpp:61
std::ostream & requests(std::ostream &out) const
Definition: metrics.cpp:125
void no_requests()
Definition: metrics.cpp:74
int nrequests_waited_
Definition: metrics.hpp:66
std::ostream & games(std::ostream &out) const
Definition: metrics.cpp:110
std::vector< sample > samples_
Definition: metrics.hpp:61
friend std::ostream & operator<<(std::ostream &out, metrics &met)
Definition: metrics.cpp:152
int current_requests_
Definition: metrics.hpp:64
int most_consecutive_requests_
Definition: metrics.hpp:63
metrics()
Definition: metrics.cpp:41
const std::chrono::steady_clock::time_point started_at_
Definition: metrics.hpp:67
~metrics()
Definition: metrics.cpp:52
void game_terminated(const std::string &reason)
Definition: metrics.cpp:105
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)
Definition: metrics.cpp:79
int nrequests_
Definition: metrics.hpp:65
std::ostream & operator<<(std::ostream &out, metrics &met)
Definition: metrics.cpp:152
std::chrono::steady_clock::duration max_processing_time
Definition: metrics.hpp:52
std::chrono::steady_clock::duration processing_time
Definition: metrics.hpp:50
std::chrono::steady_clock::duration max_parsing_time
Definition: metrics.hpp:51
std::chrono::steady_clock::duration parsing_time
Definition: metrics.hpp:49
simple_wml::string_span name
Definition: metrics.hpp:47