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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « services/tracing/trace_data_sink.h ('k') | services/tracing/tracing.mojom » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "services/tracing/trace_data_sink.h"
6
7 #include "base/files/file_util.h"
8
9 namespace tracing {
10
11 TraceDataSink::TraceDataSink(base::FilePath base_name) : empty_(true) {
12 file_ =
13 base::OpenFile(base_name.AddExtension(FILE_PATH_LITERAL(".trace")), "w+");
14 static const char start[] = "{\"traceEvents\":[";
15 fwrite(start, 1, strlen(start), file_);
16 }
17
18 TraceDataSink::~TraceDataSink() {
19 if (file_)
20 Flush();
21 DCHECK(!file_);
22 }
23
24 void TraceDataSink::AddChunk(const std::string& json) {
25 if (!empty_) {
26 fwrite(",", 1, 1, file_);
27 }
28
29 empty_ = false;
30
31 fwrite(json.data(), 1, json.length(), file_);
32 }
33
34 void TraceDataSink::Flush() {
35 static const char end[] = "]}";
36 fwrite(end, 1, strlen(end), file_);
37 base::CloseFile(file_);
38 file_ = nullptr;
39 }
40
41 } // namespace tracing
OLDNEW
« 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