Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef METRICS_HPP_INCLUDED
00019 #define METRICS_HPP_INCLUDED
00020
00021 #include <iosfwd>
00022
00023 #include <map>
00024 #include <string>
00025 #ifdef _WIN32
00026 #include <time.h>
00027 #endif
00028
00029 #include "simple_wml.hpp"
00030
00031 class metrics
00032 {
00033 public:
00034 metrics();
00035 ~metrics();
00036
00037 void service_request();
00038 void no_requests();
00039
00040 void record_sample(const simple_wml::string_span& name,
00041 clock_t parsing_time, clock_t processing_time);
00042
00043 void game_terminated(const std::string& reason);
00044
00045 std::ostream& games(std::ostream& out) const;
00046 std::ostream& requests(std::ostream& out) const;
00047 friend std::ostream& operator<<(std::ostream& out, metrics& met);
00048
00049 struct sample {
00050
00051 sample() :
00052 name(),
00053 nsamples(0),
00054 parsing_time(0),
00055 processing_time(0),
00056 max_parsing_time(0),
00057 max_processing_time(0)
00058 {
00059 }
00060
00061 simple_wml::string_span name;
00062 int nsamples;
00063 clock_t parsing_time, processing_time;
00064 clock_t max_parsing_time, max_processing_time;
00065
00066 operator const simple_wml::string_span&()
00067 {
00068 return name;
00069 }
00070 };
00071
00072 private:
00073 std::vector<sample> samples_;
00074
00075 int most_consecutive_requests_;
00076 int current_requests_;
00077 int nrequests_;
00078 int nrequests_waited_;
00079 const time_t started_at_;
00080 std::map<std::string,int> terminations_;
00081 };
00082
00083 std::ostream& operator<<(std::ostream& out, metrics& met);
00084
00085 #endif