OLD | NEW |
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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 const TraceItem& item = *events[i]; | 234 const TraceItem& item = *events[i]; |
235 | 235 |
236 if (i != 0) | 236 if (i != 0) |
237 out << ","; | 237 out << ","; |
238 out << "{\"pid\":0,\"tid\":" << item.thread_id(); | 238 out << "{\"pid\":0,\"tid\":" << item.thread_id(); |
239 out << ",\"ts\":" << item.begin().ToInternalValue(); | 239 out << ",\"ts\":" << item.begin().ToInternalValue(); |
240 out << ",\"ph\":\"X\""; // "X" = complete event with begin & duration. | 240 out << ",\"ph\":\"X\""; // "X" = complete event with begin & duration. |
241 out << ",\"dur\":" << item.delta().InMicroseconds(); | 241 out << ",\"dur\":" << item.delta().InMicroseconds(); |
242 | 242 |
243 quote_buffer.resize(0); | 243 quote_buffer.resize(0); |
244 base::JsonDoubleQuote(item.name(), true, "e_buffer); | 244 base::EscapeJSONString(item.name(), true, "e_buffer); |
245 out << ",\"name\":" << quote_buffer; | 245 out << ",\"name\":" << quote_buffer; |
246 | 246 |
247 out << ",\"cat\":"; | 247 out << ",\"cat\":"; |
248 switch (item.type()) { | 248 switch (item.type()) { |
249 case TraceItem::TRACE_FILE_LOAD: | 249 case TraceItem::TRACE_FILE_LOAD: |
250 out << "\"load\""; | 250 out << "\"load\""; |
251 break; | 251 break; |
252 case TraceItem::TRACE_FILE_PARSE: | 252 case TraceItem::TRACE_FILE_PARSE: |
253 out << "\"parse\""; | 253 out << "\"parse\""; |
254 break; | 254 break; |
255 case TraceItem::TRACE_FILE_EXECUTE: | 255 case TraceItem::TRACE_FILE_EXECUTE: |
256 out << "\"file_exec\""; | 256 out << "\"file_exec\""; |
257 break; | 257 break; |
258 case TraceItem::TRACE_FILE_WRITE: | 258 case TraceItem::TRACE_FILE_WRITE: |
259 out << "\"file_write\""; | 259 out << "\"file_write\""; |
260 break; | 260 break; |
261 case TraceItem::TRACE_SCRIPT_EXECUTE: | 261 case TraceItem::TRACE_SCRIPT_EXECUTE: |
262 out << "\"script_exec\""; | 262 out << "\"script_exec\""; |
263 break; | 263 break; |
264 case TraceItem::TRACE_DEFINE_TARGET: | 264 case TraceItem::TRACE_DEFINE_TARGET: |
265 out << "\"define\""; | 265 out << "\"define\""; |
266 } | 266 } |
267 | 267 |
268 if (!item.toolchain().empty() || !item.cmdline().empty()) { | 268 if (!item.toolchain().empty() || !item.cmdline().empty()) { |
269 out << ",\"args\":{"; | 269 out << ",\"args\":{"; |
270 bool needs_comma = false; | 270 bool needs_comma = false; |
271 if (!item.toolchain().empty()) { | 271 if (!item.toolchain().empty()) { |
272 quote_buffer.resize(0); | 272 quote_buffer.resize(0); |
273 base::JsonDoubleQuote(item.toolchain(), true, "e_buffer); | 273 base::EscapeJSONString(item.toolchain(), true, "e_buffer); |
274 out << "\"toolchain\":" << quote_buffer; | 274 out << "\"toolchain\":" << quote_buffer; |
275 needs_comma = true; | 275 needs_comma = true; |
276 } | 276 } |
277 if (!item.cmdline().empty()) { | 277 if (!item.cmdline().empty()) { |
278 quote_buffer.resize(0); | 278 quote_buffer.resize(0); |
279 base::JsonDoubleQuote(item.cmdline(), true, "e_buffer); | 279 base::EscapeJSONString(item.cmdline(), true, "e_buffer); |
280 if (needs_comma) | 280 if (needs_comma) |
281 out << ","; | 281 out << ","; |
282 out << "\"cmdline\":" << quote_buffer; | 282 out << "\"cmdline\":" << quote_buffer; |
283 needs_comma = true; | 283 needs_comma = true; |
284 } | 284 } |
285 out << "}"; | 285 out << "}"; |
286 } | 286 } |
287 out << "}"; | 287 out << "}"; |
288 } | 288 } |
289 | 289 |
290 out << "]}"; | 290 out << "]}"; |
291 | 291 |
292 std::string out_str = out.str(); | 292 std::string out_str = out.str(); |
293 file_util::WriteFile(file_name, out_str.data(), | 293 file_util::WriteFile(file_name, out_str.data(), |
294 static_cast<int>(out_str.size())); | 294 static_cast<int>(out_str.size())); |
295 } | 295 } |
OLD | NEW |