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

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: rebase 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 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 2654
2655 TEST_F(TraceEventTestFixture, TraceRecordAsMuchAsPossibleMode) { 2655 TEST_F(TraceEventTestFixture, TraceRecordAsMuchAsPossibleMode) {
2656 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"), 2656 TraceLog::GetInstance()->SetEnabled(CategoryFilter("*"),
2657 TraceLog::RECORDING_MODE, 2657 TraceLog::RECORDING_MODE,
2658 TraceOptions(RECORD_AS_MUCH_AS_POSSIBLE)); 2658 TraceOptions(RECORD_AS_MUCH_AS_POSSIBLE));
2659 TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer(); 2659 TraceBuffer* buffer = TraceLog::GetInstance()->trace_buffer();
2660 EXPECT_EQ(512000000UL, buffer->Capacity()); 2660 EXPECT_EQ(512000000UL, buffer->Capacity());
2661 TraceLog::GetInstance()->SetDisabled(); 2661 TraceLog::GetInstance()->SetDisabled();
2662 } 2662 }
2663 2663
2664 // Test the category filter.
2665 TEST_F(TraceEventTestFixture, CategoryFilter) {
2666 // Using the default filter.
2667 CategoryFilter default_cf = CategoryFilter(
2668 CategoryFilter::kDefaultCategoryFilterString);
2669 std::string category_filter_str = default_cf.ToString();
2670 EXPECT_STREQ("-*Debug,-*Test", category_filter_str.c_str());
2671 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("not-excluded-category"));
2672 EXPECT_FALSE(
2673 default_cf.IsCategoryGroupEnabled("disabled-by-default-category"));
2674 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
2675 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
2676 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
2677
2678 // Make sure that upon an empty string, we fall back to the default filter.
2679 default_cf = CategoryFilter();
2680 category_filter_str = default_cf.ToString();
2681 EXPECT_STREQ("-*Debug,-*Test", category_filter_str.c_str());
2682 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("not-excluded-category"));
2683 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
2684 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
2685 EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
2686
2687 // Using an arbitrary non-empty filter.
2688 CategoryFilter cf("included,-excluded,inc_pattern*,-exc_pattern*");
2689 category_filter_str = cf.ToString();
2690 EXPECT_STREQ("included,inc_pattern*,-excluded,-exc_pattern*",
2691 category_filter_str.c_str());
2692 EXPECT_TRUE(cf.IsCategoryGroupEnabled("included"));
2693 EXPECT_TRUE(cf.IsCategoryGroupEnabled("inc_pattern_category"));
2694 EXPECT_FALSE(cf.IsCategoryGroupEnabled("exc_pattern_category"));
2695 EXPECT_FALSE(cf.IsCategoryGroupEnabled("excluded"));
2696 EXPECT_FALSE(cf.IsCategoryGroupEnabled("not-excluded-nor-included"));
2697 EXPECT_FALSE(cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
2698 EXPECT_FALSE(cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
2699 EXPECT_FALSE(cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
2700
2701 cf.Merge(default_cf);
2702 category_filter_str = cf.ToString();
2703 EXPECT_STREQ("-excluded,-exc_pattern*,-*Debug,-*Test",
2704 category_filter_str.c_str());
2705 cf.Clear();
2706
2707 CategoryFilter reconstructed_cf(category_filter_str);
2708 category_filter_str = reconstructed_cf.ToString();
2709 EXPECT_STREQ("-excluded,-exc_pattern*,-*Debug,-*Test",
2710 category_filter_str.c_str());
2711
2712 // One included category.
2713 CategoryFilter one_inc_cf("only_inc_cat");
2714 category_filter_str = one_inc_cf.ToString();
2715 EXPECT_STREQ("only_inc_cat", category_filter_str.c_str());
2716
2717 // One excluded category.
2718 CategoryFilter one_exc_cf("-only_exc_cat");
2719 category_filter_str = one_exc_cf.ToString();
2720 EXPECT_STREQ("-only_exc_cat", category_filter_str.c_str());
2721
2722 // Enabling a disabled- category does not require all categories to be traced
2723 // to be included.
2724 CategoryFilter disabled_cat("disabled-by-default-cc,-excluded");
2725 EXPECT_STREQ("disabled-by-default-cc,-excluded",
2726 disabled_cat.ToString().c_str());
2727 EXPECT_TRUE(disabled_cat.IsCategoryGroupEnabled("disabled-by-default-cc"));
2728 EXPECT_TRUE(disabled_cat.IsCategoryGroupEnabled("some_other_group"));
2729 EXPECT_FALSE(disabled_cat.IsCategoryGroupEnabled("excluded"));
2730
2731 // Enabled a disabled- category and also including makes all categories to
2732 // be traced require including.
2733 CategoryFilter disabled_inc_cat("disabled-by-default-cc,included");
2734 EXPECT_STREQ("included,disabled-by-default-cc",
2735 disabled_inc_cat.ToString().c_str());
2736 EXPECT_TRUE(
2737 disabled_inc_cat.IsCategoryGroupEnabled("disabled-by-default-cc"));
2738 EXPECT_TRUE(disabled_inc_cat.IsCategoryGroupEnabled("included"));
2739 EXPECT_FALSE(disabled_inc_cat.IsCategoryGroupEnabled("other_included"));
2740
2741 // Test that IsEmptyOrContainsLeadingOrTrailingWhitespace actually catches
2742 // categories that are explicitly forbiden.
2743 // This method is called in a DCHECK to assert that we don't have these types
2744 // of strings as categories.
2745 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2746 " bad_category "));
2747 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2748 " bad_category"));
2749 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2750 "bad_category "));
2751 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2752 " bad_category"));
2753 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2754 "bad_category "));
2755 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2756 " bad_category "));
2757 EXPECT_TRUE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2758 ""));
2759 EXPECT_FALSE(CategoryFilter::IsEmptyOrContainsLeadingOrTrailingWhitespace(
2760 "good_category"));
2761 }
2762
2763 void BlockUntilStopped(WaitableEvent* task_start_event, 2664 void BlockUntilStopped(WaitableEvent* task_start_event,
2764 WaitableEvent* task_stop_event) { 2665 WaitableEvent* task_stop_event) {
2765 task_start_event->Signal(); 2666 task_start_event->Signal();
2766 task_stop_event->Wait(); 2667 task_stop_event->Wait();
2767 } 2668 }
2768 2669
2769 TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopBeforeTracing) { 2670 TEST_F(TraceEventTestFixture, SetCurrentThreadBlocksMessageLoopBeforeTracing) {
2770 BeginTrace(); 2671 BeginTrace();
2771 2672
2772 Thread thread("1"); 2673 Thread thread("1");
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
3041 filter1.Merge(filter2); 2942 filter1.Merge(filter2);
3042 EXPECT_EQ(2u, filter1.GetSyntheticDelayValues().size()); 2943 EXPECT_EQ(2u, filter1.GetSyntheticDelayValues().size());
3043 } 2944 }
3044 2945
3045 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) { 2946 TEST_F(TraceEventTestFixture, SyntheticDelayConfigurationToString) {
3046 const char config[] = "DELAY(test.Delay;16;oneshot)"; 2947 const char config[] = "DELAY(test.Delay;16;oneshot)";
3047 CategoryFilter filter(config); 2948 CategoryFilter filter(config);
3048 EXPECT_EQ(config, filter.ToString()); 2949 EXPECT_EQ(config, filter.ToString());
3049 } 2950 }
3050 2951
3051 TEST(TraceOptionsTest, TraceOptionsFromString) {
3052 TraceOptions options;
3053 EXPECT_TRUE(options.SetFromString("record-until-full"));
3054 EXPECT_EQ(RECORD_UNTIL_FULL, options.record_mode);
3055 EXPECT_FALSE(options.enable_sampling);
3056 EXPECT_FALSE(options.enable_systrace);
3057
3058 EXPECT_TRUE(options.SetFromString("record-continuously"));
3059 EXPECT_EQ(RECORD_CONTINUOUSLY, options.record_mode);
3060 EXPECT_FALSE(options.enable_sampling);
3061 EXPECT_FALSE(options.enable_systrace);
3062
3063 EXPECT_TRUE(options.SetFromString("trace-to-console"));
3064 EXPECT_EQ(ECHO_TO_CONSOLE, options.record_mode);
3065 EXPECT_FALSE(options.enable_sampling);
3066 EXPECT_FALSE(options.enable_systrace);
3067
3068 EXPECT_TRUE(options.SetFromString("record-as-much-as-possible"));
3069 EXPECT_EQ(RECORD_AS_MUCH_AS_POSSIBLE, options.record_mode);
3070 EXPECT_FALSE(options.enable_sampling);
3071 EXPECT_FALSE(options.enable_systrace);
3072
3073 EXPECT_TRUE(options.SetFromString("record-until-full, enable-sampling"));
3074 EXPECT_EQ(RECORD_UNTIL_FULL, options.record_mode);
3075 EXPECT_TRUE(options.enable_sampling);
3076 EXPECT_FALSE(options.enable_systrace);
3077
3078 EXPECT_TRUE(options.SetFromString("enable-systrace,record-continuously"));
3079 EXPECT_EQ(RECORD_CONTINUOUSLY, options.record_mode);
3080 EXPECT_FALSE(options.enable_sampling);
3081 EXPECT_TRUE(options.enable_systrace);
3082
3083 EXPECT_TRUE(options.SetFromString(
3084 "enable-systrace, trace-to-console,enable-sampling"));
3085 EXPECT_EQ(ECHO_TO_CONSOLE, options.record_mode);
3086 EXPECT_TRUE(options.enable_sampling);
3087 EXPECT_TRUE(options.enable_systrace);
3088
3089 EXPECT_TRUE(options.SetFromString(
3090 "record-continuously,record-until-full,trace-to-console"));
3091 EXPECT_EQ(ECHO_TO_CONSOLE, options.record_mode);
3092 EXPECT_FALSE(options.enable_systrace);
3093 EXPECT_FALSE(options.enable_sampling);
3094
3095 EXPECT_TRUE(options.SetFromString(""));
3096 EXPECT_EQ(RECORD_UNTIL_FULL, options.record_mode);
3097 EXPECT_FALSE(options.enable_systrace);
3098 EXPECT_FALSE(options.enable_sampling);
3099
3100 EXPECT_FALSE(options.SetFromString("foo-bar-baz"));
3101 }
3102
3103 TEST(TraceOptionsTest, TraceOptionsToString) {
3104 // Test that we can intialize TraceOptions from a string got from
3105 // TraceOptions.ToString() method to get a same TraceOptions.
3106 TraceRecordMode modes[] = {RECORD_UNTIL_FULL,
3107 RECORD_CONTINUOUSLY,
3108 ECHO_TO_CONSOLE,
3109 RECORD_AS_MUCH_AS_POSSIBLE};
3110 bool enable_sampling_options[] = {true, false};
3111 bool enable_systrace_options[] = {true, false};
3112
3113 for (int i = 0; i < 4; ++i) {
3114 for (int j = 0; j < 2; ++j) {
3115 for (int k = 0; k < 2; ++k) {
3116 TraceOptions original_option = TraceOptions(modes[i]);
3117 original_option.enable_sampling = enable_sampling_options[j];
3118 original_option.enable_systrace = enable_systrace_options[k];
3119 TraceOptions new_options;
3120 EXPECT_TRUE(new_options.SetFromString(original_option.ToString()));
3121 EXPECT_EQ(original_option.record_mode, new_options.record_mode);
3122 EXPECT_EQ(original_option.enable_sampling, new_options.enable_sampling);
3123 EXPECT_EQ(original_option.enable_systrace, new_options.enable_systrace);
3124 }
3125 }
3126 }
3127 }
3128
3129 } // namespace trace_event 2952 } // namespace trace_event
3130 } // namespace base 2953 } // namespace base
OLDNEW
« base/trace_event/trace_config.h ('K') | « base/trace_event/trace_event_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698