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

Side by Side 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 unified diff | Download patch
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/string_escape.h" 10 #include "base/json/string_escape.h"
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } // namespace base 451 } // namespace base
452 452
453 namespace trace_event_internal { 453 namespace trace_event_internal {
454 454
455 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 455 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
456 TraceID::AsConvertableToTraceFormat() const { 456 TraceID::AsConvertableToTraceFormat() const {
457 auto value = base::MakeUnique<base::trace_event::TracedValue>(); 457 auto value = base::MakeUnique<base::trace_event::TracedValue>();
458 458
459 if (scope_ != kGlobalScope) 459 if (scope_ != kGlobalScope)
460 value->SetString("scope", scope_); 460 value->SetString("scope", scope_);
461 switch (id_flags_) { 461
462 case TRACE_EVENT_FLAG_HAS_ID: 462 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.
463 value->SetString( 463 if (id_flags_ == TRACE_EVENT_FLAG_HAS_GLOBAL_ID) {
464 "id", 464 id_field_name = "global";
465 base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_))); 465 value->BeginDictionary("id2");
466 break; 466 } else if (id_flags_ == TRACE_EVENT_FLAG_HAS_LOCAL_ID) {
467 case TRACE_EVENT_FLAG_HAS_GLOBAL_ID: 467 id_field_name = "local";
468 value->BeginDictionary("id2"); 468 value->BeginDictionary("id2");
469 value->SetString( 469 } else if (id_flags_ != TRACE_EVENT_FLAG_HAS_ID) {
470 "global", 470 NOTREACHED() << "Unrecognized ID flag";
471 base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
472 value->EndDictionary();
473 break;
474 case TRACE_EVENT_FLAG_HAS_LOCAL_ID:
475 value->BeginDictionary("id2");
476 value->SetString(
477 "local",
478 base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
479 value->EndDictionary();
480 break;
481 default:
482 NOTREACHED() << "Unrecognized ID flag";
483 } 471 }
484 472
473 if (has_prefix_) {
474 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.
475 value->AppendString(
476 base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(prefix_)));
477 value->AppendString(
478 base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
479 value->EndArray();
480 } else {
481 value->SetStringWithCopiedName(
482 id_field_name,
483 base::StringPrintf("0x%" PRIx64, static_cast<uint64_t>(raw_id_)));
484 }
485
486 if (id_flags_ != TRACE_EVENT_FLAG_HAS_ID)
487 value->EndDictionary();
488
485 return std::move(value); 489 return std::move(value);
486 } 490 }
487 491
488 } // namespace trace_event_internal 492 } // namespace trace_event_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698