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

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

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 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 base {
16 namespace trace_event {
17
15 namespace { 18 namespace {
16 19
17 int g_atrace_fd = -1; 20 int g_atrace_fd = -1;
18 const char kATraceMarkerFile[] = "/sys/kernel/debug/tracing/trace_marker"; 21 const char kATraceMarkerFile[] = "/sys/kernel/debug/tracing/trace_marker";
19 22
20 void WriteEvent( 23 void WriteEvent(
21 char phase, 24 char phase,
22 const char* category_group, 25 const char* category_group,
23 const char* name, 26 const char* name,
24 unsigned long long id, 27 unsigned long long id,
25 const char** arg_names, 28 const char** arg_names,
26 const unsigned char* arg_types, 29 const unsigned char* arg_types,
27 const base::trace_event::TraceEvent::TraceValue* arg_values, 30 const TraceEvent::TraceValue* arg_values,
28 const scoped_refptr<base::trace_event::ConvertableToTraceFormat>* 31 const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
29 convertable_values, 32 unsigned int flags) {
30 unsigned char flags) { 33 std::string out = 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) 34 if (flags & TRACE_EVENT_FLAG_HAS_ID)
33 base::StringAppendF(&out, "-%" PRIx64, static_cast<uint64>(id)); 35 StringAppendF(&out, "-%" PRIx64, static_cast<uint64>(id));
34 out += '|'; 36 out += '|';
35 37
36 for (int i = 0; i < base::trace_event::kTraceMaxNumArgs && arg_names[i]; 38 for (int i = 0; i < kTraceMaxNumArgs && arg_names[i]; ++i) {
37 ++i) {
38 if (i) 39 if (i)
39 out += ';'; 40 out += ';';
40 out += arg_names[i]; 41 out += arg_names[i];
41 out += '='; 42 out += '=';
42 std::string::size_type value_start = out.length(); 43 std::string::size_type value_start = out.length();
43 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) { 44 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE)
44 convertable_values[i]->AppendAsTraceFormat(&out); 45 convertable_values[i]->AppendAsTraceFormat(&out);
45 } else { 46 else
46 base::trace_event::TraceEvent::AppendValueAsJSON(arg_types[i], 47 TraceEvent::AppendValueAsJSON(arg_types[i], arg_values[i], &out);
47 arg_values[i], &out); 48
48 }
49 // Remove the quotes which may confuse the atrace script. 49 // Remove the quotes which may confuse the atrace script.
50 ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'"); 50 ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'");
51 ReplaceSubstringsAfterOffset(&out, value_start, "\"", ""); 51 ReplaceSubstringsAfterOffset(&out, value_start, "\"", "");
52 // Replace chars used for separators with similar chars in the value. 52 // Replace chars used for separators with similar chars in the value.
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 std::replace(out.begin() + value_start, out.end(), '|', '!');
55 } 55 }
56 56
57 out += '|'; 57 out += '|';
58 out += category_group; 58 out += category_group;
59 write(g_atrace_fd, out.c_str(), out.size()); 59 write(g_atrace_fd, out.c_str(), out.size());
60 } 60 }
61 61
62 void NoOpOutputCallback(base::WaitableEvent* complete_event, 62 void NoOpOutputCallback(WaitableEvent* complete_event,
63 const scoped_refptr<base::RefCountedString>&, 63 const scoped_refptr<RefCountedString>&,
64 bool has_more_events) { 64 bool has_more_events) {
65 if (!has_more_events) 65 if (!has_more_events)
66 complete_event->Signal(); 66 complete_event->Signal();
67 } 67 }
68 68
69 void EndChromeTracing(base::trace_event::TraceLog* trace_log, 69 void EndChromeTracing(TraceLog* trace_log, WaitableEvent* complete_event) {
70 base::WaitableEvent* complete_event) {
71 trace_log->SetDisabled(); 70 trace_log->SetDisabled();
72 // Delete the buffered trace events as they have been sent to atrace. 71 // Delete the buffered trace events as they have been sent to atrace.
73 trace_log->Flush(base::Bind(&NoOpOutputCallback, complete_event)); 72 trace_log->Flush(Bind(&NoOpOutputCallback, complete_event));
74 } 73 }
75 74
76 } // namespace 75 } // namespace
77 76
78 namespace base {
79 namespace trace_event {
80
81 // These functions support Android systrace.py when 'webview' category is 77 // These functions support Android systrace.py when 'webview' category is
82 // traced. With the new adb_profile_chrome, we may have two phases: 78 // traced. With the new adb_profile_chrome, we may have two phases:
83 // - before WebView is ready for combined tracing, we can use adb_profile_chrome 79 // - before WebView is ready for combined tracing, we can use adb_profile_chrome
84 // to trace android categories other than 'webview' and chromium categories. 80 // to trace android categories other than 'webview' and chromium categories.
85 // In this way we can avoid the conflict between StartATrace/StopATrace and 81 // In this way we can avoid the conflict between StartATrace/StopATrace and
86 // the intents. 82 // the intents.
87 // - TODO(wangxianzhu): after WebView is ready for combined tracing, remove 83 // - TODO(wangxianzhu): after WebView is ready for combined tracing, remove
88 // StartATrace, StopATrace and SendToATrace, and perhaps send Java traces 84 // StartATrace, StopATrace and SendToATrace, and perhaps send Java traces
89 // directly to atrace in trace_event_binding.cc. 85 // directly to atrace in trace_event_binding.cc.
90 86
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 double now_in_seconds = (TraceTicks::Now() - TraceTicks()).InSecondsF(); 186 double now_in_seconds = (TraceTicks::Now() - TraceTicks()).InSecondsF();
191 std::string marker = StringPrintf( 187 std::string marker = StringPrintf(
192 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds); 188 "trace_event_clock_sync: parent_ts=%f\n", now_in_seconds);
193 if (write(atrace_fd, marker.c_str(), marker.size()) == -1) 189 if (write(atrace_fd, marker.c_str(), marker.size()) == -1)
194 PLOG(WARNING) << "Couldn't write to " << kATraceMarkerFile; 190 PLOG(WARNING) << "Couldn't write to " << kATraceMarkerFile;
195 close(atrace_fd); 191 close(atrace_fd);
196 } 192 }
197 193
198 } // namespace trace_event 194 } // namespace trace_event
199 } // namespace base 195 } // 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