Index: src/libplatform/tracing/trace-writer.cc |
diff --git a/src/libplatform/tracing/trace-writer.cc b/src/libplatform/tracing/trace-writer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..464b5713fc2b69b6076f43b7cd40ef0ad7e8dd50 |
--- /dev/null |
+++ b/src/libplatform/tracing/trace-writer.cc |
@@ -0,0 +1,57 @@ |
+// Copyright 2016 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/libplatform/tracing/trace-writer.h" |
+ |
+#include "src/base/platform/platform.h" |
+ |
+namespace v8 { |
+namespace platform { |
+namespace tracing { |
+ |
+JSONTraceWriter::JSONTraceWriter(std::ostream& stream) : stream_(stream) { |
+ stream_ << "{\"traceEvents\":["; |
+} |
+ |
+JSONTraceWriter::~JSONTraceWriter() { stream_ << "]}"; } |
+ |
+void JSONTraceWriter::AppendTraceEvent(TraceObject* trace_event) { |
+ if (append_comma_) stream_ << ","; |
+ append_comma_ = true; |
+ if (trace_event->scope() == NULL) { |
+ stream_ << "{\"pid\":" << trace_event->pid() |
+ << ",\"tid\":" << trace_event->tid() |
+ << ",\"ts\":" << trace_event->ts() |
+ << ",\"tts\":" << trace_event->tts() << ",\"ph\":\"" |
+ << trace_event->phase() << "\",\"cat\":\"" |
+ << TracingController::GetCategoryGroupName( |
+ trace_event->category_enabled_flag()) |
+ << "\",\"name\":\"" << trace_event->name() |
+ << "\",\"args\":{},\"dur\":" << trace_event->duration() |
+ << ",\"tdur\":" << trace_event->cpu_duration() << "}"; |
+ } else { |
+ stream_ << "{\"pid\":" << trace_event->pid() |
+ << ",\"tid\":" << trace_event->tid() |
+ << ",\"ts\":" << trace_event->ts() |
+ << ",\"tts\":" << trace_event->tts() << ",\"ph\":\"" |
+ << trace_event->phase() << "\",\"cat\":\"" |
+ << TracingController::GetCategoryGroupName( |
+ trace_event->category_enabled_flag()) |
+ << "\",\"name\":\"" << trace_event->name() << "\",\"scope\":\"" |
+ << trace_event->scope() |
+ << "\",\"args\":{},\"dur\":" << trace_event->duration() |
+ << ",\"tdur\":" << trace_event->cpu_duration() << "}"; |
+ } |
+ // TODO(fmeawad): Add support for Flow Events. |
+} |
+ |
+void JSONTraceWriter::Flush() {} |
+ |
+TraceWriter* TraceWriter::CreateJSONTraceWriter(std::ostream& stream) { |
+ return new JSONTraceWriter(stream); |
+} |
+ |
+} // namespace tracing |
+} // namespace platform |
+} // namespace v8 |