~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/debug_filter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: jmarantz@google.com (Joshua Marantz)
18
 
 
19
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
20
 
#define NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
21
 
 
22
 
#include "net/instaweb/htmlparse/public/empty_html_filter.h"
23
 
#include "net/instaweb/util/public/basictypes.h"
24
 
#include "net/instaweb/util/public/string.h"
25
 
#include "pagespeed/kernel/base/string_util.h"
26
 
 
27
 
namespace net_instaweb {
28
 
 
29
 
class HtmlElement;
30
 
class RewriteDriver;
31
 
class Timer;
32
 
 
33
 
// Injects HTML comments for measuring the time it takes to parse HTML,
34
 
// run the Flush/Render sequence, and the idle-time between text blocks.
35
 
// Data is written into the HTML as comments.
36
 
class DebugFilter : public EmptyHtmlFilter {
37
 
 public:
38
 
  explicit DebugFilter(RewriteDriver* driver);
39
 
  virtual ~DebugFilter();
40
 
 
41
 
  virtual void EndDocument();
42
 
  virtual void Flush();
43
 
 
44
 
  virtual const char* Name() const { return "Debug"; }
45
 
 
46
 
  // Special entry-points needed for measuring timing.  The timing
47
 
  // of StartDocument/EndDocument does not capture the correct timing,
48
 
  // and changing them so they do would alter functionality depended
49
 
  // upon by numerous filters.  So we have special entry-points for
50
 
  // this filter called directly by RewriteDriver.  This can be generalized
51
 
  // in the future if these entry-points prove useful.
52
 
  void InitParse();
53
 
  void StartParse();
54
 
  void EndParse();
55
 
  void StartRender();
56
 
  void EndRender();
57
 
 
58
 
  virtual void EndElement(HtmlElement* element);
59
 
 
60
 
  // Formats Flush/EndOfDocument messages that will be easy to read from
61
 
  // View->PageSource in a browser.
62
 
  //
63
 
  // They are exposed for testing, so that unit tests are not concerned with
64
 
  // the exact formatting of those messages.
65
 
  static GoogleString FormatFlushMessage(int64 time_since_init_parse_us,
66
 
                                         int64 parse_duration_us,
67
 
                                         int64 flush_duration_us,
68
 
                                         int64 idle_duration_us);
69
 
  static GoogleString FormatEndDocumentMessage(
70
 
      int64 time_since_init_parse_us, int64 total_parse_duration_us,
71
 
      int64 total_flush_duration_us, int64 total_idle_duration_us,
72
 
      int num_flushes, bool is_critical_images_beacon_enabled,
73
 
      const StringSet& critical_image_urls,
74
 
      const StringVector& dynamically_disabled_filter_list);
75
 
  // Gets the list of active filters from the RewriteDriver for logging to debug
76
 
  // message.
77
 
  GoogleString ListActiveFiltersAndOptions() const;
78
 
 
79
 
 private:
80
 
  // Tracks duration of events of interest that may occur multiple times
81
 
  // during an HTML rewrite.
82
 
  class Event {
83
 
   public:
84
 
    Event();
85
 
    inline void Clear();
86
 
    inline void Start(int64 now_us);
87
 
    inline void End(int64 now_us);
88
 
    inline void AddToTotal();
89
 
 
90
 
    int64 start_us() const { return start_us_; }
91
 
    int64 duration_us() const { return duration_us_; }
92
 
    int64 total_us() const { return total_us_; }
93
 
 
94
 
   private:
95
 
    int64 start_us_;
96
 
    int64 duration_us_;
97
 
    int64 total_us_;
98
 
  };
99
 
 
100
 
  void Clear();
101
 
 
102
 
  RewriteDriver* driver_;
103
 
  Timer* timer_;
104
 
  bool end_document_seen_;   // Set at EndOfDocument, checked at Flush.
105
 
  int num_flushes_;
106
 
  int64 start_doc_time_us_;  // Established at InitParse.
107
 
  Event parse_;              // Tracks how much time is spent parsing.
108
 
  Event render_;             // Tracks how much time is spent rendering.
109
 
  Event idle_;               // Tracks how much time is spent waiting.
110
 
  StringSet critical_image_urls_;
111
 
 
112
 
  // The buffered flush messages this filter generates for a flush in a literal
113
 
  // tag.
114
 
  GoogleString flush_messages_;
115
 
 
116
 
  StringVector dynamically_disabled_filter_list_;
117
 
 
118
 
  DISALLOW_COPY_AND_ASSIGN(DebugFilter);
119
 
};
120
 
 
121
 
}  // namespace net_instaweb
122
 
 
123
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_