OLD | NEW |
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/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/debug/leak_annotations.h" | 10 #include "base/debug/leak_annotations.h" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 void TraceLog::NotificationHelper::SendNotificationIfAny() { | 341 void TraceLog::NotificationHelper::SendNotificationIfAny() { |
342 if (notification_) | 342 if (notification_) |
343 callback_copy_.Run(notification_); | 343 callback_copy_.Run(notification_); |
344 } | 344 } |
345 | 345 |
346 // static | 346 // static |
347 TraceLog* TraceLog::GetInstance() { | 347 TraceLog* TraceLog::GetInstance() { |
348 return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog> >::get(); | 348 return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog> >::get(); |
349 } | 349 } |
350 | 350 |
| 351 // static |
| 352 TraceLog::TraceMode TraceLog::TraceModeFromString(const std::string& str) { |
| 353 if (str == "until_full") |
| 354 return UNTIL_FULL; |
| 355 return UNTIL_FULL; |
| 356 } |
| 357 |
| 358 // static |
| 359 const std::string TraceLog::StringFromTraceMode(TraceMode mode) { |
| 360 switch(mode) { |
| 361 case UNTIL_FULL: |
| 362 return "until_full"; |
| 363 default: |
| 364 return ""; |
| 365 } |
| 366 } |
| 367 |
351 TraceLog::TraceLog() | 368 TraceLog::TraceLog() |
352 : enable_count_(0), | 369 : enable_count_(0), |
353 dispatching_to_observer_list_(false), | 370 dispatching_to_observer_list_(false), |
354 watch_category_(NULL) { | 371 watch_category_(NULL), |
| 372 trace_mode_(UNTIL_FULL) { |
355 // Trace is enabled or disabled on one thread while other threads are | 373 // Trace is enabled or disabled on one thread while other threads are |
356 // accessing the enabled flag. We don't care whether edge-case events are | 374 // accessing the enabled flag. We don't care whether edge-case events are |
357 // traced or not, so we allow races on the enabled flag to keep the trace | 375 // traced or not, so we allow races on the enabled flag to keep the trace |
358 // macros fast. | 376 // macros fast. |
359 // TODO(jbates): ANNOTATE_BENIGN_RACE_SIZED crashes windows TSAN bots: | 377 // TODO(jbates): ANNOTATE_BENIGN_RACE_SIZED crashes windows TSAN bots: |
360 // ANNOTATE_BENIGN_RACE_SIZED(g_category_enabled, sizeof(g_category_enabled), | 378 // ANNOTATE_BENIGN_RACE_SIZED(g_category_enabled, sizeof(g_category_enabled), |
361 // "trace_event category enabled"); | 379 // "trace_event category enabled"); |
362 for (int i = 0; i < TRACE_EVENT_MAX_CATEGORIES; ++i) { | 380 for (int i = 0; i < TRACE_EVENT_MAX_CATEGORIES; ++i) { |
363 ANNOTATE_BENIGN_RACE(&g_category_enabled[i], | 381 ANNOTATE_BENIGN_RACE(&g_category_enabled[i], |
364 "trace_event category enabled"); | 382 "trace_event category enabled"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return category_enabled; | 489 return category_enabled; |
472 } | 490 } |
473 | 491 |
474 void TraceLog::GetKnownCategories(std::vector<std::string>* categories) { | 492 void TraceLog::GetKnownCategories(std::vector<std::string>* categories) { |
475 AutoLock lock(lock_); | 493 AutoLock lock(lock_); |
476 for (int i = 0; i < g_category_index; i++) | 494 for (int i = 0; i < g_category_index; i++) |
477 categories->push_back(g_categories[i]); | 495 categories->push_back(g_categories[i]); |
478 } | 496 } |
479 | 497 |
480 void TraceLog::SetEnabled(const std::vector<std::string>& included_categories, | 498 void TraceLog::SetEnabled(const std::vector<std::string>& included_categories, |
481 const std::vector<std::string>& excluded_categories) { | 499 const std::vector<std::string>& excluded_categories, |
| 500 TraceMode mode) { |
482 AutoLock lock(lock_); | 501 AutoLock lock(lock_); |
483 | 502 |
484 if (enable_count_++ > 0) { | 503 if (enable_count_++ > 0) { |
| 504 if (mode != trace_mode_) { |
| 505 DLOG(ERROR) << "Attemting to re-enable tracing with a different mode."; |
| 506 } |
| 507 |
485 // Tracing is already enabled, so just merge in enabled categories. | 508 // Tracing is already enabled, so just merge in enabled categories. |
486 // We only expand the set of enabled categories upon nested SetEnable(). | 509 // We only expand the set of enabled categories upon nested SetEnable(). |
487 if (!included_categories_.empty() && !included_categories.empty()) { | 510 if (!included_categories_.empty() && !included_categories.empty()) { |
488 included_categories_.insert(included_categories_.end(), | 511 included_categories_.insert(included_categories_.end(), |
489 included_categories.begin(), | 512 included_categories.begin(), |
490 included_categories.end()); | 513 included_categories.end()); |
491 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); | 514 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); |
492 } else { | 515 } else { |
493 // If either old or new included categories are empty, allow all events. | 516 // If either old or new included categories are empty, allow all events. |
494 included_categories_.clear(); | 517 included_categories_.clear(); |
495 excluded_categories_.clear(); | 518 excluded_categories_.clear(); |
496 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); | 519 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); |
497 } | 520 } |
498 return; | 521 return; |
499 } | 522 } |
| 523 trace_mode_ = mode; |
500 | 524 |
501 if (dispatching_to_observer_list_) { | 525 if (dispatching_to_observer_list_) { |
502 DLOG(ERROR) << | 526 DLOG(ERROR) << |
503 "Cannot manipulate TraceLog::Enabled state from an observer."; | 527 "Cannot manipulate TraceLog::Enabled state from an observer."; |
504 return; | 528 return; |
505 } | 529 } |
506 | 530 |
507 dispatching_to_observer_list_ = true; | 531 dispatching_to_observer_list_ = true; |
508 FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_, | 532 FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_, |
509 OnTraceLogWillEnable()); | 533 OnTraceLogWillEnable()); |
510 dispatching_to_observer_list_ = false; | 534 dispatching_to_observer_list_ = false; |
511 | 535 |
512 logged_events_.reserve(1024); | 536 logged_events_.reserve(1024); |
513 included_categories_ = included_categories; | 537 included_categories_ = included_categories; |
514 excluded_categories_ = excluded_categories; | 538 excluded_categories_ = excluded_categories; |
515 // Note that if both included and excluded_categories are empty, the else | 539 // Note that if both included and excluded_categories are empty, the else |
516 // clause below excludes nothing, thereby enabling all categories. | 540 // clause below excludes nothing, thereby enabling all categories. |
517 if (!included_categories_.empty()) | 541 if (!included_categories_.empty()) |
518 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); | 542 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); |
519 else | 543 else |
520 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); | 544 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); |
521 } | 545 } |
522 | 546 |
523 void TraceLog::SetEnabled(const std::string& categories) { | 547 void TraceLog::SetEnabled(const std::string& categories, TraceMode mode) { |
524 std::vector<std::string> included, excluded; | 548 std::vector<std::string> included, excluded; |
525 // Tokenize list of categories, delimited by ','. | 549 // Tokenize list of categories, delimited by ','. |
526 StringTokenizer tokens(categories, ","); | 550 StringTokenizer tokens(categories, ","); |
527 while (tokens.GetNext()) { | 551 while (tokens.GetNext()) { |
528 bool is_included = true; | 552 bool is_included = true; |
529 std::string category = tokens.token(); | 553 std::string category = tokens.token(); |
530 // Excluded categories start with '-'. | 554 // Excluded categories start with '-'. |
531 if (category.at(0) == '-') { | 555 if (category.at(0) == '-') { |
532 // Remove '-' from category string. | 556 // Remove '-' from category string. |
533 category = category.substr(1); | 557 category = category.substr(1); |
534 is_included = false; | 558 is_included = false; |
535 } | 559 } |
536 if (is_included) | 560 if (is_included) |
537 included.push_back(category); | 561 included.push_back(category); |
538 else | 562 else |
539 excluded.push_back(category); | 563 excluded.push_back(category); |
540 } | 564 } |
541 SetEnabled(included, excluded); | 565 SetEnabled(included, excluded, mode); |
542 } | 566 } |
543 | 567 |
544 void TraceLog::GetEnabledTraceCategories( | 568 void TraceLog::GetEnabledTraceCategories( |
545 std::vector<std::string>* included_out, | 569 std::vector<std::string>* included_out, |
546 std::vector<std::string>* excluded_out) { | 570 std::vector<std::string>* excluded_out) { |
547 AutoLock lock(lock_); | 571 AutoLock lock(lock_); |
548 if (enable_count_) { | 572 if (enable_count_) { |
549 *included_out = included_categories_; | 573 *included_out = included_categories_; |
550 *excluded_out = excluded_categories_; | 574 *excluded_out = excluded_categories_; |
551 } | 575 } |
(...skipping 18 matching lines...) Expand all Loading... |
570 | 594 |
571 included_categories_.clear(); | 595 included_categories_.clear(); |
572 excluded_categories_.clear(); | 596 excluded_categories_.clear(); |
573 watch_category_ = NULL; | 597 watch_category_ = NULL; |
574 watch_event_name_ = ""; | 598 watch_event_name_ = ""; |
575 for (int i = 0; i < g_category_index; i++) | 599 for (int i = 0; i < g_category_index; i++) |
576 g_category_enabled[i] = 0; | 600 g_category_enabled[i] = 0; |
577 AddThreadNameMetadataEvents(); | 601 AddThreadNameMetadataEvents(); |
578 } | 602 } |
579 | 603 |
580 void TraceLog::SetEnabled(bool enabled) { | 604 void TraceLog::SetEnabled(bool enabled, TraceMode mode) { |
581 if (enabled) | 605 if (enabled) |
582 SetEnabled(std::vector<std::string>(), std::vector<std::string>()); | 606 SetEnabled(std::vector<std::string>(), std::vector<std::string>(), mode); |
583 else | 607 else |
584 SetDisabled(); | 608 SetDisabled(); |
585 } | 609 } |
586 | 610 |
587 void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) { | 611 void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) { |
588 enabled_state_observer_list_.AddObserver(listener); | 612 enabled_state_observer_list_.AddObserver(listener); |
589 } | 613 } |
590 | 614 |
591 void TraceLog::RemoveEnabledStateObserver( | 615 void TraceLog::RemoveEnabledStateObserver( |
592 EnabledStateChangedObserver* listener) { | 616 EnabledStateChangedObserver* listener) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 0, // num_args | 886 0, // num_args |
863 NULL, // arg_names | 887 NULL, // arg_names |
864 NULL, // arg_types | 888 NULL, // arg_types |
865 NULL, // arg_values | 889 NULL, // arg_values |
866 TRACE_EVENT_FLAG_NONE); // flags | 890 TRACE_EVENT_FLAG_NONE); // flags |
867 } | 891 } |
868 } | 892 } |
869 | 893 |
870 } // namespace trace_event_internal | 894 } // namespace trace_event_internal |
871 | 895 |
OLD | NEW |