Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: tools/gn/trace.cc

Issue 216903004: Add optional public header checking to GN build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/trace.h ('k') | tools/gn/variables.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "tools/gn/trace.h" 5 #include "tools/gn/trace.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <sstream> 9 #include <sstream>
10 #include <vector> 10 #include <vector>
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 std::string SummarizeTraces() { 178 std::string SummarizeTraces() {
179 if (!trace_log) 179 if (!trace_log)
180 return std::string(); 180 return std::string();
181 181
182 std::vector<TraceItem*> events = trace_log->events(); 182 std::vector<TraceItem*> events = trace_log->events();
183 183
184 // Classify all events. 184 // Classify all events.
185 std::vector<const TraceItem*> parses; 185 std::vector<const TraceItem*> parses;
186 std::vector<const TraceItem*> file_execs; 186 std::vector<const TraceItem*> file_execs;
187 std::vector<const TraceItem*> script_execs; 187 std::vector<const TraceItem*> script_execs;
188 std::vector<const TraceItem*> check_headers;
189 int headers_checked = 0;
188 for (size_t i = 0; i < events.size(); i++) { 190 for (size_t i = 0; i < events.size(); i++) {
189 switch (events[i]->type()) { 191 switch (events[i]->type()) {
190 case TraceItem::TRACE_FILE_PARSE: 192 case TraceItem::TRACE_FILE_PARSE:
191 parses.push_back(events[i]); 193 parses.push_back(events[i]);
192 break; 194 break;
193 case TraceItem::TRACE_FILE_EXECUTE: 195 case TraceItem::TRACE_FILE_EXECUTE:
194 file_execs.push_back(events[i]); 196 file_execs.push_back(events[i]);
195 break; 197 break;
196 case TraceItem::TRACE_SCRIPT_EXECUTE: 198 case TraceItem::TRACE_SCRIPT_EXECUTE:
197 script_execs.push_back(events[i]); 199 script_execs.push_back(events[i]);
198 break; 200 break;
201 case TraceItem::TRACE_CHECK_HEADERS:
202 check_headers.push_back(events[i]);
203 break;
204 case TraceItem::TRACE_CHECK_HEADER:
205 headers_checked++;
206 break;
199 case TraceItem::TRACE_FILE_LOAD: 207 case TraceItem::TRACE_FILE_LOAD:
200 case TraceItem::TRACE_FILE_WRITE: 208 case TraceItem::TRACE_FILE_WRITE:
201 case TraceItem::TRACE_DEFINE_TARGET: 209 case TraceItem::TRACE_DEFINE_TARGET:
202 break; // Ignore these for the summary. 210 break; // Ignore these for the summary.
203 } 211 }
204 } 212 }
205 213
206 std::ostringstream out; 214 std::ostringstream out;
207 SummarizeParses(parses, out); 215 SummarizeParses(parses, out);
208 out << std::endl; 216 out << std::endl;
209 SummarizeFileExecs(file_execs, out); 217 SummarizeFileExecs(file_execs, out);
210 out << std::endl; 218 out << std::endl;
211 SummarizeScriptExecs(script_execs, out); 219 SummarizeScriptExecs(script_execs, out);
212 out << std::endl; 220 out << std::endl;
213 221
222 // Generally there will only be one header check, but it's theoretically
223 // possible for more than one to run if more than one build is going in
224 // parallel. Just report the total of all of them.
225 if (!check_headers.empty()) {
226 float check_headers_time = 0;
227 for (size_t i = 0; i < check_headers.size(); i++)
228 check_headers_time += check_headers[i]->delta().InMillisecondsF();
229
230 out << "Header check time: (total time in ms, files checked)\n";
231 out << base::StringPrintf(" %8.2f %d\n",
232 check_headers_time, headers_checked);
233 }
234
214 return out.str(); 235 return out.str();
215 } 236 }
216 237
217 void SaveTraces(const base::FilePath& file_name) { 238 void SaveTraces(const base::FilePath& file_name) {
218 std::ostringstream out; 239 std::ostringstream out;
219 240
220 out << "{\"traceEvents\":["; 241 out << "{\"traceEvents\":[";
221 242
222 std::string quote_buffer; // Allocate outside loop to prevent reallocationg. 243 std::string quote_buffer; // Allocate outside loop to prevent reallocationg.
223 244
(...skipping 30 matching lines...) Expand all
254 out << "\"file_exec\""; 275 out << "\"file_exec\"";
255 break; 276 break;
256 case TraceItem::TRACE_FILE_WRITE: 277 case TraceItem::TRACE_FILE_WRITE:
257 out << "\"file_write\""; 278 out << "\"file_write\"";
258 break; 279 break;
259 case TraceItem::TRACE_SCRIPT_EXECUTE: 280 case TraceItem::TRACE_SCRIPT_EXECUTE:
260 out << "\"script_exec\""; 281 out << "\"script_exec\"";
261 break; 282 break;
262 case TraceItem::TRACE_DEFINE_TARGET: 283 case TraceItem::TRACE_DEFINE_TARGET:
263 out << "\"define\""; 284 out << "\"define\"";
285 break;
286 case TraceItem::TRACE_CHECK_HEADER:
287 out << "\"hdr\"";
288 break;
289 case TraceItem::TRACE_CHECK_HEADERS:
290 out << "\"header_check\"";
291 break;
264 } 292 }
265 293
266 if (!item.toolchain().empty() || !item.cmdline().empty()) { 294 if (!item.toolchain().empty() || !item.cmdline().empty()) {
267 out << ",\"args\":{"; 295 out << ",\"args\":{";
268 bool needs_comma = false; 296 bool needs_comma = false;
269 if (!item.toolchain().empty()) { 297 if (!item.toolchain().empty()) {
270 quote_buffer.resize(0); 298 quote_buffer.resize(0);
271 base::EscapeJSONString(item.toolchain(), true, &quote_buffer); 299 base::EscapeJSONString(item.toolchain(), true, &quote_buffer);
272 out << "\"toolchain\":" << quote_buffer; 300 out << "\"toolchain\":" << quote_buffer;
273 needs_comma = true; 301 needs_comma = true;
(...skipping 10 matching lines...) Expand all
284 } 312 }
285 out << "}"; 313 out << "}";
286 } 314 }
287 315
288 out << "]}"; 316 out << "]}";
289 317
290 std::string out_str = out.str(); 318 std::string out_str = out.str();
291 base::WriteFile(file_name, out_str.data(), 319 base::WriteFile(file_name, out_str.data(),
292 static_cast<int>(out_str.size())); 320 static_cast<int>(out_str.size()));
293 } 321 }
OLDNEW
« no previous file with comments | « tools/gn/trace.h ('k') | tools/gn/variables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698