Page Speed Optimization Libraries  1.8.31.2
net/instaweb/rewriter/public/debug_filter.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
00021 
00022 #include "net/instaweb/htmlparse/public/empty_html_filter.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/string.h"
00025 
00026 namespace net_instaweb {
00027 
00028 class HtmlElement;
00029 class RewriteDriver;
00030 class Timer;
00031 
00035 class DebugFilter : public EmptyHtmlFilter {
00036  public:
00037   explicit DebugFilter(RewriteDriver* driver);
00038   virtual ~DebugFilter();
00039 
00040   virtual void EndDocument();
00041   virtual void Flush();
00042 
00043   virtual const char* Name() const { return "Debug"; }
00044 
00051   void InitParse();
00052   void StartParse();
00053   void EndParse();
00054   void StartRender();
00055   void EndRender();
00056 
00057   virtual void EndElement(HtmlElement* element);
00058 
00064   static GoogleString FormatFlushMessage(int64 time_since_init_parse_us,
00065                                          int64 parse_duration_us,
00066                                          int64 flush_duration_us,
00067                                          int64 idle_duration_us);
00068   static GoogleString FormatEndDocumentMessage(int64 time_since_init_parse_us,
00069                                                int64 total_parse_duration_us,
00070                                                int64 total_flush_duration_us,
00071                                                int64 total_idle_duration_us,
00072                                                int num_flushes);
00073 
00074  private:
00077   class Event {
00078    public:
00079     Event();
00080     inline void Clear();
00081     inline void Start(int64 now_us);
00082     inline void End(int64 now_us);
00083     inline void AddToTotal();
00084 
00085     int64 start_us() const { return start_us_; }
00086     int64 duration_us() const { return duration_us_; }
00087     int64 total_us() const { return total_us_; }
00088 
00089    private:
00090     int64 start_us_;
00091     int64 duration_us_;
00092     int64 total_us_;
00093   };
00094 
00095   void Clear();
00096 
00097   RewriteDriver* driver_;
00098   Timer* timer_;
00099   bool end_document_seen_; 
00100   int num_flushes_;
00101   int64 start_doc_time_us_; 
00102   Event parse_; 
00103   Event render_; 
00104   Event idle_; 
00105 
00108   GoogleString flush_messages_;
00109 
00110   DISALLOW_COPY_AND_ASSIGN(DebugFilter);
00111 };
00112 
00113 }  
00114 
00115 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_DEBUG_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines