2
* Copyright 2012 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
// Author: jmarantz@google.com (Joshua Marantz)
19
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
20
#define NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
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"
27
namespace net_instaweb {
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 {
38
explicit DebugFilter(RewriteDriver* driver);
39
virtual ~DebugFilter();
41
virtual void EndDocument();
44
virtual const char* Name() const { return "Debug"; }
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.
58
virtual void EndElement(HtmlElement* element);
60
// Formats Flush/EndOfDocument messages that will be easy to read from
61
// View->PageSource in a browser.
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
77
GoogleString ListActiveFiltersAndOptions() const;
80
// Tracks duration of events of interest that may occur multiple times
81
// during an HTML rewrite.
86
inline void Start(int64 now_us);
87
inline void End(int64 now_us);
88
inline void AddToTotal();
90
int64 start_us() const { return start_us_; }
91
int64 duration_us() const { return duration_us_; }
92
int64 total_us() const { return total_us_; }
102
RewriteDriver* driver_;
104
bool end_document_seen_; // Set at EndOfDocument, checked at Flush.
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_;
112
// The buffered flush messages this filter generates for a flush in a literal
114
GoogleString flush_messages_;
116
StringVector dynamically_disabled_filter_list_;
118
DISALLOW_COPY_AND_ASSIGN(DebugFilter);
121
} // namespace net_instaweb
123
#endif // NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_