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 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3030 BeginTrace(); | 3030 BeginTrace(); |
3031 thread.task_runner()->PostTask( | 3031 thread.task_runner()->PostTask( |
3032 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 3032 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
3033 task_complete_event.Wait(); | 3033 task_complete_event.Wait(); |
3034 task_complete_event.Reset(); | 3034 task_complete_event.Reset(); |
3035 EndTraceAndFlushInThreadWithMessageLoop(); | 3035 EndTraceAndFlushInThreadWithMessageLoop(); |
3036 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 3036 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
3037 } | 3037 } |
3038 | 3038 |
3039 std::string* g_log_buffer = NULL; | 3039 std::string* g_log_buffer = NULL; |
3040 bool MockLogMessageHandler(int, const char*, int, size_t, | 3040 class MockLogMessageListener : logging::LogMessageListener { |
3041 const std::string& str) { | 3041 public: |
3042 if (!g_log_buffer) | 3042 void OnMessage(int severity, const char* file, int line, |
3043 g_log_buffer = new std::string(); | 3043 size_t message_start, const std::string& str) override { |
3044 g_log_buffer->append(str); | 3044 if (!g_log_buffer) |
3045 return false; | 3045 g_log_buffer = new std::string(); |
3046 } | 3046 g_log_buffer->append(str); |
| 3047 } |
| 3048 }; |
3047 | 3049 |
3048 TEST_F(TraceEventTestFixture, EchoToConsole) { | 3050 TEST_F(TraceEventTestFixture, EchoToConsole) { |
3049 logging::LogMessageHandlerFunction old_log_message_handler = | 3051 MockLogMessageListener l; |
3050 logging::GetLogMessageHandler(); | |
3051 logging::SetLogMessageHandler(MockLogMessageHandler); | |
3052 | 3052 |
3053 TraceLog::GetInstance()->SetEnabled( | 3053 TraceLog::GetInstance()->SetEnabled( |
3054 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 3054 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
3055 TraceLog::RECORDING_MODE); | 3055 TraceLog::RECORDING_MODE); |
3056 TRACE_EVENT_BEGIN0("a", "begin_end"); | 3056 TRACE_EVENT_BEGIN0("a", "begin_end"); |
3057 { | 3057 { |
3058 TRACE_EVENT0("b", "duration"); | 3058 TRACE_EVENT0("b", "duration"); |
3059 TRACE_EVENT0("b1", "duration1"); | 3059 TRACE_EVENT0("b1", "duration1"); |
3060 } | 3060 } |
3061 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); | 3061 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); |
3062 TRACE_EVENT_END0("a", "begin_end"); | 3062 TRACE_EVENT_END0("a", "begin_end"); |
3063 | 3063 |
3064 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); | 3064 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); |
3065 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); | 3065 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); |
3066 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); | 3066 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); |
3067 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); | 3067 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); |
3068 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); | 3068 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); |
3069 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); | 3069 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); |
3070 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); | 3070 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); |
3071 | 3071 |
3072 EndTraceAndFlush(); | 3072 EndTraceAndFlush(); |
3073 delete g_log_buffer; | 3073 delete g_log_buffer; |
3074 logging::SetLogMessageHandler(old_log_message_handler); | |
3075 g_log_buffer = NULL; | 3074 g_log_buffer = NULL; |
3076 } | 3075 } |
3077 | 3076 |
3078 bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t, | 3077 class LogMessageListenerWithTraceEvent : logging::LogMessageListener { |
3079 const std::string&) { | 3078 public: |
3080 TRACE_EVENT0("log", "trace_event"); | 3079 void OnMessage(int severity, const char* file, int line, |
3081 return false; | 3080 size_t message_start, const std::string& str) override { |
3082 } | 3081 TRACE_EVENT0("log", "trace_event"); |
| 3082 } |
| 3083 }; |
3083 | 3084 |
3084 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { | 3085 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { |
3085 logging::LogMessageHandlerFunction old_log_message_handler = | 3086 LogMessageListenerWithTraceEvent l; |
3086 logging::GetLogMessageHandler(); | |
3087 logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent); | |
3088 | 3087 |
3089 TraceLog::GetInstance()->SetEnabled( | 3088 TraceLog::GetInstance()->SetEnabled( |
3090 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 3089 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
3091 TraceLog::RECORDING_MODE); | 3090 TraceLog::RECORDING_MODE); |
3092 { | 3091 { |
3093 // This should not cause deadlock or infinite recursion. | 3092 // This should not cause deadlock or infinite recursion. |
3094 TRACE_EVENT0("b", "duration"); | 3093 TRACE_EVENT0("b", "duration"); |
3095 } | 3094 } |
3096 | 3095 |
3097 EndTraceAndFlush(); | 3096 EndTraceAndFlush(); |
3098 logging::SetLogMessageHandler(old_log_message_handler); | |
3099 } | 3097 } |
3100 | 3098 |
3101 TEST_F(TraceEventTestFixture, TimeOffset) { | 3099 TEST_F(TraceEventTestFixture, TimeOffset) { |
3102 BeginTrace(); | 3100 BeginTrace(); |
3103 // Let TraceLog timer start from 0. | 3101 // Let TraceLog timer start from 0. |
3104 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); | 3102 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); |
3105 TraceLog::GetInstance()->SetTimeOffset(time_offset); | 3103 TraceLog::GetInstance()->SetTimeOffset(time_offset); |
3106 | 3104 |
3107 { | 3105 { |
3108 TRACE_EVENT0("all", "duration1"); | 3106 TRACE_EVENT0("all", "duration1"); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3175 | 3173 |
3176 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3174 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
3177 BeginSpecificTrace("-*"); | 3175 BeginSpecificTrace("-*"); |
3178 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3176 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
3179 EndTraceAndFlush(); | 3177 EndTraceAndFlush(); |
3180 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3178 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
3181 } | 3179 } |
3182 | 3180 |
3183 } // namespace trace_event | 3181 } // namespace trace_event |
3184 } // namespace base | 3182 } // namespace base |
OLD | NEW |