OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/dom_distiller/core/distiller_page.h" | 5 #include "components/dom_distiller/core/distiller_page.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 81 |
82 void DistillerPage::DistillPage( | 82 void DistillerPage::DistillPage( |
83 const GURL& gurl, | 83 const GURL& gurl, |
84 const dom_distiller::proto::DomDistillerOptions options, | 84 const dom_distiller::proto::DomDistillerOptions options, |
85 const DistillerPageCallback& callback) { | 85 const DistillerPageCallback& callback) { |
86 DCHECK(ready_); | 86 DCHECK(ready_); |
87 // It is only possible to distill one page at a time. |ready_| is reset when | 87 // It is only possible to distill one page at a time. |ready_| is reset when |
88 // the callback to OnDistillationDone happens. | 88 // the callback to OnDistillationDone happens. |
89 ready_ = false; | 89 ready_ = false; |
90 distiller_page_callback_ = callback; | 90 distiller_page_callback_ = callback; |
91 distillation_start_ = base::TimeTicks::Now(); | |
91 DistillPageImpl(gurl, GetDistillerScriptWithOptions(options, | 92 DistillPageImpl(gurl, GetDistillerScriptWithOptions(options, |
92 StringifyOutput(), | 93 StringifyOutput(), |
93 CreateNewContext())); | 94 CreateNewContext())); |
94 } | 95 } |
95 | 96 |
96 void DistillerPage::OnDistillationDone(const GURL& page_url, | 97 void DistillerPage::OnDistillationDone(const GURL& page_url, |
97 const base::Value* value) { | 98 const base::Value* value) { |
98 DCHECK(!ready_); | 99 DCHECK(!ready_); |
99 ready_ = true; | 100 ready_ = true; |
100 | 101 |
101 scoped_ptr<dom_distiller::proto::DomDistillerResult> distiller_result( | 102 scoped_ptr<dom_distiller::proto::DomDistillerResult> distiller_result( |
102 new dom_distiller::proto::DomDistillerResult()); | 103 new dom_distiller::proto::DomDistillerResult()); |
103 bool found_content; | 104 bool found_content; |
104 if (value->IsType(base::Value::TYPE_NULL)) { | 105 if (value->IsType(base::Value::TYPE_NULL)) { |
105 found_content = false; | 106 found_content = false; |
106 } else { | 107 } else { |
107 found_content = | 108 found_content = |
108 dom_distiller::proto::json::DomDistillerResult::ReadFromValue( | 109 dom_distiller::proto::json::DomDistillerResult::ReadFromValue( |
109 value, distiller_result.get()); | 110 value, distiller_result.get()); |
110 if (!found_content) { | 111 if (!found_content) { |
111 DVLOG(1) << "Unable to parse DomDistillerResult."; | 112 DVLOG(1) << "Unable to parse DomDistillerResult."; |
112 } else { | 113 } else { |
114 base::TimeDelta distillation_time = | |
115 base::TimeTicks::Now() - distillation_start_; | |
116 UMA_HISTOGRAM_TIMES("DomDistiller.Time.DistillPage", distillation_time); | |
117 VLOG(1) << "DomDistiller.Time.DistillPage = " << distillation_time; | |
Mark P
2015/05/11 18:27:10
minor comment: do you actually need these VLOGs ar
wychen
2015/05/11 20:42:49
Thanks for your review! I used LOG(ERROR) locally
| |
118 | |
113 if (distiller_result->has_timing_info()) { | 119 if (distiller_result->has_timing_info()) { |
114 const dom_distiller::proto::TimingInfo& timing = | 120 const dom_distiller::proto::TimingInfo& timing = |
115 distiller_result->timing_info(); | 121 distiller_result->timing_info(); |
116 if (timing.has_markup_parsing_time()) { | 122 if (timing.has_markup_parsing_time()) { |
117 UMA_HISTOGRAM_TIMES( | 123 UMA_HISTOGRAM_TIMES( |
118 "DomDistiller.Time.MarkupParsing", | 124 "DomDistiller.Time.MarkupParsing", |
119 base::TimeDelta::FromMillisecondsD(timing.markup_parsing_time())); | 125 base::TimeDelta::FromMillisecondsD(timing.markup_parsing_time())); |
120 } | 126 } |
121 if (timing.has_document_construction_time()) { | 127 if (timing.has_document_construction_time()) { |
122 UMA_HISTOGRAM_TIMES( | 128 UMA_HISTOGRAM_TIMES( |
123 "DomDistiller.Time.DocumentConstruction", | 129 "DomDistiller.Time.DocumentConstruction", |
124 base::TimeDelta::FromMillisecondsD( | 130 base::TimeDelta::FromMillisecondsD( |
125 timing.document_construction_time())); | 131 timing.document_construction_time())); |
126 } | 132 } |
127 if (timing.has_article_processing_time()) { | 133 if (timing.has_article_processing_time()) { |
128 UMA_HISTOGRAM_TIMES( | 134 UMA_HISTOGRAM_TIMES( |
129 "DomDistiller.Time.ArticleProcessing", | 135 "DomDistiller.Time.ArticleProcessing", |
130 base::TimeDelta::FromMillisecondsD( | 136 base::TimeDelta::FromMillisecondsD( |
131 timing.article_processing_time())); | 137 timing.article_processing_time())); |
132 } | 138 } |
133 if (timing.has_formatting_time()) { | 139 if (timing.has_formatting_time()) { |
134 UMA_HISTOGRAM_TIMES( | 140 UMA_HISTOGRAM_TIMES( |
135 "DomDistiller.Time.Formatting", | 141 "DomDistiller.Time.Formatting", |
136 base::TimeDelta::FromMillisecondsD(timing.formatting_time())); | 142 base::TimeDelta::FromMillisecondsD(timing.formatting_time())); |
137 } | 143 } |
138 if (timing.has_total_time()) { | 144 if (timing.has_total_time()) { |
139 UMA_HISTOGRAM_TIMES( | 145 UMA_HISTOGRAM_TIMES( |
140 "DomDistiller.Time.DistillationTotal", | 146 "DomDistiller.Time.DistillationTotal", |
141 base::TimeDelta::FromMillisecondsD(timing.total_time())); | 147 base::TimeDelta::FromMillisecondsD(timing.total_time())); |
148 VLOG(1) << "DomDistiller.Time.DistillationTotal = " << | |
149 base::TimeDelta::FromMillisecondsD(timing.total_time()); | |
142 } | 150 } |
143 } | 151 } |
144 if (distiller_result->has_statistics_info()) { | 152 if (distiller_result->has_statistics_info()) { |
145 const dom_distiller::proto::StatisticsInfo& statistics = | 153 const dom_distiller::proto::StatisticsInfo& statistics = |
146 distiller_result->statistics_info(); | 154 distiller_result->statistics_info(); |
147 if (statistics.has_word_count()) { | 155 if (statistics.has_word_count()) { |
148 UMA_HISTOGRAM_CUSTOM_COUNTS( | 156 UMA_HISTOGRAM_CUSTOM_COUNTS( |
149 "DomDistiller.Statistics.WordCount", | 157 "DomDistiller.Statistics.WordCount", |
150 statistics.word_count(), | 158 statistics.word_count(), |
151 1, 4000, 50); | 159 1, 4000, 50); |
152 } | 160 } |
153 } | 161 } |
154 } | 162 } |
155 } | 163 } |
156 | 164 |
157 base::MessageLoop::current()->PostTask( | 165 base::MessageLoop::current()->PostTask( |
158 FROM_HERE, | 166 FROM_HERE, |
159 base::Bind(distiller_page_callback_, | 167 base::Bind(distiller_page_callback_, |
160 base::Passed(&distiller_result), | 168 base::Passed(&distiller_result), |
161 found_content)); | 169 found_content)); |
162 } | 170 } |
163 | 171 |
164 } // namespace dom_distiller | 172 } // namespace dom_distiller |
OLD | NEW |