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

Side by Side Diff: services/tracing/trace_data_sink.cc

Issue 1065093003: Generate trace header/footer in tracing consumer instead of service (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « services/tracing/trace_data_sink.h ('k') | services/tracing/tracing_app.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/tracing/trace_data_sink.h" 5 #include "services/tracing/trace_data_sink.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/common/data_pipe_utils.h" 8 #include "mojo/common/data_pipe_utils.h"
9 9
10 using mojo::common::BlockingCopyFromString; 10 using mojo::common::BlockingCopyFromString;
11 11
12 namespace tracing { 12 namespace tracing {
13 namespace {
14
15 const char kStart[] = "{\"traceEvents\":[";
16 const char kEnd[] = "]}";
17
18 } // namespace
19 13
20 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe) 14 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe)
21 : pipe_(pipe.Pass()), empty_(true) { 15 : pipe_(pipe.Pass()), empty_(true) {
22 BlockingCopyFromString(kStart, pipe_);
23 } 16 }
24 17
25 TraceDataSink::~TraceDataSink() { 18 TraceDataSink::~TraceDataSink() {
26 if (pipe_.is_valid()) 19 if (pipe_.is_valid())
27 Flush(); 20 pipe_.reset();
28 DCHECK(!pipe_.is_valid()); 21 DCHECK(!pipe_.is_valid());
29 } 22 }
30 23
31 void TraceDataSink::AddChunk(const std::string& json) { 24 void TraceDataSink::AddChunk(const std::string& json) {
32 if (!empty_) 25 if (!empty_)
33 BlockingCopyFromString(",", pipe_); 26 BlockingCopyFromString(",", pipe_);
34 empty_ = false; 27 empty_ = false;
35 BlockingCopyFromString(json, pipe_); 28 BlockingCopyFromString(json, pipe_);
36 } 29 }
37 30
38 void TraceDataSink::Flush() {
39 BlockingCopyFromString(kEnd, pipe_);
40 pipe_.reset();
41 }
42
43 } // namespace tracing 31 } // namespace tracing
OLDNEW
« no previous file with comments | « services/tracing/trace_data_sink.h ('k') | services/tracing/tracing_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698