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 3063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3074 BeginTrace(); | 3074 BeginTrace(); |
3075 thread.task_runner()->PostTask( | 3075 thread.task_runner()->PostTask( |
3076 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 3076 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
3077 task_complete_event.Wait(); | 3077 task_complete_event.Wait(); |
3078 task_complete_event.Reset(); | 3078 task_complete_event.Reset(); |
3079 EndTraceAndFlushInThreadWithMessageLoop(); | 3079 EndTraceAndFlushInThreadWithMessageLoop(); |
3080 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 3080 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
3081 } | 3081 } |
3082 | 3082 |
3083 std::string* g_log_buffer = NULL; | 3083 std::string* g_log_buffer = NULL; |
3084 bool MockLogMessageHandler(int, const char*, int, size_t, | 3084 class MockLogMessageListener : logging::LogMessageListener { |
3085 const std::string& str) { | 3085 public: |
3086 if (!g_log_buffer) | 3086 void OnMessage(int severity, const char* file, int line, |
3087 g_log_buffer = new std::string(); | 3087 size_t message_start, const std::string& str) override { |
3088 g_log_buffer->append(str); | 3088 if (!g_log_buffer) |
3089 return false; | 3089 g_log_buffer = new std::string(); |
3090 } | 3090 g_log_buffer->append(str); |
| 3091 } |
| 3092 }; |
3091 | 3093 |
3092 TEST_F(TraceEventTestFixture, EchoToConsole) { | 3094 TEST_F(TraceEventTestFixture, EchoToConsole) { |
3093 logging::LogMessageHandlerFunction old_log_message_handler = | 3095 MockLogMessageListener l; |
3094 logging::GetLogMessageHandler(); | |
3095 logging::SetLogMessageHandler(MockLogMessageHandler); | |
3096 | 3096 |
3097 TraceLog::GetInstance()->SetEnabled( | 3097 TraceLog::GetInstance()->SetEnabled( |
3098 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 3098 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
3099 TraceLog::RECORDING_MODE); | 3099 TraceLog::RECORDING_MODE); |
3100 TRACE_EVENT_BEGIN0("a", "begin_end"); | 3100 TRACE_EVENT_BEGIN0("a", "begin_end"); |
3101 { | 3101 { |
3102 TRACE_EVENT0("b", "duration"); | 3102 TRACE_EVENT0("b", "duration"); |
3103 TRACE_EVENT0("b1", "duration1"); | 3103 TRACE_EVENT0("b1", "duration1"); |
3104 } | 3104 } |
3105 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); | 3105 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); |
3106 TRACE_EVENT_END0("a", "begin_end"); | 3106 TRACE_EVENT_END0("a", "begin_end"); |
3107 | 3107 |
3108 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); | 3108 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); |
3109 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); | 3109 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); |
3110 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); | 3110 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); |
3111 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); | 3111 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); |
3112 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); | 3112 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); |
3113 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); | 3113 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); |
3114 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); | 3114 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); |
3115 | 3115 |
3116 EndTraceAndFlush(); | 3116 EndTraceAndFlush(); |
3117 delete g_log_buffer; | 3117 delete g_log_buffer; |
3118 logging::SetLogMessageHandler(old_log_message_handler); | |
3119 g_log_buffer = NULL; | 3118 g_log_buffer = NULL; |
3120 } | 3119 } |
3121 | 3120 |
3122 bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t, | 3121 class LogMessageListenerWithTraceEvent : logging::LogMessageListener { |
3123 const std::string&) { | 3122 public: |
3124 TRACE_EVENT0("log", "trace_event"); | 3123 void OnMessage(int severity, const char* file, int line, |
3125 return false; | 3124 size_t message_start, const std::string& str) override { |
3126 } | 3125 TRACE_EVENT0("log", "trace_event"); |
| 3126 } |
| 3127 }; |
3127 | 3128 |
3128 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { | 3129 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { |
3129 logging::LogMessageHandlerFunction old_log_message_handler = | 3130 LogMessageListenerWithTraceEvent l; |
3130 logging::GetLogMessageHandler(); | |
3131 logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent); | |
3132 | 3131 |
3133 TraceLog::GetInstance()->SetEnabled( | 3132 TraceLog::GetInstance()->SetEnabled( |
3134 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 3133 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
3135 TraceLog::RECORDING_MODE); | 3134 TraceLog::RECORDING_MODE); |
3136 { | 3135 { |
3137 // This should not cause deadlock or infinite recursion. | 3136 // This should not cause deadlock or infinite recursion. |
3138 TRACE_EVENT0("b", "duration"); | 3137 TRACE_EVENT0("b", "duration"); |
3139 } | 3138 } |
3140 | 3139 |
3141 EndTraceAndFlush(); | 3140 EndTraceAndFlush(); |
3142 logging::SetLogMessageHandler(old_log_message_handler); | |
3143 } | 3141 } |
3144 | 3142 |
3145 TEST_F(TraceEventTestFixture, TimeOffset) { | 3143 TEST_F(TraceEventTestFixture, TimeOffset) { |
3146 BeginTrace(); | 3144 BeginTrace(); |
3147 // Let TraceLog timer start from 0. | 3145 // Let TraceLog timer start from 0. |
3148 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); | 3146 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); |
3149 TraceLog::GetInstance()->SetTimeOffset(time_offset); | 3147 TraceLog::GetInstance()->SetTimeOffset(time_offset); |
3150 | 3148 |
3151 { | 3149 { |
3152 TRACE_EVENT0("all", "duration1"); | 3150 TRACE_EVENT0("all", "duration1"); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3219 | 3217 |
3220 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3218 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
3221 BeginSpecificTrace("-*"); | 3219 BeginSpecificTrace("-*"); |
3222 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3220 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
3223 EndTraceAndFlush(); | 3221 EndTraceAndFlush(); |
3224 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3222 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
3225 } | 3223 } |
3226 | 3224 |
3227 } // namespace trace_event | 3225 } // namespace trace_event |
3228 } // namespace base | 3226 } // namespace base |
OLD | NEW |