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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 TraceLog::TraceLog() | 351 TraceLog::TraceLog() |
352 : enable_count_(0), | 352 : enable_count_(0), |
353 dispatching_to_observer_list_(false), | 353 dispatching_to_observer_list_(false), |
354 watch_category_(NULL) { | 354 watch_category_(NULL), |
| 355 trace_mode_(UNTIL_FULL) { |
355 // Trace is enabled or disabled on one thread while other threads are | 356 // 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 | 357 // 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 | 358 // traced or not, so we allow races on the enabled flag to keep the trace |
358 // macros fast. | 359 // macros fast. |
359 // TODO(jbates): ANNOTATE_BENIGN_RACE_SIZED crashes windows TSAN bots: | 360 // TODO(jbates): ANNOTATE_BENIGN_RACE_SIZED crashes windows TSAN bots: |
360 // ANNOTATE_BENIGN_RACE_SIZED(g_category_enabled, sizeof(g_category_enabled), | 361 // ANNOTATE_BENIGN_RACE_SIZED(g_category_enabled, sizeof(g_category_enabled), |
361 // "trace_event category enabled"); | 362 // "trace_event category enabled"); |
362 for (int i = 0; i < TRACE_EVENT_MAX_CATEGORIES; ++i) { | 363 for (int i = 0; i < TRACE_EVENT_MAX_CATEGORIES; ++i) { |
363 ANNOTATE_BENIGN_RACE(&g_category_enabled[i], | 364 ANNOTATE_BENIGN_RACE(&g_category_enabled[i], |
364 "trace_event category enabled"); | 365 "trace_event category enabled"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return category_enabled; | 472 return category_enabled; |
472 } | 473 } |
473 | 474 |
474 void TraceLog::GetKnownCategories(std::vector<std::string>* categories) { | 475 void TraceLog::GetKnownCategories(std::vector<std::string>* categories) { |
475 AutoLock lock(lock_); | 476 AutoLock lock(lock_); |
476 for (int i = 0; i < g_category_index; i++) | 477 for (int i = 0; i < g_category_index; i++) |
477 categories->push_back(g_categories[i]); | 478 categories->push_back(g_categories[i]); |
478 } | 479 } |
479 | 480 |
480 void TraceLog::SetEnabled(const std::vector<std::string>& included_categories, | 481 void TraceLog::SetEnabled(const std::vector<std::string>& included_categories, |
481 const std::vector<std::string>& excluded_categories) { | 482 const std::vector<std::string>& excluded_categories, |
| 483 TraceMode mode) { |
482 AutoLock lock(lock_); | 484 AutoLock lock(lock_); |
483 | 485 |
484 if (enable_count_++ > 0) { | 486 if (enable_count_++ > 0) { |
| 487 if (mode != trace_mode_) { |
| 488 DLOG(ERROR) << "Attemting to re-enable tracing with a different mode."; |
| 489 } |
| 490 |
485 // Tracing is already enabled, so just merge in enabled categories. | 491 // Tracing is already enabled, so just merge in enabled categories. |
486 // We only expand the set of enabled categories upon nested SetEnable(). | 492 // We only expand the set of enabled categories upon nested SetEnable(). |
487 if (!included_categories_.empty() && !included_categories.empty()) { | 493 if (!included_categories_.empty() && !included_categories.empty()) { |
488 included_categories_.insert(included_categories_.end(), | 494 included_categories_.insert(included_categories_.end(), |
489 included_categories.begin(), | 495 included_categories.begin(), |
490 included_categories.end()); | 496 included_categories.end()); |
491 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); | 497 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); |
492 } else { | 498 } else { |
493 // If either old or new included categories are empty, allow all events. | 499 // If either old or new included categories are empty, allow all events. |
494 included_categories_.clear(); | 500 included_categories_.clear(); |
495 excluded_categories_.clear(); | 501 excluded_categories_.clear(); |
496 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); | 502 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); |
497 } | 503 } |
498 return; | 504 return; |
499 } | 505 } |
| 506 trace_mode_ = mode; |
500 | 507 |
501 if (dispatching_to_observer_list_) { | 508 if (dispatching_to_observer_list_) { |
502 DLOG(ERROR) << | 509 DLOG(ERROR) << |
503 "Cannot manipulate TraceLog::Enabled state from an observer."; | 510 "Cannot manipulate TraceLog::Enabled state from an observer."; |
504 return; | 511 return; |
505 } | 512 } |
506 | 513 |
507 dispatching_to_observer_list_ = true; | 514 dispatching_to_observer_list_ = true; |
508 FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_, | 515 FOR_EACH_OBSERVER(EnabledStateChangedObserver, enabled_state_observer_list_, |
509 OnTraceLogWillEnable()); | 516 OnTraceLogWillEnable()); |
510 dispatching_to_observer_list_ = false; | 517 dispatching_to_observer_list_ = false; |
511 | 518 |
512 logged_events_.reserve(1024); | 519 logged_events_.reserve(1024); |
513 included_categories_ = included_categories; | 520 included_categories_ = included_categories; |
514 excluded_categories_ = excluded_categories; | 521 excluded_categories_ = excluded_categories; |
515 // Note that if both included and excluded_categories are empty, the else | 522 // Note that if both included and excluded_categories are empty, the else |
516 // clause below excludes nothing, thereby enabling all categories. | 523 // clause below excludes nothing, thereby enabling all categories. |
517 if (!included_categories_.empty()) | 524 if (!included_categories_.empty()) |
518 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); | 525 EnableMatchingCategories(included_categories_, CATEGORY_ENABLED, 0); |
519 else | 526 else |
520 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); | 527 EnableMatchingCategories(excluded_categories_, 0, CATEGORY_ENABLED); |
521 } | 528 } |
522 | 529 |
523 void TraceLog::SetEnabled(const std::string& categories) { | 530 void TraceLog::SetEnabled(const std::string& categories, TraceMode mode) { |
524 std::vector<std::string> included, excluded; | 531 std::vector<std::string> included, excluded; |
525 // Tokenize list of categories, delimited by ','. | 532 // Tokenize list of categories, delimited by ','. |
526 StringTokenizer tokens(categories, ","); | 533 StringTokenizer tokens(categories, ","); |
527 while (tokens.GetNext()) { | 534 while (tokens.GetNext()) { |
528 bool is_included = true; | 535 bool is_included = true; |
529 std::string category = tokens.token(); | 536 std::string category = tokens.token(); |
530 // Excluded categories start with '-'. | 537 // Excluded categories start with '-'. |
531 if (category.at(0) == '-') { | 538 if (category.at(0) == '-') { |
532 // Remove '-' from category string. | 539 // Remove '-' from category string. |
533 category = category.substr(1); | 540 category = category.substr(1); |
534 is_included = false; | 541 is_included = false; |
535 } | 542 } |
536 if (is_included) | 543 if (is_included) |
537 included.push_back(category); | 544 included.push_back(category); |
538 else | 545 else |
539 excluded.push_back(category); | 546 excluded.push_back(category); |
540 } | 547 } |
541 SetEnabled(included, excluded); | 548 SetEnabled(included, excluded, mode); |
542 } | 549 } |
543 | 550 |
544 void TraceLog::GetEnabledTraceCategories( | 551 void TraceLog::GetEnabledTraceCategories( |
545 std::vector<std::string>* included_out, | 552 std::vector<std::string>* included_out, |
546 std::vector<std::string>* excluded_out) { | 553 std::vector<std::string>* excluded_out) { |
547 AutoLock lock(lock_); | 554 AutoLock lock(lock_); |
548 if (enable_count_) { | 555 if (enable_count_) { |
549 *included_out = included_categories_; | 556 *included_out = included_categories_; |
550 *excluded_out = excluded_categories_; | 557 *excluded_out = excluded_categories_; |
551 } | 558 } |
(...skipping 18 matching lines...) Expand all Loading... |
570 | 577 |
571 included_categories_.clear(); | 578 included_categories_.clear(); |
572 excluded_categories_.clear(); | 579 excluded_categories_.clear(); |
573 watch_category_ = NULL; | 580 watch_category_ = NULL; |
574 watch_event_name_ = ""; | 581 watch_event_name_ = ""; |
575 for (int i = 0; i < g_category_index; i++) | 582 for (int i = 0; i < g_category_index; i++) |
576 g_category_enabled[i] = 0; | 583 g_category_enabled[i] = 0; |
577 AddThreadNameMetadataEvents(); | 584 AddThreadNameMetadataEvents(); |
578 } | 585 } |
579 | 586 |
580 void TraceLog::SetEnabled(bool enabled) { | 587 void TraceLog::SetEnabled(bool enabled, TraceMode mode) { |
581 if (enabled) | 588 if (enabled) |
582 SetEnabled(std::vector<std::string>(), std::vector<std::string>()); | 589 SetEnabled(std::vector<std::string>(), std::vector<std::string>(), mode); |
583 else | 590 else |
584 SetDisabled(); | 591 SetDisabled(); |
585 } | 592 } |
586 | 593 |
587 void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) { | 594 void TraceLog::AddEnabledStateObserver(EnabledStateChangedObserver* listener) { |
588 enabled_state_observer_list_.AddObserver(listener); | 595 enabled_state_observer_list_.AddObserver(listener); |
589 } | 596 } |
590 | 597 |
591 void TraceLog::RemoveEnabledStateObserver( | 598 void TraceLog::RemoveEnabledStateObserver( |
592 EnabledStateChangedObserver* listener) { | 599 EnabledStateChangedObserver* listener) { |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 0, // num_args | 869 0, // num_args |
863 NULL, // arg_names | 870 NULL, // arg_names |
864 NULL, // arg_types | 871 NULL, // arg_types |
865 NULL, // arg_values | 872 NULL, // arg_values |
866 TRACE_EVENT_FLAG_NONE); // flags | 873 TRACE_EVENT_FLAG_NONE); // flags |
867 } | 874 } |
868 } | 875 } |
869 | 876 |
870 } // namespace trace_event_internal | 877 } // namespace trace_event_internal |
871 | 878 |
OLD | NEW |