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

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

Issue 869043008: Reland of Move tracing namespace from base::debug to base::trace_event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Fix suppressions Created 5 years, 10 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 | « base/trace_event/trace_event.h ('k') | base/trace_event/trace_event_argument.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/trace_event/trace_event_impl.h" 5 #include "base/trace_event/trace_event_impl.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.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 void WriteEvent( 20 void WriteEvent(
21 char phase, 21 char phase,
22 const char* category_group, 22 const char* category_group,
23 const char* name, 23 const char* name,
24 unsigned long long id, 24 unsigned long long id,
25 const char** arg_names, 25 const char** arg_names,
26 const unsigned char* arg_types, 26 const unsigned char* arg_types,
27 const base::debug::TraceEvent::TraceValue* arg_values, 27 const base::trace_event::TraceEvent::TraceValue* arg_values,
28 const scoped_refptr<base::debug::ConvertableToTraceFormat>* 28 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>*
29 convertable_values, 29 convertable_values,
30 unsigned char flags) { 30 unsigned char flags) {
31 std::string out = base::StringPrintf("%c|%d|%s", phase, getpid(), name); 31 std::string out = base::StringPrintf("%c|%d|%s", phase, getpid(), name);
32 if (flags & TRACE_EVENT_FLAG_HAS_ID) 32 if (flags & TRACE_EVENT_FLAG_HAS_ID)
33 base::StringAppendF(&out, "-%" PRIx64, static_cast<uint64>(id)); 33 base::StringAppendF(&out, "-%" PRIx64, static_cast<uint64>(id));
34 out += '|'; 34 out += '|';
35 35
36 for (int i = 0; i < base::debug::kTraceMaxNumArgs && arg_names[i]; ++i) { 36 for (int i = 0; i < base::trace_event::kTraceMaxNumArgs && arg_names[i];
37 ++i) {
37 if (i) 38 if (i)
38 out += ';'; 39 out += ';';
39 out += arg_names[i]; 40 out += arg_names[i];
40 out += '='; 41 out += '=';
41 std::string::size_type value_start = out.length(); 42 std::string::size_type value_start = out.length();
42 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) { 43 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) {
43 convertable_values[i]->AppendAsTraceFormat(&out); 44 convertable_values[i]->AppendAsTraceFormat(&out);
44 } else { 45 } else {
45 base::debug::TraceEvent::AppendValueAsJSON( 46 base::trace_event::TraceEvent::AppendValueAsJSON(arg_types[i],
46 arg_types[i], arg_values[i], &out); 47 arg_values[i], &out);
47 } 48 }
48 // Remove the quotes which may confuse the atrace script. 49 // Remove the quotes which may confuse the atrace script.
49 ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'"); 50 ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'");
50 ReplaceSubstringsAfterOffset(&out, value_start, "\"", ""); 51 ReplaceSubstringsAfterOffset(&out, value_start, "\"", "");
51 // Replace chars used for separators with similar chars in the value. 52 // Replace chars used for separators with similar chars in the value.
52 std::replace(out.begin() + value_start, out.end(), ';', ','); 53 std::replace(out.begin() + value_start, out.end(), ';', ',');
53 std::replace(out.begin() + value_start, out.end(), '|', '!'); 54 std::replace(out.begin() + value_start, out.end(), '|', '!');
54 } 55 }
55 56
56 out += '|'; 57 out += '|';
57 out += category_group; 58 out += category_group;
58 write(g_atrace_fd, out.c_str(), out.size()); 59 write(g_atrace_fd, out.c_str(), out.size());
59 } 60 }
60 61
61 void NoOpOutputCallback(base::WaitableEvent* complete_event, 62 void NoOpOutputCallback(base::WaitableEvent* complete_event,
62 const scoped_refptr<base::RefCountedString>&, 63 const scoped_refptr<base::RefCountedString>&,
63 bool has_more_events) { 64 bool has_more_events) {
64 if (!has_more_events) 65 if (!has_more_events)
65 complete_event->Signal(); 66 complete_event->Signal();
66 } 67 }
67 68
68 void EndChromeTracing(base::debug::TraceLog* trace_log, 69 void EndChromeTracing(base::trace_event::TraceLog* trace_log,
69 base::WaitableEvent* complete_event) { 70 base::WaitableEvent* complete_event) {
70 trace_log->SetDisabled(); 71 trace_log->SetDisabled();
71 // Delete the buffered trace events as they have been sent to atrace. 72 // Delete the buffered trace events as they have been sent to atrace.
72 trace_log->Flush(base::Bind(&NoOpOutputCallback, complete_event)); 73 trace_log->Flush(base::Bind(&NoOpOutputCallback, complete_event));
73 } 74 }
74 75
75 } // namespace 76 } // namespace
76 77
77 namespace base { 78 namespace base {
78 namespace debug { 79 namespace trace_event {
79 80
80 // These functions support Android systrace.py when 'webview' category is 81 // These functions support Android systrace.py when 'webview' category is
81 // traced. With the new adb_profile_chrome, we may have two phases: 82 // traced. With the new adb_profile_chrome, we may have two phases:
82 // - before WebView is ready for combined tracing, we can use adb_profile_chrome 83 // - before WebView is ready for combined tracing, we can use adb_profile_chrome
83 // to trace android categories other than 'webview' and chromium categories. 84 // to trace android categories other than 'webview' and chromium categories.
84 // In this way we can avoid the conflict between StartATrace/StopATrace and 85 // In this way we can avoid the conflict between StartATrace/StopATrace and
85 // the intents. 86 // the intents.
86 // - TODO(wangxianzhu): after WebView is ready for combined tracing, remove 87 // - TODO(wangxianzhu): after WebView is ready for combined tracing, remove
87 // StartATrace, StopATrace and SendToATrace, and perhaps send Java traces 88 // StartATrace, StopATrace and SendToATrace, and perhaps send Java traces
88 // directly to atrace in trace_event_binding.cc. 89 // directly to atrace in trace_event_binding.cc.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // trace buffer. 189 // trace buffer.
189 TimeTicks now = TimeTicks::NowFromSystemTraceTime(); 190 TimeTicks now = TimeTicks::NowFromSystemTraceTime();
190 double now_in_seconds = now.ToInternalValue() / 1000000.0; 191 double now_in_seconds = now.ToInternalValue() / 1000000.0;
191 std::string marker = StringPrintf( 192 std::string marker = StringPrintf(
192 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds); 193 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds);
193 if (write(atrace_fd, marker.c_str(), marker.size()) == -1) 194 if (write(atrace_fd, marker.c_str(), marker.size()) == -1)
194 PLOG(WARNING) << "Couldn't write to " << kATraceMarkerFile; 195 PLOG(WARNING) << "Couldn't write to " << kATraceMarkerFile;
195 close(atrace_fd); 196 close(atrace_fd);
196 } 197 }
197 198
198 } // namespace debug 199 } // namespace trace_event
199 } // namespace base 200 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/trace_event.h ('k') | base/trace_event/trace_event_argument.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698