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

Unified Diff: base/trace_event/trace_event_impl.cc

Issue 2504753002: tracing: Introduce API for composite IDs (Closed)
Patch Set: Slightly more efficient implementation Created 4 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/trace_event/trace_event_impl.cc
diff --git a/base/trace_event/trace_event_impl.cc b/base/trace_event/trace_event_impl.cc
index f9792d0d6df6aea004447b3bf2a293f50d08e646..1f4e0d6699e2c4e52b7d8e89669c57d7c816ae27 100644
--- a/base/trace_event/trace_event_impl.cc
+++ b/base/trace_event/trace_event_impl.cc
@@ -458,30 +458,34 @@ TraceID::AsConvertableToTraceFormat() const {
if (scope_ != kGlobalScope)
value->SetString("scope", scope_);
- switch (id_flags_) {
- case TRACE_EVENT_FLAG_HAS_ID:
- value->SetString(
- "id",
- base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
- break;
- case TRACE_EVENT_FLAG_HAS_GLOBAL_ID:
- value->BeginDictionary("id2");
- value->SetString(
- "global",
- base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
- value->EndDictionary();
- break;
- case TRACE_EVENT_FLAG_HAS_LOCAL_ID:
- value->BeginDictionary("id2");
- value->SetString(
- "local",
- base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
- value->EndDictionary();
- break;
- default:
- NOTREACHED() << "Unrecognized ID flag";
+
+ std::string id_field_name = "id";
caseq 2016/11/21 19:47:20 looks like this could be const char* instead.
chiniforooshan 2016/11/21 21:12:15 Done.
+ if (id_flags_ == TRACE_EVENT_FLAG_HAS_GLOBAL_ID) {
+ id_field_name = "global";
+ value->BeginDictionary("id2");
+ } else if (id_flags_ == TRACE_EVENT_FLAG_HAS_LOCAL_ID) {
+ id_field_name = "local";
+ value->BeginDictionary("id2");
+ } else if (id_flags_ != TRACE_EVENT_FLAG_HAS_ID) {
+ NOTREACHED() << "Unrecognized ID flag";
}
+ if (has_prefix_) {
+ value->BeginArrayWithCopiedName(id_field_name);
caseq 2016/11/21 19:47:20 ... using const char* would let us get rid of copi
chiniforooshan 2016/11/21 21:12:15 Done.
+ value->AppendString(
+ base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(prefix_)));
+ value->AppendString(
+ base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
+ value->EndArray();
+ } else {
+ value->SetStringWithCopiedName(
+ id_field_name,
+ base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
+ }
+
+ if (id_flags_ != TRACE_EVENT_FLAG_HAS_ID)
+ value->EndDictionary();
+
return std::move(value);
}

Powered by Google App Engine
This is Rietveld 408576698