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 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2817 BeginTrace(); | 2817 BeginTrace(); |
2818 thread.task_runner()->PostTask( | 2818 thread.task_runner()->PostTask( |
2819 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 2819 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
2820 task_complete_event.Wait(); | 2820 task_complete_event.Wait(); |
2821 task_complete_event.Reset(); | 2821 task_complete_event.Reset(); |
2822 EndTraceAndFlushInThreadWithMessageLoop(); | 2822 EndTraceAndFlushInThreadWithMessageLoop(); |
2823 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 2823 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
2824 } | 2824 } |
2825 | 2825 |
2826 std::string* g_log_buffer = NULL; | 2826 std::string* g_log_buffer = NULL; |
2827 bool MockLogMessageHandler(int, const char*, int, size_t, | 2827 class MockLogMessageListener : logging::LogMessageListener { |
2828 const std::string& str) { | 2828 public: |
2829 if (!g_log_buffer) | 2829 void OnMessage(int severity, |
2830 g_log_buffer = new std::string(); | 2830 const char* file, |
2831 g_log_buffer->append(str); | 2831 int line, |
2832 return false; | 2832 size_t message_start, |
2833 } | 2833 const std::string& str) override { |
| 2834 if (!g_log_buffer) |
| 2835 g_log_buffer = new std::string(); |
| 2836 g_log_buffer->append(str); |
| 2837 } |
| 2838 }; |
2834 | 2839 |
2835 TEST_F(TraceEventTestFixture, EchoToConsole) { | 2840 TEST_F(TraceEventTestFixture, EchoToConsole) { |
2836 logging::LogMessageHandlerFunction old_log_message_handler = | 2841 MockLogMessageListener l; |
2837 logging::GetLogMessageHandler(); | |
2838 logging::SetLogMessageHandler(MockLogMessageHandler); | |
2839 | 2842 |
2840 TraceLog::GetInstance()->SetEnabled( | 2843 TraceLog::GetInstance()->SetEnabled( |
2841 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 2844 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
2842 TraceLog::RECORDING_MODE); | 2845 TraceLog::RECORDING_MODE); |
2843 TRACE_EVENT_BEGIN0("a", "begin_end"); | 2846 TRACE_EVENT_BEGIN0("a", "begin_end"); |
2844 { | 2847 { |
2845 TRACE_EVENT0("b", "duration"); | 2848 TRACE_EVENT0("b", "duration"); |
2846 TRACE_EVENT0("b1", "duration1"); | 2849 TRACE_EVENT0("b1", "duration1"); |
2847 } | 2850 } |
2848 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); | 2851 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); |
2849 TRACE_EVENT_END0("a", "begin_end"); | 2852 TRACE_EVENT_END0("a", "begin_end"); |
2850 | 2853 |
2851 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); | 2854 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); |
2852 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); | 2855 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); |
2853 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); | 2856 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); |
2854 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); | 2857 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); |
2855 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); | 2858 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); |
2856 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); | 2859 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); |
2857 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); | 2860 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); |
2858 | 2861 |
2859 EndTraceAndFlush(); | 2862 EndTraceAndFlush(); |
2860 delete g_log_buffer; | 2863 delete g_log_buffer; |
2861 logging::SetLogMessageHandler(old_log_message_handler); | |
2862 g_log_buffer = NULL; | 2864 g_log_buffer = NULL; |
2863 } | 2865 } |
2864 | 2866 |
2865 bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t, | 2867 class LogMessageListenerWithTraceEvent : logging::LogMessageListener { |
2866 const std::string&) { | 2868 public: |
2867 TRACE_EVENT0("log", "trace_event"); | 2869 void OnMessage(int severity, |
2868 return false; | 2870 const char* file, |
2869 } | 2871 int line, |
| 2872 size_t message_start, |
| 2873 const std::string& str) override { |
| 2874 TRACE_EVENT0("log", "trace_event"); |
| 2875 } |
| 2876 }; |
2870 | 2877 |
2871 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { | 2878 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { |
2872 logging::LogMessageHandlerFunction old_log_message_handler = | 2879 LogMessageListenerWithTraceEvent l; |
2873 logging::GetLogMessageHandler(); | |
2874 logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent); | |
2875 | 2880 |
2876 TraceLog::GetInstance()->SetEnabled( | 2881 TraceLog::GetInstance()->SetEnabled( |
2877 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 2882 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
2878 TraceLog::RECORDING_MODE); | 2883 TraceLog::RECORDING_MODE); |
2879 { | 2884 { |
2880 // This should not cause deadlock or infinite recursion. | 2885 // This should not cause deadlock or infinite recursion. |
2881 TRACE_EVENT0("b", "duration"); | 2886 TRACE_EVENT0("b", "duration"); |
2882 } | 2887 } |
2883 | 2888 |
2884 EndTraceAndFlush(); | 2889 EndTraceAndFlush(); |
2885 logging::SetLogMessageHandler(old_log_message_handler); | |
2886 } | 2890 } |
2887 | 2891 |
2888 TEST_F(TraceEventTestFixture, TimeOffset) { | 2892 TEST_F(TraceEventTestFixture, TimeOffset) { |
2889 BeginTrace(); | 2893 BeginTrace(); |
2890 // Let TraceLog timer start from 0. | 2894 // Let TraceLog timer start from 0. |
2891 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); | 2895 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); |
2892 TraceLog::GetInstance()->SetTimeOffset(time_offset); | 2896 TraceLog::GetInstance()->SetTimeOffset(time_offset); |
2893 | 2897 |
2894 { | 2898 { |
2895 TRACE_EVENT0("all", "duration1"); | 2899 TRACE_EVENT0("all", "duration1"); |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3169 | 3173 |
3170 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3174 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
3171 BeginSpecificTrace("-*"); | 3175 BeginSpecificTrace("-*"); |
3172 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3176 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
3173 EndTraceAndFlush(); | 3177 EndTraceAndFlush(); |
3174 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3178 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
3175 } | 3179 } |
3176 | 3180 |
3177 } // namespace trace_event | 3181 } // namespace trace_event |
3178 } // namespace base | 3182 } // namespace base |
OLD | NEW |