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

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

Issue 952413002: The tracing service sometimes creates corrupt data (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 | « mojo/common/data_pipe_utils.cc ('k') | no next file » | 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 9
9 namespace tracing { 10 namespace tracing {
10 namespace { 11 namespace {
11 12
12 const char kStart[] = "{\"traceEvents\":["; 13 const char kStart[] = "{\"traceEvents\":[";
13 const char kEnd[] = "]}"; 14 const char kEnd[] = "]}";
14 15
15 void Write(const mojo::ScopedDataPipeProducerHandle& pipe, 16 } // namespace
16 const char* string,
17 uint32_t num_bytes) {
18 CHECK_EQ(MOJO_RESULT_OK,
19 mojo::WriteDataRaw(pipe.get(), string, &num_bytes,
20 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
21 }
22 }
23 17
24 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe) 18 TraceDataSink::TraceDataSink(mojo::ScopedDataPipeProducerHandle pipe)
25 : pipe_(pipe.Pass()), empty_(true) { 19 : pipe_(pipe.Pass()), empty_(true) {
26 Write(pipe_, kStart, strlen(kStart)); 20 mojo::common::BlockingCopyFromString(kStart, pipe_);
jamesr 2015/02/26 00:25:22 since we're calling this 3 times could you put a u
abarth-chromium 2015/02/26 02:54:12 Will do. Thanks!
27 } 21 }
28 22
29 TraceDataSink::~TraceDataSink() { 23 TraceDataSink::~TraceDataSink() {
30 if (pipe_.is_valid()) 24 if (pipe_.is_valid())
31 Flush(); 25 Flush();
32 DCHECK(!pipe_.is_valid()); 26 DCHECK(!pipe_.is_valid());
33 } 27 }
34 28
35 void TraceDataSink::AddChunk(const std::string& json) { 29 void TraceDataSink::AddChunk(const std::string& json) {
36 if (!empty_) 30 if (!empty_)
37 Write(pipe_, ",", 1); 31 mojo::common::BlockingCopyFromString(",", pipe_);
38 empty_ = false; 32 empty_ = false;
39 Write(pipe_, json.data(), json.length()); 33 mojo::common::BlockingCopyFromString(json, pipe_);
40 } 34 }
41 35
42 void TraceDataSink::Flush() { 36 void TraceDataSink::Flush() {
43 Write(pipe_, kEnd, strlen(kEnd)); 37 mojo::common::BlockingCopyFromString(kEnd, pipe_);
44 pipe_.reset(); 38 pipe_.reset();
45 } 39 }
46 40
47 } // namespace tracing 41 } // namespace tracing
OLDNEW
« no previous file with comments | « mojo/common/data_pipe_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698