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

Side by Side Diff: base/trace_event/trace_event_unittest.cc

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 #include <math.h> 5 #include <math.h>
6 #include <cstdlib> 6 #include <cstdlib>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 TraceOptions new_options; 3073 TraceOptions new_options;
3074 EXPECT_TRUE(new_options.SetFromString(original_option.ToString())); 3074 EXPECT_TRUE(new_options.SetFromString(original_option.ToString()));
3075 EXPECT_EQ(original_option.record_mode, new_options.record_mode); 3075 EXPECT_EQ(original_option.record_mode, new_options.record_mode);
3076 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling); 3076 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling);
3077 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace); 3077 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace);
3078 } 3078 }
3079 } 3079 }
3080 } 3080 }
3081 } 3081 }
3082 3082
3083 TEST(TraceConfigTest, TraceConfigFromAndToString) {
3084 // From and to trace options strings
3085 TraceConfig config = TraceConfig("", "record-until-full");
3086 EXPECT_EQ(RECORD_UNTIL_FULL, config.record_mode_);
3087 EXPECT_FALSE(config.enable_sampling_);
3088 EXPECT_FALSE(config.enable_systrace_);
3089 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str());
3090
3091 config = TraceConfig("", "record-continuously");
3092 EXPECT_EQ(RECORD_CONTINUOUSLY, config.record_mode_);
3093 EXPECT_FALSE(config.enable_sampling_);
3094 EXPECT_FALSE(config.enable_systrace_);
3095 EXPECT_STREQ("record-continuously", config.ToTraceOptionsString().c_str());
3096
3097 config = TraceConfig("", "trace-to-console");
3098 EXPECT_EQ(ECHO_TO_CONSOLE, config.record_mode_);
3099 EXPECT_FALSE(config.enable_sampling_);
3100 EXPECT_FALSE(config.enable_systrace_);
3101 EXPECT_STREQ("trace-to-console", config.ToTraceOptionsString().c_str());
3102
3103 config = TraceConfig("", "record-as-much-as-possible");
3104 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, config.record_mode_);
3105 EXPECT_FALSE(config.enable_sampling_);
3106 EXPECT_FALSE(config.enable_systrace_);
3107 EXPECT_STREQ("record-as-much-as-possible",
3108 config.ToTraceOptionsString().c_str());
3109
3110 config = TraceConfig("", "record-until-full, enable-sampling");
3111 EXPECT_EQ(RECORD_UNTIL_FULL, config.record_mode_);
3112 EXPECT_TRUE(config.enable_sampling_);
3113 EXPECT_FALSE(config.enable_systrace_);
3114 EXPECT_STREQ("record-until-full,enable-sampling",
3115 config.ToTraceOptionsString().c_str());
3116
3117 config = TraceConfig("", "enable-systrace, record-continuously");
3118 EXPECT_EQ(RECORD_CONTINUOUSLY, config.record_mode_);
3119 EXPECT_FALSE(config.enable_sampling_);
3120 EXPECT_TRUE(config.enable_systrace_);
3121 EXPECT_STREQ("record-continuously,enable-systrace",
3122 config.ToTraceOptionsString().c_str());
3123
3124 config = TraceConfig("",
3125 "enable-systrace, trace-to-console, enable-sampling");
3126 EXPECT_EQ(ECHO_TO_CONSOLE, config.record_mode_);
3127 EXPECT_TRUE(config.enable_sampling_);
3128 EXPECT_TRUE(config.enable_systrace_);
3129 EXPECT_STREQ("trace-to-console,enable-sampling,enable-systrace",
3130 config.ToTraceOptionsString().c_str());
3131
3132 config = TraceConfig(
3133 "", "record-continuously, record-until-full, trace-to-console");
3134 EXPECT_EQ(ECHO_TO_CONSOLE, config.record_mode_);
3135 EXPECT_FALSE(config.enable_systrace_);
3136 EXPECT_FALSE(config.enable_sampling_);
3137 EXPECT_STREQ("trace-to-console", config.ToTraceOptionsString().c_str());
3138
3139 config = TraceConfig("", "foo-bar-baz");
nednguyen 2015/05/11 17:59:28 I would move these invalid trace option cases to a
Zhen Wang 2015/05/13 00:01:11 Added TraceConfigFromInvalidLegacyString. There i
3140 EXPECT_EQ(RECORD_UNTIL_FULL, config.record_mode_);
3141 EXPECT_FALSE(config.enable_systrace_);
3142 EXPECT_FALSE(config.enable_sampling_);
3143 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str());
3144
3145 // From and to category filter strings
3146 config = TraceConfig("-*Debug,-*Test", "");
3147 EXPECT_STREQ("-*Debug,-*Test", config.ToCategoryFilterString().c_str());
3148
3149 config = TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*", "");
3150 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
3151 config.ToCategoryFilterString().c_str());
3152
3153 config = TraceConfig("only_inc_cat", "");
3154 EXPECT_STREQ("only_inc_cat", config.ToCategoryFilterString().c_str());
3155
3156 config = TraceConfig("-only_exc_cat", "");
3157 EXPECT_STREQ("-only_exc_cat", config.ToCategoryFilterString().c_str());
3158
3159 config = TraceConfig("disabled-by-default-cc,-excluded", "");
3160 EXPECT_STREQ("disabled-by-default-cc,-excluded",
3161 config.ToCategoryFilterString().c_str());
3162
3163 config = TraceConfig("disabled-by-default-cc,included", "");
3164 EXPECT_STREQ("included,disabled-by-default-cc",
3165 config.ToCategoryFilterString().c_str());
3166
3167 config = TraceConfig("DELAY(test.Delay1;16),included", "");
3168 EXPECT_STREQ("included,DELAY(test.Delay1;16)",
3169 config.ToCategoryFilterString().c_str());
3170
3171 // From and to both trace options and category filter strings
3172 config = TraceConfig("", "");
3173 EXPECT_EQ(RECORD_UNTIL_FULL, config.record_mode_);
3174 EXPECT_FALSE(config.enable_systrace_);
3175 EXPECT_FALSE(config.enable_sampling_);
3176 EXPECT_STREQ("-*Debug,-*Test", config.ToCategoryFilterString().c_str());
3177 EXPECT_STREQ("record-until-full", config.ToTraceOptionsString().c_str());
3178
3179 config = TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*",
3180 "enable-systrace, trace-to-console, enable-sampling");
3181 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
3182 config.ToCategoryFilterString().c_str());
3183 EXPECT_STREQ("trace-to-console,enable-sampling,enable-systrace",
3184 config.ToTraceOptionsString().c_str());
3185 }
3186
3187 TEST(TraceConfigTest, TraceConfigFromAndToLegacyFormat) {
3188 std::string filter_string = "included,-excluded,inc_pattern*,-exc_pattern*";
3189 std::string options_string =
3190 "enable-systrace, trace-to-console, enable-sampling";
3191 TraceConfig tc = TraceConfig(filter_string, options_string);
3192 CategoryFilter cf;
3193 TraceOptions to;
3194 tc.ToCategoryFilter(cf);
3195 tc.ToTraceOptions(to);
3196
3197 CategoryFilter cf2 = CategoryFilter(filter_string);
3198 TraceOptions to2;
3199 to2.SetFromString(options_string);
3200 TraceConfig tc2 = TraceConfig(cf2, to2);
3201
3202 EXPECT_STREQ(cf.ToString().c_str(), cf2.ToString().c_str());
3203 EXPECT_STREQ(to.ToString().c_str(), to2.ToString().c_str());
3204 EXPECT_STREQ(tc.ToString().c_str(), tc2.ToString().c_str());
3205 }
3206
3207 TEST(TraceConfigTest, TraceConfig) {
nednguyen 2015/05/11 17:59:28 This test should also split into multiple ones, ea
Zhen Wang 2015/05/13 00:01:11 Done.
3208 // Using the default trace config.
3209 TraceConfig tc = TraceConfig(TraceConfig::kDefaultTraceConfigString);
3210
3211 EXPECT_STREQ(TraceConfig::kDefaultTraceConfigString, tc.ToString().c_str());
3212 EXPECT_TRUE(tc.record_mode_ == RECORD_UNTIL_FULL);
3213 EXPECT_FALSE(tc.enable_sampling_);
3214 EXPECT_FALSE(tc.enable_systrace_);
3215 EXPECT_STREQ("-*Debug,-*Test", tc.ToCategoryFilterString().c_str());
3216 EXPECT_TRUE(tc.IsCategoryGroupEnabled("not-excluded-category"));
3217 EXPECT_FALSE(tc.IsCategoryGroupEnabled("disabled-by-default-category"));
3218 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug"));
3219 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1"));
3220 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,Category2"));
3221
3222 // Make sure that upon an empty string, we fall back to the default config.
3223 tc = TraceConfig();
3224 EXPECT_STREQ(TraceConfig::kDefaultTraceConfigString, tc.ToString().c_str());
3225 EXPECT_TRUE(tc.record_mode_ == RECORD_UNTIL_FULL);
3226 EXPECT_FALSE(tc.enable_sampling_);
3227 EXPECT_FALSE(tc.enable_systrace_);
3228 EXPECT_STREQ("-*Debug,-*Test", tc.ToCategoryFilterString().c_str());
3229 EXPECT_TRUE(tc.IsCategoryGroupEnabled("not-excluded-category"));
3230 EXPECT_TRUE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug"));
3231 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1"));
3232 EXPECT_TRUE(tc.IsCategoryGroupEnabled("CategoryTest,Category2"));
3233
3234 // Using an arbitrary non-empty config string.
3235 char config_string[] =
3236 "{"
3237 "\"enable_sampling\":true,"
3238 "\"enable_systrace\":true,"
3239 "\"excluded_categories\":[\"excluded\",\"exc_pattern*\"],"
3240 "\"included_categories\":[\"included\",\"inc_pattern*\"],"
3241 "\"record_mode\":\"record-continuously\","
3242 "\"synthetic_delays\":[\"test.Delay1;16\"]"
3243 "}";
3244 tc = TraceConfig(config_string);
3245 EXPECT_STREQ(config_string, tc.ToString().c_str());
3246 EXPECT_TRUE(tc.record_mode_ == RECORD_CONTINUOUSLY);
3247 EXPECT_TRUE(tc.enable_sampling_);
3248 EXPECT_TRUE(tc.enable_systrace_);
3249 EXPECT_STREQ(
3250 "included,inc_pattern*,-excluded,-exc_pattern*,DELAY(test.Delay1;16)",
3251 tc.ToCategoryFilterString().c_str());
3252 EXPECT_TRUE(tc.IsCategoryGroupEnabled("included"));
3253 EXPECT_TRUE(tc.IsCategoryGroupEnabled("inc_pattern_category"));
3254 EXPECT_FALSE(tc.IsCategoryGroupEnabled("exc_pattern_category"));
3255 EXPECT_FALSE(tc.IsCategoryGroupEnabled("excluded"));
3256 EXPECT_FALSE(tc.IsCategoryGroupEnabled("not-excluded-nor-included"));
3257 EXPECT_FALSE(tc.IsCategoryGroupEnabled("Category1,CategoryDebug"));
3258 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryDebug,Category1"));
3259 EXPECT_FALSE(tc.IsCategoryGroupEnabled("CategoryTest,Category2"));
nednguyen 2015/05/11 17:59:28 what about synthetic delay values?
Zhen Wang 2015/05/13 00:01:11 Synthetic delay values are not considered in IsCat
nednguyen 2015/05/13 18:16:31 I mean we should also add test for synthetic delay
Zhen Wang 2015/05/13 20:59:16 This test includes "\"synthetic_delays\":[\"test.D
3260
3261 // Clear
3262 tc.Clear();
3263 EXPECT_STREQ(tc.ToString().c_str(),
3264 "{"
3265 "\"enable_sampling\":false,"
3266 "\"enable_systrace\":false,"
3267 "\"record_mode\":\"record-until-full\""
3268 "}");
3269
3270 // Merge
3271 tc = TraceConfig();
3272 TraceConfig tc2 = TraceConfig("included,-excluded,inc_pattern*,-exc_pattern*",
3273 "");
3274 tc.Merge(tc2);
3275 EXPECT_STREQ("{"
3276 "\"enable_sampling\":false,"
3277 "\"enable_systrace\":false,"
3278 "\"excluded_categories\":["
3279 "\"*Debug\",\"*Test\",\"excluded\",\"exc_pattern*\""
3280 "],"
3281 "\"record_mode\":\"record-until-full\""
3282 "}",
3283 tc.ToString().c_str());
3284
3285 // Enabling a disabled- category does not require all categories to be traced
3286 // to be included.
3287 tc = TraceConfig("disabled-by-default-cc,-excluded", "");
3288 EXPECT_STREQ("disabled-by-default-cc,-excluded",
3289 tc.ToCategoryFilterString().c_str());
3290 EXPECT_TRUE(tc.IsCategoryGroupEnabled("disabled-by-default-cc"));
3291 EXPECT_TRUE(tc.IsCategoryGroupEnabled("some_other_group"));
3292 EXPECT_FALSE(tc.IsCategoryGroupEnabled("excluded"));
3293
3294 // Enabled a disabled- category and also including makes all categories to
3295 // be traced require including.
3296 tc = TraceConfig("disabled-by-default-cc,included", "");
3297 EXPECT_STREQ("included,disabled-by-default-cc",
3298 tc.ToCategoryFilterString().c_str());
3299 EXPECT_TRUE(tc.IsCategoryGroupEnabled("disabled-by-default-cc"));
3300 EXPECT_TRUE(tc.IsCategoryGroupEnabled("included"));
3301 EXPECT_FALSE(tc.IsCategoryGroupEnabled("other_included"));
3302
3303 // Test that IsEmptyOrContainsLeadingOrTrailingWhitespace actually catches
3304 // categories that are explicitly forbidden.
3305 // This method is called in a DCHECK to assert that we don't have these types
3306 // of strings as categories.
3307 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3308 " bad_category "));
3309 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3310 " bad_category"));
3311 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3312 "bad_category "));
3313 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3314 " bad_category"));
3315 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3316 "bad_category "));
3317 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3318 " bad_category "));
3319 EXPECT_TRUE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3320 ""));
3321 EXPECT_FALSE(TraceConfig::IsEmptyOrContainsLeadingOrTrailingWhitespace(
3322 "good_category"));
3323 }
3324
3083 } // namespace trace_event 3325 } // namespace trace_event
3084 } // namespace base 3326 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698