| 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 | 5 |
| 6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 6 #ifndef BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
| 7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 7 #define BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
| 8 | 8 |
| 9 #include <stack> | 9 #include <stack> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/atomicops.h" | 13 #include "base/atomicops.h" |
| 14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "base/synchronization/condition_variable.h" | 23 #include "base/synchronization/condition_variable.h" |
| 24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
| 25 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 26 #include "base/threading/thread_local.h" | 26 #include "base/threading/thread_local.h" |
| 27 #include "base/values.h" |
| 27 | 28 |
| 28 // Older style trace macros with explicit id and extra data | 29 // Older style trace macros with explicit id and extra data |
| 29 // Only these macros result in publishing data to ETW as currently implemented. | 30 // Only these macros result in publishing data to ETW as currently implemented. |
| 30 // TODO(georgesak): Update/replace these with new ETW macros. | 31 // TODO(georgesak): Update/replace these with new ETW macros. |
| 31 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ | 32 #define TRACE_EVENT_BEGIN_ETW(name, id, extra) \ |
| 32 base::trace_event::TraceLog::AddTraceEventEtw( \ | 33 base::trace_event::TraceLog::AddTraceEventEtw( \ |
| 33 TRACE_EVENT_PHASE_BEGIN, \ | 34 TRACE_EVENT_PHASE_BEGIN, \ |
| 34 name, reinterpret_cast<const void*>(id), extra) | 35 name, reinterpret_cast<const void*>(id), extra) |
| 35 | 36 |
| 36 #define TRACE_EVENT_END_ETW(name, id, extra) \ | 37 #define TRACE_EVENT_END_ETW(name, id, extra) \ |
| 37 base::trace_event::TraceLog::AddTraceEventEtw( \ | 38 base::trace_event::TraceLog::AddTraceEventEtw( \ |
| 38 TRACE_EVENT_PHASE_END, \ | 39 TRACE_EVENT_PHASE_END, \ |
| 39 name, reinterpret_cast<const void*>(id), extra) | 40 name, reinterpret_cast<const void*>(id), extra) |
| 40 | 41 |
| 41 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ | 42 #define TRACE_EVENT_INSTANT_ETW(name, id, extra) \ |
| 42 base::trace_event::TraceLog::AddTraceEventEtw( \ | 43 base::trace_event::TraceLog::AddTraceEventEtw( \ |
| 43 TRACE_EVENT_PHASE_INSTANT, \ | 44 TRACE_EVENT_PHASE_INSTANT, \ |
| 44 name, reinterpret_cast<const void*>(id), extra) | 45 name, reinterpret_cast<const void*>(id), extra) |
| 45 | 46 |
| 46 template <typename Type> | 47 template <typename Type> |
| 47 struct DefaultSingletonTraits; | 48 struct DefaultSingletonTraits; |
| 48 | 49 |
| 49 namespace base { | 50 namespace base { |
| 50 | 51 |
| 51 class WaitableEvent; | 52 class WaitableEvent; |
| 52 class MessageLoop; | 53 class MessageLoop; |
| 53 | 54 |
| 54 namespace trace_event { | 55 namespace trace_event { |
| 55 | 56 |
| 57 class TraceConfig; |
| 58 |
| 56 // For any argument of type TRACE_VALUE_TYPE_CONVERTABLE the provided | 59 // For any argument of type TRACE_VALUE_TYPE_CONVERTABLE the provided |
| 57 // class must implement this interface. | 60 // class must implement this interface. |
| 58 class BASE_EXPORT ConvertableToTraceFormat | 61 class BASE_EXPORT ConvertableToTraceFormat |
| 59 : public RefCounted<ConvertableToTraceFormat> { | 62 : public RefCounted<ConvertableToTraceFormat> { |
| 60 public: | 63 public: |
| 61 // Append the class info to the provided |out| string. The appended | 64 // Append the class info to the provided |out| string. The appended |
| 62 // data must be a valid JSON object. Strings must be properly quoted, and | 65 // data must be a valid JSON object. Strings must be properly quoted, and |
| 63 // escaped. There is no processing applied to the content after it is | 66 // escaped. There is no processing applied to the content after it is |
| 64 // appended. | 67 // appended. |
| 65 virtual void AppendAsTraceFormat(std::string* out) const = 0; | 68 virtual void AppendAsTraceFormat(std::string* out) const = 0; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 // Clears both included/excluded pattern lists. This would be equivalent to | 338 // Clears both included/excluded pattern lists. This would be equivalent to |
| 336 // creating a CategoryFilter with an empty string, through the constructor. | 339 // creating a CategoryFilter with an empty string, through the constructor. |
| 337 // i.e: CategoryFilter(). | 340 // i.e: CategoryFilter(). |
| 338 // | 341 // |
| 339 // When using an empty filter, all categories are considered included as we | 342 // When using an empty filter, all categories are considered included as we |
| 340 // are not excluding anything. | 343 // are not excluding anything. |
| 341 void Clear(); | 344 void Clear(); |
| 342 | 345 |
| 343 private: | 346 private: |
| 344 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter); | 347 FRIEND_TEST_ALL_PREFIXES(TraceEventTestFixture, CategoryFilter); |
| 348 friend class TraceConfig; |
| 345 | 349 |
| 346 // Returns true if category is enable according to this filter. | 350 // Returns true if category is enable according to this filter. |
| 347 bool IsCategoryEnabled(const char* category_name) const; | 351 bool IsCategoryEnabled(const char* category_name) const; |
| 348 | 352 |
| 349 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( | 353 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( |
| 350 const std::string& str); | 354 const std::string& str); |
| 351 | 355 |
| 352 void Initialize(const std::string& filter_string); | 356 void Initialize(const std::string& filter_string); |
| 353 void WriteString(const StringList& values, | 357 void WriteString(const StringList& values, |
| 354 std::string* out, | 358 std::string* out, |
| 355 bool included) const; | 359 bool included) const; |
| 356 void WriteString(const StringList& delays, std::string* out) const; | 360 void WriteString(const StringList& delays, std::string* out) const; |
| 357 bool HasIncludedPatterns() const; | 361 bool HasIncludedPatterns() const; |
| 358 | 362 |
| 359 StringList included_; | 363 scoped_ptr<TraceConfig> config_; |
| 360 StringList disabled_; | |
| 361 StringList excluded_; | |
| 362 StringList delays_; | |
| 363 }; | 364 }; |
| 364 | 365 |
| 365 class TraceSamplingThread; | 366 class TraceSamplingThread; |
| 366 | 367 |
| 367 // Options determines how the trace buffer stores data. | 368 // Options determines how the trace buffer stores data. |
| 368 enum TraceRecordMode { | 369 enum TraceRecordMode { |
| 369 // Record until the trace buffer is full. | 370 // Record until the trace buffer is full. |
| 370 RECORD_UNTIL_FULL, | 371 RECORD_UNTIL_FULL, |
| 371 | 372 |
| 372 // Record until the user ends the trace. The trace buffer is a fixed size | 373 // Record until the user ends the trace. The trace buffer is a fixed size |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // Returns true on success. | 416 // Returns true on success. |
| 416 bool SetFromString(const std::string& options_string); | 417 bool SetFromString(const std::string& options_string); |
| 417 | 418 |
| 418 std::string ToString() const; | 419 std::string ToString() const; |
| 419 | 420 |
| 420 TraceRecordMode record_mode; | 421 TraceRecordMode record_mode; |
| 421 bool enable_sampling; | 422 bool enable_sampling; |
| 422 bool enable_systrace; | 423 bool enable_systrace; |
| 423 }; | 424 }; |
| 424 | 425 |
| 426 class BASE_EXPORT TraceConfig { |
| 427 public: |
| 428 typedef std::vector<std::string> StringList; |
| 429 |
| 430 TraceConfig(); |
| 431 |
| 432 // Create TraceConfig object from CategoryFilter and TraceOptions. |
| 433 TraceConfig(const CategoryFilter& cf, const TraceOptions& options); |
| 434 |
| 435 // Create TraceConfig object from category filter and trace options strings. |
| 436 TraceConfig(const std::string& category_filter_string, |
| 437 const std::string& trace_options_string); |
| 438 |
| 439 // |config_string| is a dictionary formatted as a JSON string, containing both |
| 440 // category filters and trace options. |
| 441 explicit TraceConfig(const std::string& config_string); |
| 442 |
| 443 explicit TraceConfig(const TraceConfig& tc); |
| 444 |
| 445 ~TraceConfig(); |
| 446 |
| 447 TraceConfig& operator=(const TraceConfig& rhs); |
| 448 |
| 449 // Return a list of the synthetic delays specified in this category filter. |
| 450 const StringList& GetSyntheticDelayValues() const; |
| 451 |
| 452 // Convert TraceConfig to the dict representation of the TraceConfig. |
| 453 void ToDict(base::DictionaryValue& dict) const; |
| 454 |
| 455 // Writes the string representation of the TraceConfig. The string is JSON |
| 456 // formatted. |
| 457 std::string ToString() const; |
| 458 |
| 459 // Write the string representation of the CategoryFilter part. |
| 460 std::string ToCategoryFilterString() const; |
| 461 |
| 462 // Write the string representation of the TraceOptions part. |
| 463 std::string ToTraceOptionsString() const; |
| 464 |
| 465 // Returns true if at least one category in the list is enabled by this |
| 466 // trace config. |
| 467 bool IsCategoryGroupEnabled(const char* category_group) const; |
| 468 |
| 469 // Merges config with the current TraceConfig |
| 470 void Merge(const TraceConfig& config); |
| 471 |
| 472 void Clear(); |
| 473 |
| 474 private: |
| 475 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidLegacyString); |
| 476 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidLegacyString); |
| 477 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, ConstructDefaultTraceConfig); |
| 478 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromValidString); |
| 479 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromInvalidString); |
| 480 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, |
| 481 IsEmptyOrContainsLeadingOrTrailingWhitespace); |
| 482 friend class CategoryFilter; |
| 483 |
| 484 void Initialize(const std::string& config_string); |
| 485 |
| 486 // The default trace config, used when none is provided. |
| 487 // Allows all categories through, except if they end in the suffix 'Debug' or |
| 488 // 'Test'. |
| 489 void InitializeDefault(); |
| 490 |
| 491 void SetCategoriesFromList(StringList& categories, |
| 492 const base::ListValue& list); |
| 493 void AddCategoryToDict(base::DictionaryValue& dict, |
| 494 const char* param, |
| 495 const StringList& categories) const; |
| 496 |
| 497 // Returns true if category is enable according to this trace config. |
| 498 bool IsCategoryEnabled(const char* category_name) const; |
| 499 |
| 500 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace( |
| 501 const std::string& str); |
| 502 |
| 503 bool HasIncludedPatterns() const; |
| 504 |
| 505 TraceRecordMode record_mode_; |
| 506 bool enable_sampling_; |
| 507 bool enable_systrace_; |
| 508 |
| 509 StringList included_categories_; |
| 510 StringList disabled_categories_; |
| 511 StringList excluded_categories_; |
| 512 StringList synthetic_delays_; |
| 513 }; |
| 514 |
| 425 struct BASE_EXPORT TraceLogStatus { | 515 struct BASE_EXPORT TraceLogStatus { |
| 426 TraceLogStatus(); | 516 TraceLogStatus(); |
| 427 ~TraceLogStatus(); | 517 ~TraceLogStatus(); |
| 428 size_t event_capacity; | 518 size_t event_capacity; |
| 429 size_t event_count; | 519 size_t event_count; |
| 430 }; | 520 }; |
| 431 | 521 |
| 432 class BASE_EXPORT TraceLog { | 522 class BASE_EXPORT TraceLog { |
| 433 public: | 523 public: |
| 434 enum Mode { | 524 enum Mode { |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 subtle::AtomicWord generation_; | 904 subtle::AtomicWord generation_; |
| 815 bool use_worker_thread_; | 905 bool use_worker_thread_; |
| 816 | 906 |
| 817 DISALLOW_COPY_AND_ASSIGN(TraceLog); | 907 DISALLOW_COPY_AND_ASSIGN(TraceLog); |
| 818 }; | 908 }; |
| 819 | 909 |
| 820 } // namespace trace_event | 910 } // namespace trace_event |
| 821 } // namespace base | 911 } // namespace base |
| 822 | 912 |
| 823 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ | 913 #endif // BASE_TRACE_EVENT_TRACE_EVENT_IMPL_H_ |
| OLD | NEW |