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

Side by Side Diff: sky/viewer/services/tracing_impl.cc

Issue 751303003: Move tracing_impl code to mojo/common (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 | « sky/viewer/services/tracing_impl.h ('k') | sky/viewer/viewer.cc » ('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 "sky/viewer/services/tracing_impl.h"
6
7 #include "base/callback.h"
8 #include "base/debug/trace_event.h"
9 #include "base/files/file_util.h"
10
11 namespace sky {
12 namespace {
13
14 static bool g_tracing = false;
15 static int g_blocks = 0;
16 static FILE* g_trace_file = NULL;
17
18 void WriteTraceDataCollected(
19 const scoped_refptr<base::RefCountedString>& events_str,
20 bool has_more_events) {
21 if (g_blocks) {
22 fwrite(",", 1, 1, g_trace_file);
23 }
24 ++g_blocks;
25 fwrite(
26 events_str->data().c_str(), 1, events_str->data().length(), g_trace_file);
27 if (!has_more_events) {
28 fwrite("]}", 1, 2, g_trace_file);
29 base::CloseFile(g_trace_file);
30 g_trace_file = NULL;
31 g_blocks = 0;
32 }
33 }
34
35 void StopTracingAndFlushToDisk() {
36 base::debug::TraceLog::GetInstance()->SetDisabled();
37
38 g_trace_file = base::OpenFile(
39 base::FilePath(FILE_PATH_LITERAL("sky_viewer.trace")), "w+");
40 static const char start[] = "{\"traceEvents\":[";
41 fwrite(start, 1, strlen(start), g_trace_file);
42 base::debug::TraceLog::GetInstance()->Flush(
43 base::Bind(&WriteTraceDataCollected));
44 }
45
46 }
47
48 TracingImpl::TracingImpl() {
49 }
50
51 TracingImpl::~TracingImpl() {
52 }
53
54 void TracingImpl::Start() {
55 if (g_tracing)
56 return;
57 g_tracing = true;
58 base::debug::TraceLog::GetInstance()->SetEnabled(
59 base::debug::CategoryFilter("*"),
60 base::debug::TraceLog::RECORDING_MODE,
61 base::debug::TraceOptions(base::debug::RECORD_UNTIL_FULL));
62 }
63
64 void TracingImpl::Stop() {
65 if (!g_tracing)
66 return;
67 g_tracing = false;
68 StopTracingAndFlushToDisk();
69 }
70
71 } // namespace sky
OLDNEW
« no previous file with comments | « sky/viewer/services/tracing_impl.h ('k') | sky/viewer/viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698