| 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 #include "base/trace_event/trace_event.h" | 5 #include "base/trace_event/trace_event.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 } | 997 } |
| 998 | 998 |
| 999 EXPECT_FALSE(results[-1][-1]); | 999 EXPECT_FALSE(results[-1][-1]); |
| 1000 for (int thread = 0; thread < num_threads; thread++) { | 1000 for (int thread = 0; thread < num_threads; thread++) { |
| 1001 for (int event = 0; event < num_events; event++) { | 1001 for (int event = 0; event < num_events; event++) { |
| 1002 EXPECT_TRUE(results[thread][event]); | 1002 EXPECT_TRUE(results[thread][event]); |
| 1003 } | 1003 } |
| 1004 } | 1004 } |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 void CheckTraceDefaultCategoryFilters(const TraceLog& trace_log) { |
| 1008 // Default enables all category filters except the disabled-by-default-* ones. |
| 1009 EXPECT_TRUE(*trace_log.GetCategoryGroupEnabled("foo")); |
| 1010 EXPECT_TRUE(*trace_log.GetCategoryGroupEnabled("bar")); |
| 1011 EXPECT_TRUE(*trace_log.GetCategoryGroupEnabled("foo,bar")); |
| 1012 EXPECT_TRUE(*trace_log.GetCategoryGroupEnabled( |
| 1013 "foo,disabled-by-default-foo")); |
| 1014 EXPECT_FALSE(*trace_log.GetCategoryGroupEnabled( |
| 1015 "disabled-by-default-foo,disabled-by-default-bar")); |
| 1016 } |
| 1017 |
| 1007 } // namespace | 1018 } // namespace |
| 1008 | 1019 |
| 1009 // Simple Test for emitting data and validating it was received. | 1020 // Simple Test for emitting data and validating it was received. |
| 1010 TEST_F(TraceEventTestFixture, DataCaptured) { | 1021 TEST_F(TraceEventTestFixture, DataCaptured) { |
| 1011 TraceLog::GetInstance()->SetEnabled(TraceConfig(kRecordAllCategoryFilter, ""), | 1022 TraceLog::GetInstance()->SetEnabled(TraceConfig(kRecordAllCategoryFilter, ""), |
| 1012 TraceLog::RECORDING_MODE); | 1023 TraceLog::RECORDING_MODE); |
| 1013 | 1024 |
| 1014 TraceWithAllMacroVariants(NULL); | 1025 TraceWithAllMacroVariants(NULL); |
| 1015 | 1026 |
| 1016 EndTraceAndFlush(); | 1027 EndTraceAndFlush(); |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1956 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar")); | 1967 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar")); |
| 1957 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); | 1968 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); |
| 1958 trace_log->SetEnabled(TraceConfig("foo2", ""), TraceLog::RECORDING_MODE); | 1969 trace_log->SetEnabled(TraceConfig("foo2", ""), TraceLog::RECORDING_MODE); |
| 1959 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo2")); | 1970 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo2")); |
| 1960 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); | 1971 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); |
| 1961 // The "" becomes the default catergory set when applied. | 1972 // The "" becomes the default catergory set when applied. |
| 1962 trace_log->SetEnabled(TraceConfig(), TraceLog::RECORDING_MODE); | 1973 trace_log->SetEnabled(TraceConfig(), TraceLog::RECORDING_MODE); |
| 1963 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo")); | 1974 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo")); |
| 1964 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); | 1975 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); |
| 1965 EXPECT_STREQ( | 1976 EXPECT_STREQ( |
| 1966 "-*Debug,-*Test", | 1977 "", |
| 1967 trace_log->GetCurrentTraceConfig().ToCategoryFilterString().c_str()); | 1978 trace_log->GetCurrentTraceConfig().ToCategoryFilterString().c_str()); |
| 1968 trace_log->SetDisabled(); | 1979 trace_log->SetDisabled(); |
| 1969 trace_log->SetDisabled(); | 1980 trace_log->SetDisabled(); |
| 1970 trace_log->SetDisabled(); | 1981 trace_log->SetDisabled(); |
| 1971 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo")); | 1982 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo")); |
| 1972 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); | 1983 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("baz")); |
| 1973 | 1984 |
| 1974 trace_log->SetEnabled(TraceConfig("-foo,-bar", ""), TraceLog::RECORDING_MODE); | 1985 trace_log->SetEnabled(TraceConfig("-foo,-bar", ""), TraceLog::RECORDING_MODE); |
| 1975 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo")); | 1986 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("foo")); |
| 1976 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); | 1987 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("baz")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1993 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-cc")); | 2004 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-cc")); |
| 1994 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-gpu")); | 2005 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-gpu")); |
| 1995 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar")); | 2006 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar")); |
| 1996 EXPECT_STREQ( | 2007 EXPECT_STREQ( |
| 1997 "disabled-by-default-cc,disabled-by-default-gpu", | 2008 "disabled-by-default-cc,disabled-by-default-gpu", |
| 1998 trace_log->GetCurrentTraceConfig().ToCategoryFilterString().c_str()); | 2009 trace_log->GetCurrentTraceConfig().ToCategoryFilterString().c_str()); |
| 1999 trace_log->SetDisabled(); | 2010 trace_log->SetDisabled(); |
| 2000 trace_log->SetDisabled(); | 2011 trace_log->SetDisabled(); |
| 2001 } | 2012 } |
| 2002 | 2013 |
| 2014 TEST_F(TraceEventTestFixture, TraceWithDefaultCategoryFilters) { |
| 2015 TraceLog* trace_log = TraceLog::GetInstance(); |
| 2016 |
| 2017 trace_log->SetEnabled(TraceConfig(), TraceLog::RECORDING_MODE); |
| 2018 CheckTraceDefaultCategoryFilters(*trace_log); |
| 2019 trace_log->SetDisabled(); |
| 2020 |
| 2021 trace_log->SetEnabled(TraceConfig("", ""), TraceLog::RECORDING_MODE); |
| 2022 CheckTraceDefaultCategoryFilters(*trace_log); |
| 2023 trace_log->SetDisabled(); |
| 2024 |
| 2025 trace_log->SetEnabled(TraceConfig("*", ""), TraceLog::RECORDING_MODE); |
| 2026 CheckTraceDefaultCategoryFilters(*trace_log); |
| 2027 trace_log->SetDisabled(); |
| 2028 |
| 2029 trace_log->SetEnabled(TraceConfig(""), TraceLog::RECORDING_MODE); |
| 2030 CheckTraceDefaultCategoryFilters(*trace_log); |
| 2031 trace_log->SetDisabled(); |
| 2032 } |
| 2033 |
| 2034 TEST_F(TraceEventTestFixture, TraceWithDisabledByDefaultCategoryFilters) { |
| 2035 TraceLog* trace_log = TraceLog::GetInstance(); |
| 2036 |
| 2037 trace_log->SetEnabled(TraceConfig("foo,disabled-by-default-foo", ""), |
| 2038 TraceLog::RECORDING_MODE); |
| 2039 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo")); |
| 2040 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-foo")); |
| 2041 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("bar")); |
| 2042 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-bar")); |
| 2043 trace_log->SetDisabled(); |
| 2044 |
| 2045 // Enabling only the disabled-by-default-* category means the default ones |
| 2046 // are also enabled. |
| 2047 trace_log->SetEnabled(TraceConfig("disabled-by-default-foo", ""), |
| 2048 TraceLog::RECORDING_MODE); |
| 2049 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-foo")); |
| 2050 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("foo")); |
| 2051 EXPECT_TRUE(*trace_log->GetCategoryGroupEnabled("bar")); |
| 2052 EXPECT_FALSE(*trace_log->GetCategoryGroupEnabled("disabled-by-default-bar")); |
| 2053 trace_log->SetDisabled(); |
| 2054 } |
| 2055 |
| 2003 TEST_F(TraceEventTestFixture, TraceSampling) { | 2056 TEST_F(TraceEventTestFixture, TraceSampling) { |
| 2004 TraceLog::GetInstance()->SetEnabled( | 2057 TraceLog::GetInstance()->SetEnabled( |
| 2005 TraceConfig(kRecordAllCategoryFilter, "record-until-full,enable-sampling"), | 2058 TraceConfig(kRecordAllCategoryFilter, "record-until-full,enable-sampling"), |
| 2006 TraceLog::RECORDING_MODE); | 2059 TraceLog::RECORDING_MODE); |
| 2007 | 2060 |
| 2008 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "cc", "Stuff"); | 2061 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "cc", "Stuff"); |
| 2009 TraceLog::GetInstance()->WaitSamplingEventForTesting(); | 2062 TraceLog::GetInstance()->WaitSamplingEventForTesting(); |
| 2010 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "cc", "Things"); | 2063 TRACE_EVENT_SET_SAMPLING_STATE_FOR_BUCKET(1, "cc", "Things"); |
| 2011 TraceLog::GetInstance()->WaitSamplingEventForTesting(); | 2064 TraceLog::GetInstance()->WaitSamplingEventForTesting(); |
| 2012 | 2065 |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3122 | 3175 |
| 3123 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3176 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
| 3124 BeginSpecificTrace("-*"); | 3177 BeginSpecificTrace("-*"); |
| 3125 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3178 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
| 3126 EndTraceAndFlush(); | 3179 EndTraceAndFlush(); |
| 3127 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3180 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
| 3128 } | 3181 } |
| 3129 | 3182 |
| 3130 } // namespace trace_event | 3183 } // namespace trace_event |
| 3131 } // namespace base | 3184 } // namespace base |
| OLD | NEW |