server/metrics.hpp

Go to the documentation of this file.
00001 /* $Id: metrics.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2003 - 2012 by David White <dave@whitevine.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /** @file */
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:09 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs