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

Unified Diff: base/debug/trace_event.cc

Issue 8590015: trace_event: distinguish between scoped begin/end and global start/finish events (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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.cc
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc
index 0550ca3484eae9aeb78ec3e8b0b6ba8cb96d8c42..1c313681f5055d4fc29bdfc6eb339c68664bdf0a 100644
--- a/base/debug/trace_event.cc
+++ b/base/debug/trace_event.cc
@@ -72,32 +72,26 @@ LazyInstance<ThreadLocalPointer<char>,
////////////////////////////////////////////////////////////////////////////////
void TraceValue::AppendAsJSON(std::string* out) const {
- char temp_string[128];
std::string::size_type start_pos;
switch (type_) {
case TRACE_TYPE_BOOL:
*out += as_bool() ? "true" : "false";
break;
case TRACE_TYPE_UINT:
- base::snprintf(temp_string, arraysize(temp_string), "%llu",
- static_cast<unsigned long long>(as_uint()));
- *out += temp_string;
+ StringAppendF(out, "%llu", static_cast<unsigned long long>(as_uint()));
jbates 2011/11/17 01:15:28 Cleanup to match other instances of StringAppendF
break;
case TRACE_TYPE_INT:
- base::snprintf(temp_string, arraysize(temp_string), "%lld",
- static_cast<long long>(as_int()));
- *out += temp_string;
+ StringAppendF(out, "%lld", static_cast<long long>(as_int()));
break;
case TRACE_TYPE_DOUBLE:
- base::snprintf(temp_string, arraysize(temp_string), "%f", as_double());
- *out += temp_string;
+ StringAppendF(out, "%f", as_double());
break;
case TRACE_TYPE_POINTER:
- base::snprintf(temp_string, arraysize(temp_string), "%llu",
- static_cast<unsigned long long>(
- reinterpret_cast<intptr_t>(
- as_pointer())));
- *out += temp_string;
+ // 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, "\"%llx\"", static_cast<unsigned long long>(
jbates 2011/11/17 01:15:28 Storing the pointer as a string instead of an int,
+ reinterpret_cast<intptr_t>(
+ as_pointer())));
break;
case TRACE_TYPE_STRING:
case TRACE_TYPE_STATIC_STRING:
@@ -145,30 +139,30 @@ void CopyTraceEventParameter(char** buffer,
} // namespace
TraceEvent::TraceEvent()
- : process_id_(0),
- thread_id_(0),
- phase_(TRACE_EVENT_PHASE_BEGIN),
+ : extra_(0u),
category_(NULL),
- name_(NULL) {
+ name_(NULL),
+ thread_id_(0),
+ phase_(TRACE_EVENT_PHASE_BEGIN) {
arg_names_[0] = NULL;
arg_names_[1] = NULL;
}
-TraceEvent::TraceEvent(unsigned long process_id,
- unsigned long thread_id,
+TraceEvent::TraceEvent(int thread_id,
TimeTicks timestamp,
TraceEventPhase phase,
const TraceCategory* category,
const char* name,
+ uint64 extra,
const char* arg1_name, const TraceValue& arg1_val,
const char* arg2_name, const TraceValue& arg2_val,
bool copy)
- : process_id_(process_id),
- thread_id_(thread_id),
- timestamp_(timestamp),
- phase_(phase),
+ : timestamp_(timestamp),
+ extra_(extra),
category_(category),
- name_(name) {
+ name_(name),
+ thread_id_(thread_id),
+ phase_(phase) {
COMPILE_ASSERT(kTraceMaxNumArgs == 2, TraceEvent_arg_count_out_of_sync);
arg_names_[0] = arg1_name;
arg_names_[1] = arg2_name;
@@ -217,10 +211,14 @@ const char* TraceEvent::GetPhaseString(TraceEventPhase phase) {
switch(phase) {
case TRACE_EVENT_PHASE_BEGIN:
return "B";
- case TRACE_EVENT_PHASE_INSTANT:
- return "I";
case TRACE_EVENT_PHASE_END:
jbates 2011/11/17 01:15:28 Reordered these to match the order in the enum.
return "E";
+ case TRACE_EVENT_PHASE_INSTANT:
+ return "I";
+ case TRACE_EVENT_PHASE_START:
+ return "S";
+ case TRACE_EVENT_PHASE_FINISH:
+ return "F";
case TRACE_EVENT_PHASE_METADATA:
return "M";
default:
@@ -233,10 +231,14 @@ TraceEventPhase TraceEvent::GetPhase(const char* phase) {
switch(*phase) {
case 'B':
return TRACE_EVENT_PHASE_BEGIN;
- case 'I':
- return TRACE_EVENT_PHASE_INSTANT;
case 'E':
return TRACE_EVENT_PHASE_END;
+ case 'I':
+ return TRACE_EVENT_PHASE_INSTANT;
+ case 'S':
+ return TRACE_EVENT_PHASE_START;
+ case 'F':
+ return TRACE_EVENT_PHASE_FINISH;
case 'M':
return TRACE_EVENT_PHASE_METADATA;
default:
@@ -259,14 +261,15 @@ void TraceEvent::AppendEventsAsJSON(const std::vector<TraceEvent>& events,
void TraceEvent::AppendAsJSON(std::string* out) const {
const char* phase_str = GetPhaseString(phase_);
int64 time_int64 = timestamp_.ToInternalValue();
+ int process_id = static_cast<int>(base::GetCurrentProcId());
// Category name checked at category creation time.
DCHECK(!strchr(name_, '"'));
StringAppendF(out,
"{\"cat\":\"%s\",\"pid\":%i,\"tid\":%i,\"ts\":%lld,"
"\"ph\":\"%s\",\"name\":\"%s\",\"args\":{",
category_->name,
- static_cast<int>(process_id_),
- static_cast<int>(thread_id_),
+ process_id,
+ thread_id_,
static_cast<long long>(time_int64),
phase_str,
name_);
@@ -280,7 +283,14 @@ void TraceEvent::AppendAsJSON(std::string* out) const {
*out += "\":";
arg_values_[i].AppendAsJSON(out);
}
- *out += "}}";
+ *out += "}";
+
+ // If extra_ is non-zero, print it out as a hex string so we don't loose any
+ // bits (it might be a 64-bit pointer).
+ if (extra_ != 0ull)
+ StringAppendF(out, ",\"ext\":\"%llx\"",
+ static_cast<unsigned long long>(extra_));
+ *out += "}";
}
////////////////////////////////////////////////////////////////////////////////
@@ -529,6 +539,7 @@ void TraceLog::Flush() {
int TraceLog::AddTraceEvent(TraceEventPhase phase,
const TraceCategory* category,
const char* name,
+ uint64 extra,
const char* arg1_name, TraceValue arg1_val,
const char* arg2_name, TraceValue arg2_val,
int threshold_begin_id,
@@ -545,7 +556,7 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase,
if (logged_events_.size() >= kTraceEventBufferSize)
return -1;
- PlatformThreadId thread_id = PlatformThread::CurrentId();
+ int thread_id = static_cast<int>(PlatformThread::CurrentId());
const char* new_name = PlatformThread::GetName();
// Check if the thread name has been set or changed since the previous
@@ -594,9 +605,8 @@ int TraceLog::AddTraceEvent(TraceEventPhase phase,
}
ret_begin_id = static_cast<int>(logged_events_.size());
logged_events_.push_back(
- TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()),
- thread_id,
- now, phase, category, name,
+ TraceEvent(thread_id,
+ now, phase, category, name, extra,
arg1_name, arg1_val,
arg2_name, arg2_val,
flags & EVENT_FLAG_COPY));
@@ -645,10 +655,9 @@ void TraceLog::AddCurrentMetadataEvents() {
it++) {
if (!it->second.empty())
logged_events_.push_back(
- TraceEvent(static_cast<unsigned long>(base::GetCurrentProcId()),
- it->first,
+ TraceEvent(it->first,
TimeTicks(), base::debug::TRACE_EVENT_PHASE_METADATA,
- g_category_metadata, "thread_name",
+ g_category_metadata, "thread_name", 0,
"name", it->second,
NULL, 0,
false));
@@ -678,7 +687,7 @@ void TraceEndOnScopeClose::AddEventIfEnabled() {
base::debug::TraceLog::GetInstance()->AddTraceEvent(
base::debug::TRACE_EVENT_PHASE_END,
p_data_->category,
- p_data_->name,
+ p_data_->name, 0,
NULL, 0, NULL, 0,
-1, 0, TraceLog::EVENT_FLAG_NONE);
}
@@ -701,7 +710,7 @@ void TraceEndOnScopeCloseThreshold::AddEventIfEnabled() {
base::debug::TraceLog::GetInstance()->AddTraceEvent(
base::debug::TRACE_EVENT_PHASE_END,
p_data_->category,
- p_data_->name,
+ p_data_->name, 0,
NULL, 0, NULL, 0,
p_data_->threshold_begin_id, p_data_->threshold,
TraceLog::EVENT_FLAG_NONE);

Powered by Google App Engine
This is Rietveld 408576698