alaCarte Maps
Renderer for OpenStreetMap tiles
statistic.hpp
Go to the documentation of this file.
1 
21 #pragma once
22 #ifndef STATISTIC_HPP
23 #define STATISTIC_HPP
24 
25 #include <settings.hpp>
26 #include <boost/thread/mutex.hpp>
27 
28 class Configuration;
29 
30 class Statistic
31 {
32 public:
33  typedef boost::posix_time::time_duration duration;
34  typedef boost::posix_time::ptime ptime;
35 
36  enum Component{
37  //Change the order of the following Components will change the output order (file and log),
38  //you have to update /alacarte/doc/statistics/stat2html.py
39  Cache = 0,
48  Size //amount of Components
49  };
50 
51 
53  friend class Statistic;
54  public:
55  JobMeasurement() = default;
56  JobMeasurement(const string& stylesheet, int zoom)
57  : stylesheet(stylesheet), zoom(zoom), nodes(0), ways(0), relations(0)
58  {
59  for(int i = 0; i < Component::Size; i++) {
60  stopped[i] = false;
61  }
62  };
63  duration getDuration(int i);
64  private:
65  uint16_t zoom;
66  uint32_t nodes;
67  uint32_t ways;
68  uint32_t relations;
69  string stylesheet;
70  bool stopped[Component::Size];
71  ptime jobStartTime;
72  ptime startTime[Component::Size];
73  ptime stopTime[Component::Size];
74  };
75 
76  shared_ptr<JobMeasurement> startNewMeasurement(const string& stylesheet, int zoom);
77  void start(shared_ptr<Statistic::JobMeasurement>& job, Component component) const;
78  void stop(shared_ptr<Statistic::JobMeasurement>& job, Component component) const;
79  void finished(shared_ptr<Statistic::JobMeasurement>& job);
80  void setStats(shared_ptr<Statistic::JobMeasurement>& job, unsigned int nodes, unsigned int ways, unsigned int relations);
81  void printStatistic() const;
82 
83  static const shared_ptr<Statistic>& Get()
84  {
85  assert(instance);
86  return instance;
87  }
88 
89  static void Init(const shared_ptr<Configuration>& conf)
90  {
91  instance = shared_ptr<Statistic>(new Statistic(conf));
92  }
93 
94 
95  ~Statistic();
96 private:
97  void writeToFile(const char* filename);
98  string componentToName(Component component) const;
99 
100  Statistic(const shared_ptr<Configuration>& config);
101  Statistic(const Statistic&){};
102 
103  static shared_ptr<Statistic> instance;
104 
105 private:
106  shared_ptr<Configuration> config;
107  boost::mutex bufferLock;
108  std::vector<shared_ptr<JobMeasurement>> measurementsBuffer;
109 
111  {
112  // for every zoomlevel an average value
113  uint32_t count[19];
114  float average[19];
115  };
116  boost::mutex avgLock;
117  AvgMeasurement componentAvgs[Component::Size];
118 };
119 
120 #endif
shared_ptr< Configuration > config
Definition: statistic.hpp:106
string componentToName(Component component) const
Definition: statistic.cpp:161
void stop(shared_ptr< Statistic::JobMeasurement > &job, Component component) const
Definition: statistic.cpp:79
shared_ptr< JobMeasurement > startNewMeasurement(const string &stylesheet, int zoom)
Definition: statistic.cpp:52
void setStats(shared_ptr< Statistic::JobMeasurement > &job, unsigned int nodes, unsigned int ways, unsigned int relations)
Definition: statistic.cpp:61
boost::posix_time::time_duration duration
Definition: statistic.hpp:33
void start(shared_ptr< Statistic::JobMeasurement > &job, Component component) const
Definition: statistic.cpp:72
boost::posix_time::ptime ptime
Definition: statistic.hpp:34
void finished(shared_ptr< Statistic::JobMeasurement > &job)
Definition: statistic.cpp:110
std::vector< shared_ptr< JobMeasurement > > measurementsBuffer
Definition: statistic.hpp:108
ptime stopTime[Component::Size]
Definition: statistic.hpp:73
ptime startTime[Component::Size]
Definition: statistic.hpp:72
AvgMeasurement componentAvgs[Component::Size]
Definition: statistic.hpp:117
boost::mutex bufferLock
Definition: statistic.hpp:107
static shared_ptr< Statistic > instance
This file is part of alaCarte.
Definition: statistic.hpp:101
static const shared_ptr< Statistic > & Get()
Definition: statistic.hpp:83
void writeToFile(const char *filename)
Definition: statistic.cpp:142
boost::mutex avgLock
Definition: statistic.hpp:116
JobMeasurement(const string &stylesheet, int zoom)
Definition: statistic.hpp:56
Represents a set of options accessible via strings.
static void Init(const shared_ptr< Configuration > &conf)
Definition: statistic.hpp:89
Statistic(const Statistic &)
Definition: statistic.hpp:101
duration getDuration(int i)
Definition: statistic.cpp:30
void printStatistic() const
Definition: statistic.cpp:86
Definition: cache.hpp:38
bool stopped[Component::Size]
Definition: statistic.hpp:70