OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/libplatform/tracing/trace-writer.h" |
| 6 |
| 7 #include "src/base/platform/platform.h" |
| 8 |
| 9 namespace v8 { |
| 10 namespace platform { |
| 11 namespace tracing { |
| 12 |
| 13 JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) { |
| 14 stream_ << "{\"traceEvents\":["; |
| 15 } |
| 16 |
| 17 JSONTraceWriter::~JSONTraceWriter() { stream_ << "]}"; } |
| 18 |
| 19 void JSONTraceWriter::AppendTraceEvent(TraceObject* trace_event) { |
| 20 if (append_comma_) stream_ << ","; |
| 21 append_comma_ = true; |
| 22 if (trace_event->scope() == NULL) { |
| 23 stream_ << "{\"pid\":" << trace_event->pid() |
| 24 << ",\"tid\":" << trace_event->tid() |
| 25 << ",\"ts\":" << trace_event->ts() |
| 26 << ",\"tts\":" << trace_event->tts() << ",\"ph\":\"" |
| 27 << trace_event->phase() << "\",\"cat\":\"" |
| 28 << TracingController::GetCategoryGroupName( |
| 29 trace_event->category_enabled_flag()) |
| 30 << "\",\"name\":\"" << trace_event->name() |
| 31 << "\",\"args\":{},\"dur\":" << trace_event->duration() |
| 32 << ",\"tdur\":" << trace_event->cpu_duration() << "}"; |
| 33 } else { |
| 34 stream_ << "{\"pid\":" << trace_event->pid() |
| 35 << ",\"tid\":" << trace_event->tid() |
| 36 << ",\"ts\":" << trace_event->ts() |
| 37 << ",\"tts\":" << trace_event->tts() << ",\"ph\":\"" |
| 38 << trace_event->phase() << "\",\"cat\":\"" |
| 39 << TracingController::GetCategoryGroupName( |
| 40 trace_event->category_enabled_flag()) |
| 41 << "\",\"name\":\"" << trace_event->name() << "\",\"scope\":\"" |
| 42 << trace_event->scope() |
| 43 << "\",\"args\":{},\"dur\":" << trace_event->duration() |
| 44 << ",\"tdur\":" << trace_event->cpu_duration() << "}"; |
| 45 } |
| 46 // TODO(fmeawad): Add support for Flow Events. |
| 47 } |
| 48 |
| 49 void JSONTraceWriter::Flush() {} |
| 50 |
| 51 TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) { |
| 52 return new JSONTraceWriter(stream); |
| 53 } |
| 54 |
| 55 } // namespace tracing |
| 56 } // namespace platform |
| 57 } // namespace v8 |
OLD | NEW |