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

Unified Diff: base/debug/trace_event_impl.cc

Issue 11345019: Make Chrome Trace work with Android ATrace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't append arguments to name Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: base/debug/trace_event_impl.cc
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 13b6a97440f87c56a777b29b6ac1ae2ff817082f..e4f4c21b7a3daff679f81ff44755ff2682aff7ca 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/debug/leak_annotations.h"
#include "base/debug/trace_event.h"
-#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/lazy_instance.h"
#include "base/memory/singleton.h"
@@ -70,50 +69,6 @@ int g_category_index = 3; // skip initial 3 categories
LazyInstance<ThreadLocalPointer<const char> >::Leaky
g_current_thread_name = LAZY_INSTANCE_INITIALIZER;
-void AppendValueAsJSON(unsigned char type,
- TraceEvent::TraceValue value,
- std::string* out) {
- std::string::size_type start_pos;
- switch (type) {
- case TRACE_VALUE_TYPE_BOOL:
- *out += value.as_bool ? "true" : "false";
- break;
- case TRACE_VALUE_TYPE_UINT:
- StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint));
- break;
- case TRACE_VALUE_TYPE_INT:
- StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int));
- break;
- case TRACE_VALUE_TYPE_DOUBLE:
- StringAppendF(out, "%f", value.as_double);
- break;
- case TRACE_VALUE_TYPE_POINTER:
- // JSON only supports double and int numbers.
- // So as not to lose bits from a 64-bit pointer, output as a hex string.
- StringAppendF(out, "\"%" PRIx64 "\"", static_cast<uint64>(
- reinterpret_cast<intptr_t>(
- value.as_pointer)));
- break;
- case TRACE_VALUE_TYPE_STRING:
- case TRACE_VALUE_TYPE_COPY_STRING:
- *out += "\"";
- start_pos = out->size();
- *out += value.as_string ? value.as_string : "NULL";
- // insert backslash before special characters for proper json format.
- while ((start_pos = out->find_first_of("\\\"", start_pos)) !=
- std::string::npos) {
- out->insert(start_pos, 1, '\\');
- // skip inserted escape character and following character.
- start_pos += 2;
- }
- *out += "\"";
- break;
- default:
- NOTREACHED() << "Don't know how to print this value";
- break;
- }
-}
-
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -225,6 +180,51 @@ TraceEvent::TraceEvent(int thread_id,
TraceEvent::~TraceEvent() {
}
+// static
+void TraceEvent::AppendValueAsJSON(unsigned char type,
+ TraceEvent::TraceValue value,
+ std::string* out) {
+ std::string::size_type start_pos;
+ switch (type) {
+ case TRACE_VALUE_TYPE_BOOL:
+ *out += value.as_bool ? "true" : "false";
+ break;
+ case TRACE_VALUE_TYPE_UINT:
+ StringAppendF(out, "%" PRIu64, static_cast<uint64>(value.as_uint));
+ break;
+ case TRACE_VALUE_TYPE_INT:
+ StringAppendF(out, "%" PRId64, static_cast<int64>(value.as_int));
+ break;
+ case TRACE_VALUE_TYPE_DOUBLE:
+ StringAppendF(out, "%f", value.as_double);
+ break;
+ case TRACE_VALUE_TYPE_POINTER:
+ // JSON only supports double and int numbers.
+ // So as not to lose bits from a 64-bit pointer, output as a hex string.
+ StringAppendF(out, "\"%" PRIx64 "\"", static_cast<uint64>(
+ reinterpret_cast<intptr_t>(
+ value.as_pointer)));
+ break;
+ case TRACE_VALUE_TYPE_STRING:
+ case TRACE_VALUE_TYPE_COPY_STRING:
+ *out += "\"";
+ start_pos = out->size();
+ *out += value.as_string ? value.as_string : "NULL";
+ // insert backslash before special characters for proper json format.
+ while ((start_pos = out->find_first_of("\\\"", start_pos)) !=
+ std::string::npos) {
+ out->insert(start_pos, 1, '\\');
+ // skip inserted escape character and following character.
+ start_pos += 2;
+ }
+ *out += "\"";
+ break;
+ default:
+ NOTREACHED() << "Don't know how to print this value";
+ break;
+ }
+}
+
void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events,
size_t start,
size_t count,
@@ -543,7 +543,9 @@ void TraceLog::SetDisabled() {
for (int i = 0; i < g_category_index; i++)
g_category_enabled[i] = 0;
AddThreadNameMetadataEvents();
+#if defined(OS_ANDROID)
AddClockSyncMetadataEvents();
+#endif
}
void TraceLog::SetEnabled(bool enabled) {
@@ -604,6 +606,14 @@ int TraceLog::AddTraceEvent(char phase,
long long threshold,
unsigned char flags) {
DCHECK(name);
+
+#if defined(OS_ANDROID)
+ if (IsATraceEnabled()) {
jbates 2012/10/30 20:22:14 This if looks redundant
Xianzhu 2012/10/30 21:45:01 Done.
+ SendToATrace(phase, GetCategoryName(category_enabled), name,
+ num_args, arg_names, arg_types, arg_values);
+ }
+#endif
+
TimeTicks now = TimeTicks::NowFromSystemTraceTime();
NotificationHelper notifier(this);
int ret_begin_id = -1;
@@ -741,45 +751,6 @@ void TraceLog::CancelWatchEvent() {
watch_event_name_ = "";
}
-void TraceLog::AddClockSyncMetadataEvents() {
-#if defined(OS_ANDROID)
- // Since Android does not support sched_setaffinity, we cannot establish clock
- // sync unless the scheduler clock is set to global. If the trace_clock file
- // can't be read, we will assume the kernel doesn't support tracing and do
- // nothing.
- std::string clock_mode;
- if (!file_util::ReadFileToString(
- FilePath("/sys/kernel/debug/tracing/trace_clock"),
- &clock_mode))
- return;
-
- if (clock_mode != "local [global]\n") {
- DLOG(WARNING) <<
- "The kernel's tracing clock must be set to global in order for " <<
- "trace_event to be synchronized with . Do this by\n" <<
- " echo global > /sys/kerel/debug/tracing/trace_clock";
- return;
- }
-
- // Android's kernel trace system has a trace_marker feature: this is a file on
- // debugfs that takes the written data and pushes it onto the trace
- // buffer. So, to establish clock sync, we write our monotonic clock into that
- // trace buffer.
- TimeTicks now = TimeTicks::NowFromSystemTraceTime();
-
- double now_in_seconds = now.ToInternalValue() / 1000000.0;
- std::string marker =
- StringPrintf("trace_event_clock_sync: parent_ts=%f\n",
- now_in_seconds);
- if (file_util::WriteFile(
- FilePath("/sys/kernel/debug/tracing/trace_marker"),
- marker.c_str(), marker.size()) == -1) {
- DLOG(WARNING) << "Couldn't write to /sys/kernel/debug/tracing/trace_marker";
- return;
- }
-#endif
-}
-
void TraceLog::AddThreadNameMetadataEvents() {
lock_.AssertAcquired();
for(base::hash_map<int, std::string>::iterator it = thread_names_.begin();

Powered by Google App Engine
This is Rietveld 408576698