Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log_record.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_OPT_LOGGING_LOG_RECORD_H_
20 #define PAGESPEED_OPT_LOGGING_LOG_RECORD_H_
21 
22 #include <map>
28 #include "pagespeed/kernel/http/image_types.pb.h"
29 #include "pagespeed/opt/logging/enums.pb.h"
32 
37 
38 namespace net_instaweb {
39 
40 class AbstractMutex;
41 class RequestTimingInfo;
42 
56 
60  public:
64  virtual ~AbstractLogRecord();
65 
71 
76  RewriterInfo* NewRewriterInfo(const char* rewriter_id);
77 
81  const char* rewriter_id, RewriterApplication::Status status);
82 
86  const char* rewriter_id, const GoogleString& url,
87  RewriterApplication::Status status) {
88  SetRewriterLoggingStatusHelper(rewriter_id, url, status);
89  }
90 
94  void LogRewriterHtmlStatus(const char* rewriter_id,
95  RewriterHtmlApplication::Status status);
96 
100  const char* rewriter_id, RewriterApplication::Status status);
101 
105  virtual LoggingInfo* logging_info() = 0;
106 
109 
114  RewriterApplication::Status status,
115  const GoogleString& url,
116  const char* id,
117  int original_size,
118  int optimized_size,
119  bool is_recompressed,
120  ImageType original_image_type,
121  ImageType optimized_image_type,
122  bool is_resized,
123  int original_width,
124  int original_height,
125  bool is_resized_using_rendered_dimensions,
126  int resized_width,
127  int resized_height);
128 
130  void SetIsHtml(bool is_html);
131 
134  virtual void AddFoundPropertyToCohortInfo(
135  int page_type, const GoogleString& cohort,
136  const GoogleString& property) = 0;
137 
141  int page_type, const GoogleString& cohort,
142  const GoogleString& property) = 0;
143 
145  virtual void SetCacheStatusForCohortInfo(
146  int page_type, const GoogleString& cohort,
147  bool found, int key_state) = 0;
148 
152  void SetIsOriginalResourceCacheable(bool cacheable);
153 
155  virtual void LogImageRewriteActivity(
156  const char* id,
157  const GoogleString& url,
158  RewriterApplication::Status status,
159  bool is_image_inlined,
160  bool is_critical_image,
161  bool is_url_rewritten,
162  int size,
163  bool try_low_res_src_insertion,
164  bool low_res_src_inserted,
165  ImageType low_res_image_type,
166  int low_res_data_size) = 0;
167 
169  void LogJsDisableFilter(const char* id, bool has_pagespeed_no_defer);
170 
171  void LogLazyloadFilter(const char* id,
172  RewriterApplication::Status status,
173  bool is_blacklisted, bool is_critical);
174 
177  bool WriteLog();
178 
181  AbstractMutex* mutex() { return mutex_.get(); }
182 
185  void SetRewriterInfoMaxSize(int x);
186 
189  void SetAllowLoggingUrls(bool allow_logging_urls);
190 
193  void SetLogUrlIndices(bool log_url_indices);
194 
196  void SetNumHtmlCriticalImages(int num_html_critical_images);
197 
199  void SetNumCssCriticalImages(int num_css_critical_images);
200 
202  virtual void SetImageStats(int num_img_tags, int num_inlined_img_tags,
203  int num_critical_images_used) = 0;
204 
206  virtual void SetResourceCounts(int num_external_css, int num_scripts) = 0;
207 
209  void SetCriticalCssInfo(int critical_inlined_bytes,
210  int original_external_bytes,
211  int overhead_bytes);
212 
214  virtual void LogDeviceInfo(
215  int device_type,
216  bool supports_image_inlining,
217  bool supports_lazyload_images,
218  bool supports_critical_images_beacon,
219  bool supports_deferjs,
220  bool supports_webp_in_place,
221  bool supports_webp_rewritten_urls,
222  bool supports_webplossless_alpha,
223  bool is_bot) = 0;
224 
226  void LogIsXhr(bool is_xhr);
227 
229  virtual void SetBackgroundRewriteInfo(
230  bool log_urls,
231  bool log_url_indices,
232  int max_rewrite_info_log_size);
233 
235  virtual void SetTimingInfo(const RequestTimingInfo& timing_info) {}
236 
237  protected:
240  virtual bool WriteLogImpl() = 0;
241 
245  RewriterInfo* SetRewriterLoggingStatusHelper(
246  const char* rewriter_id, const GoogleString& url,
247  RewriterApplication::Status status);
248 
249  private:
251  void InitLogging();
252 
253  void PopulateUrl(
254  const GoogleString& url, RewriteResourceInfo* rewrite_resource_info);
255 
258  void PopulateRewriterStatusCounts();
259 
263 
265  int rewriter_info_max_size_;
266 
268  bool allow_logging_urls_;
269 
271  bool log_url_indices_;
272 
274  StringIntMap url_index_map_;
275 
277  typedef std::map<RewriterApplication::Status, int> RewriteStatusCountMap;
278  struct RewriterStatsInternal {
279  RewriterHtmlApplication::Status html_status;
280 
282  RewriteStatusCountMap status_counts;
283 
284  RewriterStatsInternal()
285  : html_status(RewriterHtmlApplication::UNKNOWN_STATUS) {}
286  };
287  typedef std::map<GoogleString, RewriterStatsInternal> RewriterStatsMap;
288  RewriterStatsMap rewriter_stats_;
289 
290 
291 };
292 
294 class LogRecord : public AbstractLogRecord {
295  public:
296  explicit LogRecord(AbstractMutex* mutex);
297 
298  virtual ~LogRecord();
299 
300  LoggingInfo* logging_info() { return logging_info_.get(); }
301 
302  virtual void SetImageStats(int num_img_tags, int num_inlined_img_tags,
303  int num_critical_images_used) {}
304 
305  virtual void SetResourceCounts(int num_external_css, int num_scripts) {}
306 
308  int page_type, const GoogleString& cohort,
309  const GoogleString& property) {}
310 
312  int page_type, const GoogleString& cohort,
313  const GoogleString& property) {}
314 
316  int page_type, const GoogleString& cohort, bool found, int key_state) {}
317 
319  const char* id,
320  const GoogleString& url,
321  RewriterApplication::Status status,
322  bool is_image_inlined,
323  bool is_critical_image,
324  bool is_url_rewritten,
325  int size,
326  bool try_low_res_src_insertion,
327  bool low_res_src_inserted,
328  ImageType low_res_image_type,
329  int low_res_data_size) {}
330 
332  int device_type,
333  bool supports_image_inlining,
334  bool supports_lazyload_images,
335  bool supports_critical_images_beacon,
336  bool supports_deferjs,
337  bool supports_webp_in_place,
338  bool supports_webp_rewritten_urls,
339  bool supports_webplossless_alpha,
340  bool is_bot) override {}
341 
342  bool WriteLogImpl() override { return true; }
343 
344  private:
345  scoped_ptr<LoggingInfo> logging_info_;
346 };
347 
355  public:
356  CopyOnWriteLogRecord(AbstractMutex* logging_mutex, LoggingInfo* logging_info)
357  : LogRecord(logging_mutex), logging_info_copy_(logging_info) {}
358 
359  protected:
360  virtual bool WriteLogImpl() {
361  logging_info_copy_->CopyFrom(*logging_info());
362  return true;
363  }
364 
365  private:
366  LoggingInfo* logging_info_copy_;
367 
368 
369 };
370 
371 }
372 
373 #endif
void SetRewriterLoggingStatus(const char *rewriter_id, RewriterApplication::Status status)
void LogImageBackgroundRewriteActivity(RewriterApplication::Status status, const GoogleString &url, const char *id, int original_size, int optimized_size, bool is_recompressed, ImageType original_image_type, ImageType optimized_image_type, bool is_resized, int original_width, int original_height, bool is_resized_using_rendered_dimensions, int resized_width, int resized_height)
void LogRewriterHtmlStatus(const char *rewriter_id, RewriterHtmlApplication::Status status)
Simple AbstractLogRecord implementation which owns a LoggingInfo protobuf.
Definition: log_record.h:294
virtual void AddFoundPropertyToCohortInfo(int page_type, const GoogleString &cohort, const GoogleString &property)=0
RewriterInfo * NewRewriterInfo(const char *rewriter_id)
void SetAllowLoggingUrls(bool allow_logging_urls)
bool WriteLogImpl() override
Definition: log_record.h:342
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
void SetIsHtml(bool is_html)
Atomically sets is_html_response in the logging proto.
virtual void SetTimingInfo(const RequestTimingInfo &timing_info)
Set timing information in the logging implementation.
Definition: log_record.h:235
void LogJsDisableFilter(const char *id, bool has_pagespeed_no_defer)
Definition: log_record.h:59
void SetLogUrlIndices(bool log_url_indices)
void SetRewriterLoggingStatus(const char *rewriter_id, const GoogleString &url, RewriterApplication::Status status)
Definition: log_record.h:85
virtual void SetResourceCounts(int num_external_css, int num_scripts)
Sets the number of external resources on an HTML page.
Definition: log_record.h:305
virtual void AddRetrievedPropertyToCohortInfo(int page_type, const GoogleString &cohort, const GoogleString &property)
Definition: log_record.h:311
Definition: scoped_ptr.h:30
virtual bool WriteLogImpl()
Definition: log_record.h:360
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: request_timing_info.h:43
void SetIsOriginalResourceCacheable(bool cacheable)
virtual void LogImageRewriteActivity(const char *id, const GoogleString &url, RewriterApplication::Status status, bool is_image_inlined, bool is_critical_image, bool is_url_rewritten, int size, bool try_low_res_src_insertion, bool low_res_src_inserted, ImageType low_res_image_type, int low_res_data_size)=0
Log a RewriterInfo for the image rewrite filter.
virtual void SetResourceCounts(int num_external_css, int num_scripts)=0
Sets the number of external resources on an HTML page.
virtual void SetCacheStatusForCohortInfo(int page_type, const GoogleString &cohort, bool found, int key_state)=0
Updates the cohort info to update the cache key state.
GoogleString AppliedRewritersString()
void SetCriticalCssInfo(int critical_inlined_bytes, int original_external_bytes, int overhead_bytes)
Sets critical CSS related byte counts (all uncompressed).
AbstractMutex * mutex()
Definition: log_record.h:181
virtual void AddFoundPropertyToCohortInfo(int page_type, const GoogleString &cohort, const GoogleString &property)
Definition: log_record.h:307
virtual LoggingInfo * logging_info()=0
void SetNumCssCriticalImages(int num_css_critical_images)
Sets the number of critical images in CSS.
virtual void SetImageStats(int num_img_tags, int num_inlined_img_tags, int num_critical_images_used)=0
Sets image related statistics.
virtual void SetImageStats(int num_img_tags, int num_inlined_img_tags, int num_critical_images_used)
Sets image related statistics.
Definition: log_record.h:302
void LogIsXhr(bool is_xhr)
Log whether the request is an XmlHttpRequest.
void SetNumHtmlCriticalImages(int num_html_critical_images)
Sets the number of critical images in HTML.
void LogRewriterApplicationStatus(const char *rewriter_id, RewriterApplication::Status status)
virtual void AddRetrievedPropertyToCohortInfo(int page_type, const GoogleString &cohort, const GoogleString &property)=0
void LogDeviceInfo(int device_type, bool supports_image_inlining, bool supports_lazyload_images, bool supports_critical_images_beacon, bool supports_deferjs, bool supports_webp_in_place, bool supports_webp_rewritten_urls, bool supports_webplossless_alpha, bool is_bot) override
Log information related to the user agent and device making the request.
Definition: log_record.h:331
virtual void LogDeviceInfo(int device_type, bool supports_image_inlining, bool supports_lazyload_images, bool supports_critical_images_beacon, bool supports_deferjs, bool supports_webp_in_place, bool supports_webp_rewritten_urls, bool supports_webplossless_alpha, bool is_bot)=0
Log information related to the user agent and device making the request.
LoggingInfo * logging_info()
Definition: log_record.h:300
AbstractLogRecord(AbstractMutex *mutex)
Definition: log_record.h:354
virtual void LogImageRewriteActivity(const char *id, const GoogleString &url, RewriterApplication::Status status, bool is_image_inlined, bool is_critical_image, bool is_url_rewritten, int size, bool try_low_res_src_insertion, bool low_res_src_inserted, ImageType low_res_image_type, int low_res_data_size)
Log a RewriterInfo for the image rewrite filter.
Definition: log_record.h:318
RewriterInfo * SetRewriterLoggingStatusHelper(const char *rewriter_id, const GoogleString &url, RewriterApplication::Status status)
void SetCacheStatusForCohortInfo(int page_type, const GoogleString &cohort, bool found, int key_state)
Updates the cohort info to update the cache key state.
Definition: log_record.h:315
virtual void SetBackgroundRewriteInfo(bool log_urls, bool log_url_indices, int max_rewrite_info_log_size)
Sets initial information for background rewrite log.