| 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 2802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2813 BeginTrace(); | 2813 BeginTrace(); |
| 2814 thread.task_runner()->PostTask( | 2814 thread.task_runner()->PostTask( |
| 2815 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); | 2815 FROM_HERE, Bind(&TraceWithAllMacroVariants, &task_complete_event)); |
| 2816 task_complete_event.Wait(); | 2816 task_complete_event.Wait(); |
| 2817 task_complete_event.Reset(); | 2817 task_complete_event.Reset(); |
| 2818 EndTraceAndFlushInThreadWithMessageLoop(); | 2818 EndTraceAndFlushInThreadWithMessageLoop(); |
| 2819 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 2819 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
| 2820 } | 2820 } |
| 2821 | 2821 |
| 2822 std::string* g_log_buffer = NULL; | 2822 std::string* g_log_buffer = NULL; |
| 2823 bool MockLogMessageHandler(int, const char*, int, size_t, | 2823 bool MockLogMessageHandler(int, |
| 2824 const std::string, |
| 2825 int, |
| 2824 const std::string& str) { | 2826 const std::string& str) { |
| 2825 if (!g_log_buffer) | 2827 if (!g_log_buffer) |
| 2826 g_log_buffer = new std::string(); | 2828 g_log_buffer = new std::string(); |
| 2827 g_log_buffer->append(str); | 2829 g_log_buffer->append(str); |
| 2828 return false; | 2830 return false; |
| 2829 } | 2831 } |
| 2830 | 2832 |
| 2831 TEST_F(TraceEventTestFixture, EchoToConsole) { | 2833 TEST_F(TraceEventTestFixture, EchoToConsole) { |
| 2832 logging::LogMessageHandlerFunction old_log_message_handler = | 2834 logging::AddLogMessageHandler(MockLogMessageHandler); |
| 2833 logging::GetLogMessageHandler(); | |
| 2834 logging::SetLogMessageHandler(MockLogMessageHandler); | |
| 2835 | 2835 |
| 2836 TraceLog::GetInstance()->SetEnabled( | 2836 TraceLog::GetInstance()->SetEnabled( |
| 2837 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 2837 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
| 2838 TraceLog::RECORDING_MODE); | 2838 TraceLog::RECORDING_MODE); |
| 2839 TRACE_EVENT_BEGIN0("a", "begin_end"); | 2839 TRACE_EVENT_BEGIN0("a", "begin_end"); |
| 2840 { | 2840 { |
| 2841 TRACE_EVENT0("b", "duration"); | 2841 TRACE_EVENT0("b", "duration"); |
| 2842 TRACE_EVENT0("b1", "duration1"); | 2842 TRACE_EVENT0("b1", "duration1"); |
| 2843 } | 2843 } |
| 2844 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); | 2844 TRACE_EVENT_INSTANT0("c", "instant", TRACE_EVENT_SCOPE_GLOBAL); |
| 2845 TRACE_EVENT_END0("a", "begin_end"); | 2845 TRACE_EVENT_END0("a", "begin_end"); |
| 2846 | 2846 |
| 2847 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); | 2847 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a]\x1b")); |
| 2848 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); | 2848 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b]\x1b")); |
| 2849 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); | 2849 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1]\x1b")); |
| 2850 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); | 2850 EXPECT_NE(std::string::npos, g_log_buffer->find("| | duration1[b1] (")); |
| 2851 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); | 2851 EXPECT_NE(std::string::npos, g_log_buffer->find("| duration[b] (")); |
| 2852 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); | 2852 EXPECT_NE(std::string::npos, g_log_buffer->find("| instant[c]\x1b")); |
| 2853 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); | 2853 EXPECT_NE(std::string::npos, g_log_buffer->find("begin_end[a] (")); |
| 2854 | 2854 |
| 2855 EndTraceAndFlush(); | 2855 EndTraceAndFlush(); |
| 2856 delete g_log_buffer; | 2856 delete g_log_buffer; |
| 2857 logging::SetLogMessageHandler(old_log_message_handler); | 2857 logging::RemoveLogMessageHandler(MockLogMessageHandler); |
| 2858 g_log_buffer = NULL; | 2858 g_log_buffer = NULL; |
| 2859 } | 2859 } |
| 2860 | 2860 |
| 2861 bool LogMessageHandlerWithTraceEvent(int, const char*, int, size_t, | 2861 bool LogMessageHandlerWithTraceEvent(int, |
| 2862 const std::string&, |
| 2863 int, |
| 2862 const std::string&) { | 2864 const std::string&) { |
| 2863 TRACE_EVENT0("log", "trace_event"); | 2865 TRACE_EVENT0("log", "trace_event"); |
| 2864 return false; | 2866 return false; |
| 2865 } | 2867 } |
| 2866 | 2868 |
| 2867 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { | 2869 TEST_F(TraceEventTestFixture, EchoToConsoleTraceEventRecursion) { |
| 2868 logging::LogMessageHandlerFunction old_log_message_handler = | 2870 logging::AddLogMessageHandler(LogMessageHandlerWithTraceEvent); |
| 2869 logging::GetLogMessageHandler(); | |
| 2870 logging::SetLogMessageHandler(LogMessageHandlerWithTraceEvent); | |
| 2871 | 2871 |
| 2872 TraceLog::GetInstance()->SetEnabled( | 2872 TraceLog::GetInstance()->SetEnabled( |
| 2873 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), | 2873 TraceConfig(kRecordAllCategoryFilter, ECHO_TO_CONSOLE), |
| 2874 TraceLog::RECORDING_MODE); | 2874 TraceLog::RECORDING_MODE); |
| 2875 { | 2875 { |
| 2876 // This should not cause deadlock or infinite recursion. | 2876 // This should not cause deadlock or infinite recursion. |
| 2877 TRACE_EVENT0("b", "duration"); | 2877 TRACE_EVENT0("b", "duration"); |
| 2878 } | 2878 } |
| 2879 | 2879 |
| 2880 EndTraceAndFlush(); | 2880 EndTraceAndFlush(); |
| 2881 logging::SetLogMessageHandler(old_log_message_handler); | 2881 logging::RemoveLogMessageHandler(LogMessageHandlerWithTraceEvent); |
| 2882 } | 2882 } |
| 2883 | 2883 |
| 2884 TEST_F(TraceEventTestFixture, TimeOffset) { | 2884 TEST_F(TraceEventTestFixture, TimeOffset) { |
| 2885 BeginTrace(); | 2885 BeginTrace(); |
| 2886 // Let TraceLog timer start from 0. | 2886 // Let TraceLog timer start from 0. |
| 2887 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); | 2887 TimeDelta time_offset = TimeTicks::Now() - TimeTicks(); |
| 2888 TraceLog::GetInstance()->SetTimeOffset(time_offset); | 2888 TraceLog::GetInstance()->SetTimeOffset(time_offset); |
| 2889 | 2889 |
| 2890 { | 2890 { |
| 2891 TRACE_EVENT0("all", "duration1"); | 2891 TRACE_EVENT0("all", "duration1"); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3203 | 3203 |
| 3204 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { | 3204 TEST_F(TraceEventTestFixture, ClockSyncEventsAreAlwaysAddedToTrace) { |
| 3205 BeginSpecificTrace("-*"); | 3205 BeginSpecificTrace("-*"); |
| 3206 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); | 3206 TRACE_EVENT_CLOCK_SYNC_RECEIVER(1); |
| 3207 EndTraceAndFlush(); | 3207 EndTraceAndFlush(); |
| 3208 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); | 3208 EXPECT_TRUE(FindNamePhase("clock_sync", "c")); |
| 3209 } | 3209 } |
| 3210 | 3210 |
| 3211 } // namespace trace_event | 3211 } // namespace trace_event |
| 3212 } // namespace base | 3212 } // namespace base |
| OLD | NEW |