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

Side by Side Diff: base/trace_event/trace_event_impl.h

Issue 1115023003: [Startup Tracing] The TraceConfig class [STALE] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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 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
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;
dsinclair 2015/05/08 17:44:50 Can we just merge this straight into TraceConfig w
Zhen Wang 2015/05/13 00:01:11 Many places are using CategoryFilter. Do you mean
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_;
nednguyen 2015/05/11 17:59:28 Why not just make this a value instead of scoped_p
Zhen Wang 2015/05/13 00:01:11 There will be extra copies in the constructors, ri
nednguyen 2015/05/13 18:16:31 Chatted offline. It doesn't matter much & the comp
Zhen Wang 2015/05/13 20:59:16 Done.
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
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;
dsinclair 2015/05/08 17:44:49 Is this worth typedef'ing?
Zhen Wang 2015/05/13 00:01:11 I was following the style used in CategoryFilter,
429
430 // The default trace config, used when none is provided.
431 // Allows all categories through, except if they end in the suffix 'Debug' or
dsinclair 2015/05/08 17:44:49 Is this true? We don't want to allow disable-by-de
Zhen Wang 2015/05/13 00:01:11 This is converted from kDefaultCategoryFilterStrin
432 // 'Test'.
433 static const char kDefaultTraceConfigString[];
dsinclair 2015/05/08 17:44:49 Does this need to be in the public header? Can it
Zhen Wang 2015/05/13 00:01:11 This is removed now as we will use InitializeDefau
434
435 TraceConfig();
436
437 // Create TraceConfig object from CategoryFilter and TraceOptions.
438 TraceConfig(const CategoryFilter& cf, const TraceOptions& options);
439
440 // Create TraceConfig object from category filter and trace options strings.
441 TraceConfig(const std::string& category_filter_string,
442 const std::string& trace_options_string);
443
444 // |config_string| is a JSON formated string, containing both category filters
dsinclair 2015/05/08 17:44:49 Can you add a similar comment to the above here:
Zhen Wang 2015/05/13 00:01:11 Done.
445 // and trace options.
446 TraceConfig(const std::string& config_string);
dsinclair 2015/05/08 17:44:50 nit: explicit
Zhen Wang 2015/05/13 00:01:11 Done.
447
448 TraceConfig(const TraceConfig& tc);
dsinclair 2015/05/08 17:44:50 nit: explicit
Zhen Wang 2015/05/13 00:01:10 Done.
449
450 ~TraceConfig();
451
452 TraceConfig& operator=(const TraceConfig& rhs);
dsinclair 2015/05/08 17:44:49 Do we use copy and assign for this?
Zhen Wang 2015/05/13 00:01:11 Not now. But it may be used later when updating th
dsinclair 2015/05/21 13:42:07 In that case, let's add the DISALLOW for now and w
Zhen Wang 2015/05/22 23:38:04 COPY and ASSIGN are needed to implement CategoryFi
dsinclair 2015/05/25 13:36:02 I'm confused, above you said they aren't used? So,
453
454 // Return a list of the synthetic delays specified in this category filter.
455 const StringList& GetSyntheticDelayValues() const;
456
457 // Convert TraceConfig to CategoryFilter.
458 void ToCategoryFilter(CategoryFilter& cf) const;
dsinclair 2015/05/08 17:44:49 Are these ToXXX methods only for tests? I don't se
Zhen Wang 2015/05/13 00:01:11 Removed now.
459
460 // Convert TraceConfig to TraceOptions.
461 void ToTraceOptions(TraceOptions& options) const;
462
463 // Convert TraceConfig to the dict representation of the TraceConfig.
464 void ToDict(base::DictionaryValue& dict) const;
nednguyen 2015/05/11 17:59:28 Do we actually need this API?
Zhen Wang 2015/05/13 00:01:11 I think this can be used by slow report.
dsinclair 2015/05/21 13:42:07 Can we determine if it is or isn't? I'd prefer to
Zhen Wang 2015/05/22 23:38:04 Fadi has confirmed that this is not needed in the
465
466 // Writes the string representation of the TraceConfig. The string is JSON
467 // formatted.
468 std::string ToString() const;
469
470 // Write the string representation of the CategoryFilter part.
471 std::string ToCategoryFilterString() const;
472
473 // Write the string representation of the TraceOptions part.
474 std::string ToTraceOptionsString() const;
475
476 // Returns true if at least one category in the list is enabled by this
dsinclair 2015/05/08 17:44:49 How does this interact with disabled categories? I
Zhen Wang 2015/05/13 00:01:11 Yes, it will be considered enabled. This comes fro
477 // trace config.
478 bool IsCategoryGroupEnabled(const char* category_group) const;
479
480 // Merges config with the current TraceConfig
481 void Merge(const TraceConfig& config);
dsinclair 2015/05/08 17:44:49 Will this go away when CategoryFilter is removed?
Zhen Wang 2015/05/13 00:01:11 This will live on. It is used by TraceLog. See htt
482
483 void Clear();
dsinclair 2015/05/08 17:44:50 Is this needed? Or just for tests? If for tests, d
Zhen Wang 2015/05/13 00:01:11 Clear() will be used by TraceLog. See https://code
484
485 private:
486 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfigFromAndToString);
487 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest, TraceConfig);
488 friend class CategoryFilter;
489
490 void Initialize(const std::string& config_string);
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_;
dsinclair 2015/05/08 17:44:50 bool enable_sampling_ : 1; bool enable_systrace_ :
Zhen Wang 2015/05/13 00:01:11 Those two members will be used in TraceConfig::Ini
dsinclair 2015/05/21 13:42:07 Sure, but we can also easily change the initialize
Zhen Wang 2015/05/22 23:38:04 Done.
508
509 StringList included_categories_;
510 StringList disabled_categories_;
511 StringList excluded_categories_;
512 StringList synthetic_delays_;
513 };
dsinclair 2015/05/08 17:44:50 Should this have a DISALLOW_COPY_AND_ASSIGN?
Zhen Wang 2015/05/13 00:01:10 Existing CategoryFilter has copy constructor and o
dsinclair 2015/05/21 13:42:07 If it isn't needed let, let's put in the DISALLOW.
Zhen Wang 2015/05/22 23:38:04 COPY and ASSIGN are needed to implement CategoryFi
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
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_
OLDNEW
« no previous file with comments | « no previous file | base/trace_event/trace_event_impl.cc » ('j') | base/trace_event/trace_event_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698