1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_TRACE_EVENT_TRACE_CONFIG_H_
6 #define BASE_TRACE_EVENT_TRACE_CONFIG_H_
11 #include "base/base_export.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/trace_event/category_filter.h"
14 #include "base/trace_event/trace_options.h"
15 #include "base/values.h"
18 namespace trace_event
{
22 class BASE_EXPORT TraceConfig
{
24 typedef std::vector
<std::string
> StringList
;
28 // Create TraceConfig object from CategoryFilter and TraceOptions.
29 TraceConfig(const CategoryFilter
& cf
, const TraceOptions
& options
);
31 // Create TraceConfig object from category filter and trace options strings.
32 TraceConfig(const std::string
& category_filter_string
,
33 const std::string
& trace_options_string
);
35 // |config_string| is a dictionary formatted as a JSON string, containing both
36 // category filters and trace options.
37 explicit TraceConfig(const std::string
& config_string
);
41 // Return a list of the synthetic delays specified in this category filter.
42 const StringList
& GetSyntheticDelayValues() const;
44 // Writes the string representation of the TraceConfig. The string is JSON
46 std::string
ToString() const;
48 // Write the string representation of the CategoryFilter part.
49 std::string
ToCategoryFilterString() const;
51 // Returns true if at least one category in the list is enabled by this
53 bool IsCategoryGroupEnabled(const char* category_group
) const;
55 // Merges config with the current TraceConfig
56 void Merge(const TraceConfig
& config
);
61 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
, TraceConfigFromValidLegacyStrings
);
62 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
,
63 TraceConfigFromInvalidLegacyStrings
);
64 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
, ConstructDefaultTraceConfig
);
65 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
, TraceConfigFromValidString
);
66 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
, TraceConfigFromInvalidString
);
67 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
, MergingTraceConfigs
);
68 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
, IsCategoryGroupEnabled
);
69 FRIEND_TEST_ALL_PREFIXES(TraceConfigTest
,
70 IsEmptyOrContainsLeadingOrTrailingWhitespace
);
71 friend class CategoryFilter
;
73 // TODO(zhenw): remove COPY and ASSIGN after CategoryFilter is removed.
74 explicit TraceConfig(const TraceConfig
& tc
);
75 TraceConfig
& operator=(const TraceConfig
& rhs
);
77 // The default trace config, used when none is provided.
78 // Allows all non-disabled-by-default categories through, except if they end
79 // in the suffix 'Debug' or 'Test'.
80 void InitializeDefault();
82 void Initialize(const std::string
& config_string
);
84 void SetCategoriesFromList(StringList
& categories
,
85 const base::ListValue
& list
);
86 void SetSyntheticDelaysFromList(StringList
& delays
,
87 const base::ListValue
& list
);
88 void AddCategoryToDict(base::DictionaryValue
& dict
,
90 const StringList
& categories
) const;
92 // Convert TraceConfig to the dict representation of the TraceConfig.
93 void ToDict(base::DictionaryValue
& dict
) const;
95 std::string
ToTraceOptionsString() const;
97 void WriteCategoryFilterString(const StringList
& values
,
100 void WriteCategoryFilterString(const StringList
& delays
,
101 std::string
* out
) const;
103 // Returns true if category is enable according to this trace config.
104 bool IsCategoryEnabled(const char* category_name
) const;
106 static bool IsEmptyOrContainsLeadingOrTrailingWhitespace(
107 const std::string
& str
);
109 bool HasIncludedPatterns() const;
111 TraceRecordMode record_mode_
;
112 bool enable_sampling_
: 1;
113 bool enable_systrace_
: 1;
114 bool enable_argument_filter_
: 1;
116 StringList included_categories_
;
117 StringList disabled_categories_
;
118 StringList excluded_categories_
;
119 StringList synthetic_delays_
;
122 } // namespace trace_event
125 #endif // BASE_TRACE_EVENT_TRACE_CONFIG_H_