Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
statistics_logger.h
Go to the documentation of this file.
1 // Copyright 2013 Google Inc. All Rights Reserved.
17 
18 #ifndef PAGESPEED_KERNEL_BASE_STATISTICS_LOGGER_H_
19 #define PAGESPEED_KERNEL_BASE_STATISTICS_LOGGER_H_
20 
21 #include <cstddef>
22 #include <map>
23 #include <utility>
24 #include <vector>
25 
30 
31 namespace net_instaweb {
32 
33 class MessageHandler;
34 class MutexedScalar;
35 class Statistics;
36 class StatisticsLogfileReader;
37 class Timer;
38 class UpDownCounter;
39 class Variable;
40 class Writer;
41 
43  public:
46  int64 update_interval_ms, int64 max_logfile_size_kb,
47  const StringPiece& log_file, MutexedScalar* last_dump_timestamp,
48  MessageHandler* message_handler, Statistics* stats,
49  FileSystem* file_system, Timer* timer);
51 
56  void DumpJSON(bool dump_for_graphs, const StringSet& var_titles,
57  int64 start_time, int64 end_time, int64 granularity_ms,
58  Writer* writer, MessageHandler* message_handler) const;
59 
63 
65  void TrimLogfileIfNeeded();
66 
72  void Init();
73 
74  private:
75  friend class StatisticsLoggerTest;
76 
77  typedef std::vector<GoogleString> VariableInfo;
78  typedef std::map<GoogleString, VariableInfo> VarMap;
79 
83  typedef std::pair<Variable*, UpDownCounter*> VariableOrCounter;
84  typedef std::map<StringPiece, VariableOrCounter> VariableMap;
85 
88  void DumpConsoleVarsToWriter(int64 current_time_ms, Writer* writer);
90  void ParseDataFromReader(const StringSet& var_titles,
92  std::vector<int64>* list_of_timestamps,
93  VarMap* parsed_var_data) const;
95  void ParseDataForGraphs(StatisticsLogfileReader* reader,
96  std::vector<int64>* list_of_timestamps,
97  VarMap* parsed_var_data) const;
101  void ParseVarDataIntoMap(StringPiece logfile_var_data,
102  std::map<StringPiece, StringPiece>* parsed_var_data)
103  const;
104  void PrintVarDataAsJSON(const VarMap& parsed_var_data, Writer* writer,
105  MessageHandler* message_handler) const;
106  void PrintTimestampListAsJSON(const std::vector<int64>& list_of_timestamps,
107  Writer* writer,
108  MessageHandler* message_handler) const;
109  void PrintJSON(const std::vector<int64>& list_of_timestamps,
110  const VarMap& parsed_var_data,
111  Writer* writer, MessageHandler* message_handler) const;
112  void AddVariable(StringPiece var_name);
113 
116  void InitStatsForTest();
117 
120  MutexedScalar* last_dump_timestamp_;
121  MessageHandler* message_handler_;
122  Statistics* statistics_;
123  FileSystem* file_system_;
126  Timer* timer_;
127  const int64 update_interval_ms_;
128  const int64 max_logfile_size_kb_;
129  GoogleString logfile_name_;
130  VariableMap variables_to_log_;
131 
132 
133 };
134 
137  public:
138  StatisticsLogfileReader(FileSystem::InputFile* file, int64 start_time,
139  int64 end_time, int64 granularity_ms,
140  MessageHandler* message_handler);
142 
148  bool ReadNextDataBlock(int64* timestamp, GoogleString* data);
149  int64 end_time() { return end_time_; }
150 
151  private:
153  size_t BufferFind(const char* search_for, size_t start_at);
154  int FeedBuffer();
155 
156  FileSystem::InputFile* file_;
157  int64 start_time_;
158  int64 end_time_;
159  int64 granularity_ms_;
160  MessageHandler* message_handler_;
162  GoogleString buffer_;
163 
164 
165 };
166 
167 }
168 
169 #endif
bool ReadNextDataBlock(int64 *timestamp, GoogleString *data)
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: file_system.h:76
Handles reading the logfile created by StatisticsLogger.
Definition: statistics_logger.h:136
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: file_system.h:96
void DumpJSON(bool dump_for_graphs, const StringSet &var_titles, int64 start_time, int64 end_time, int64 granularity_ms, Writer *writer, MessageHandler *message_handler) const
Definition: statistics.h:112
Definition: message_handler.h:39
void TrimLogfileIfNeeded()
Trim file down if it gets above max_logfile_size_kb.
StatisticsLogger(int64 update_interval_ms, int64 max_logfile_size_kb, const StringPiece &log_file, MutexedScalar *last_dump_timestamp, MessageHandler *message_handler, Statistics *stats, FileSystem *file_system, Timer *timer)
Does not take ownership of any objects passed in.
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: statistics_logger.h:42