The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
metrics.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef METRICS_HPP_INCLUDED
18 #define METRICS_HPP_INCLUDED
19 
20 #include <iosfwd>
21 
22 #include <map>
23 #include <string>
24 #include <time.h>
25 
26 #include "simple_wml.hpp"
27 
28 class metrics
29 {
30 public:
31  metrics();
32  ~metrics();
33 
34  void service_request();
35  void no_requests();
36 
38  clock_t parsing_time, clock_t processing_time);
39 
40  void game_terminated(const std::string& reason);
41 
42  std::ostream& games(std::ostream& out) const;
43  std::ostream& requests(std::ostream& out) const;
44  friend std::ostream& operator<<(std::ostream& out, metrics& met);
45 
46  struct sample {
47 
48  sample() :
49  name(),
50  nsamples(0),
51  parsing_time(0),
52  processing_time(0),
55  {
56  }
57 
59  int nsamples;
62 
63  operator const simple_wml::string_span&()
64  {
65  return name;
66  }
67  };
68 
69 private:
70  std::vector<sample> samples_;
71 
76  const time_t started_at_;
77  std::map<std::string,int> terminations_;
78 };
79 
80 std::ostream& operator<<(std::ostream& out, metrics& met);
81 
82 #endif
metrics()
Definition: metrics.cpp:41
std::ostream & games(std::ostream &out) const
Definition: metrics.cpp:111
std::ostream & operator<<(std::ostream &out, metrics &met)
Definition: metrics.cpp:153
int current_requests_
Definition: metrics.hpp:73
clock_t max_parsing_time
Definition: metrics.hpp:61
void service_request()
Definition: metrics.cpp:62
std::ostream & requests(std::ostream &out) const
Definition: metrics.cpp:126
std::vector< sample > samples_
Definition: metrics.hpp:70
~metrics()
Definition: metrics.cpp:51
const time_t started_at_
Definition: metrics.hpp:76
void no_requests()
Definition: metrics.cpp:75
clock_t max_processing_time
Definition: metrics.hpp:61
clock_t processing_time
Definition: metrics.hpp:60
int nrequests_
Definition: metrics.hpp:74
simple_wml::string_span name
Definition: metrics.hpp:58
void game_terminated(const std::string &reason)
Definition: metrics.cpp:106
GLuint const GLchar * name
Definition: glew.h:1782
std::map< std::string, int > terminations_
Definition: metrics.hpp:77
int most_consecutive_requests_
Definition: metrics.hpp:72
clock_t parsing_time
Definition: metrics.hpp:60
void record_sample(const simple_wml::string_span &name, clock_t parsing_time, clock_t processing_time)
Definition: metrics.cpp:80
friend std::ostream & operator<<(std::ostream &out, metrics &met)
Definition: metrics.cpp:153
int nrequests_waited_
Definition: metrics.hpp:75
GLsizei const GLcharARB ** string
Definition: glew.h:4503