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

Side by Side Diff: base/debug/trace_event_android.cc

Issue 12025014: Android: removes "trace_event_clock_sync" from atrace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/debug/trace_event_impl.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/debug/trace_event_impl.h" 5 #include "base/debug/trace_event_impl.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
willchan no longer on Chromium 2013/01/18 16:59:58 Can we delete this too?
bulach 2013/01/18 19:24:28 Done.
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
willchan no longer on Chromium 2013/01/18 16:59:58 Not clear to me why this is necessary
bulach 2013/01/18 19:24:28 Done.
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 14
15 namespace { 15 namespace {
16 16
17 int g_atrace_fd = -1; 17 int g_atrace_fd = -1;
18 const char* kATraceMarkerFile = "/sys/kernel/debug/tracing/trace_marker"; 18 const char* kATraceMarkerFile = "/sys/kernel/debug/tracing/trace_marker";
19 19
20 } // namespace 20 } // namespace
21 21
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 write(g_atrace_fd, out.c_str(), out.size()); 82 write(g_atrace_fd, out.c_str(), out.size());
83 } 83 }
84 break; 84 break;
85 85
86 default: 86 default:
87 // Do nothing. 87 // Do nothing.
88 break; 88 break;
89 } 89 }
90 } 90 }
91 91
92 void TraceLog::AddClockSyncMetadataEvents() {
93 // Since Android does not support sched_setaffinity, we cannot establish clock
94 // sync unless the scheduler clock is set to global. If the trace_clock file
95 // can't be read, we will assume the kernel doesn't support tracing and do
96 // nothing.
97 std::string clock_mode;
98 if (!file_util::ReadFileToString(
99 FilePath("/sys/kernel/debug/tracing/trace_clock"), &clock_mode))
100 return;
101
102 if (clock_mode != "local [global]\n") {
103 DLOG(WARNING) <<
104 "The kernel's tracing clock must be set to global in order for " <<
105 "trace_event to be synchronized with . Do this by\n" <<
106 " echo global > /sys/kerel/debug/tracing/trace_clock";
107 return;
108 }
109
110 int atrace_fd = g_atrace_fd;
111 if (atrace_fd == -1) {
112 // This function may be called when atrace is not enabled.
113 atrace_fd = open(kATraceMarkerFile, O_WRONLY | O_APPEND);
114 if (atrace_fd == -1) {
115 LOG(WARNING) << "Couldn't open " << kATraceMarkerFile;
116 return;
117 }
118 }
119
120 // Android's kernel trace system has a trace_marker feature: this is a file on
121 // debugfs that takes the written data and pushes it onto the trace
122 // buffer. So, to establish clock sync, we write our monotonic clock into that
123 // trace buffer.
124 TimeTicks now = TimeTicks::NowFromSystemTraceTime();
125 double now_in_seconds = now.ToInternalValue() / 1000000.0;
126 std::string marker = StringPrintf(
127 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds);
128 if (write(atrace_fd, marker.c_str(), marker.size()) != 0) {
129 DLOG(WARNING) << "Couldn't write to " << kATraceMarkerFile << ": "
130 << strerror(errno);
131 }
132
133 if (g_atrace_fd == -1)
134 close(atrace_fd);
135 }
136
137 // Must be called with lock_ locked. 92 // Must be called with lock_ locked.
138 void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_enabled) { 93 void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_enabled) {
139 if (g_atrace_fd != -1) 94 if (g_atrace_fd != -1)
140 *category_enabled |= ATRACE_ENABLED; 95 *category_enabled |= ATRACE_ENABLED;
141 } 96 }
142 97
143 } // namespace debug 98 } // namespace debug
144 } // namespace base 99 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698