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

Unified Diff: services/tracing/trace_data_sink.cc

Issue 769963004: Add tracing service and make the shell+sky_viewer+services talk to it (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/tracing/trace_data_sink.h ('k') | services/tracing/tracing.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/tracing/trace_data_sink.cc
diff --git a/services/tracing/trace_data_sink.cc b/services/tracing/trace_data_sink.cc
new file mode 100644
index 0000000000000000000000000000000000000000..aeae144888f1787041150b471bc230747ac17a70
--- /dev/null
+++ b/services/tracing/trace_data_sink.cc
@@ -0,0 +1,41 @@
+// Copyright 2014 The Chromium 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 "services/tracing/trace_data_sink.h"
+
+#include "base/files/file_util.h"
+
+namespace tracing {
+
+TraceDataSink::TraceDataSink(base::FilePath base_name) : empty_(true) {
+ file_ =
+ base::OpenFile(base_name.AddExtension(FILE_PATH_LITERAL(".trace")), "w+");
+ static const char start[] = "{\"traceEvents\":[";
+ fwrite(start, 1, strlen(start), file_);
+}
+
+TraceDataSink::~TraceDataSink() {
+ if (file_)
+ Flush();
+ DCHECK(!file_);
+}
+
+void TraceDataSink::AddChunk(const std::string& json) {
+ if (!empty_) {
+ fwrite(",", 1, 1, file_);
+ }
+
+ empty_ = false;
+
+ fwrite(json.data(), 1, json.length(), file_);
+}
+
+void TraceDataSink::Flush() {
+ static const char end[] = "]}";
+ fwrite(end, 1, strlen(end), file_);
+ base::CloseFile(file_);
+ file_ = nullptr;
+}
+
+} // namespace tracing
« no previous file with comments | « services/tracing/trace_data_sink.h ('k') | services/tracing/tracing.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698