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/debug/trace_event.h" | 5 #include "base/debug/trace_event_unittest.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | |
9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
11 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
14 #include "base/process_util.h" | 15 #include "base/process_util.h" |
15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
17 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
24 using base::debug::HighResSleepForTraceTest; | |
25 | |
23 namespace base { | 26 namespace base { |
24 namespace debug { | 27 namespace debug { |
25 | 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 enum CompareOp { | 31 enum CompareOp { |
29 IS_EQUAL, | 32 IS_EQUAL, |
30 IS_NOT_EQUAL, | 33 IS_NOT_EQUAL, |
31 }; | 34 }; |
32 | 35 |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 | 629 |
627 void TraceCallsWithCachedCategoryPointersPointers(const char* name_str) { | 630 void TraceCallsWithCachedCategoryPointersPointers(const char* name_str) { |
628 TRACE_EVENT0("category name1", name_str); | 631 TRACE_EVENT0("category name1", name_str); |
629 TRACE_EVENT_INSTANT0("category name2", name_str); | 632 TRACE_EVENT_INSTANT0("category name2", name_str); |
630 TRACE_EVENT_BEGIN0("category name3", name_str); | 633 TRACE_EVENT_BEGIN0("category name3", name_str); |
631 TRACE_EVENT_END0("category name4", name_str); | 634 TRACE_EVENT_END0("category name4", name_str); |
632 } | 635 } |
633 | 636 |
634 } // namespace | 637 } // namespace |
635 | 638 |
639 void HighResSleepForTraceTest(base::TimeDelta elapsed) { | |
640 base::TimeTicks end_time = base::TimeTicks::HighResNow() + elapsed; | |
641 do { | |
642 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | |
jar (doing other things)
2012/08/16 01:23:35
As per our discussion... it is very alarming that
| |
643 } while (base::TimeTicks::HighResNow() < end_time); | |
644 } | |
645 | |
636 // Simple Test for emitting data and validating it was received. | 646 // Simple Test for emitting data and validating it was received. |
637 TEST_F(TraceEventTestFixture, DataCaptured) { | 647 TEST_F(TraceEventTestFixture, DataCaptured) { |
638 ManualTestSetUp(); | 648 ManualTestSetUp(); |
639 TraceLog::GetInstance()->SetEnabled(true); | 649 TraceLog::GetInstance()->SetEnabled(true); |
640 | 650 |
641 TraceWithAllMacroVariants(NULL); | 651 TraceWithAllMacroVariants(NULL); |
642 | 652 |
643 TraceLog::GetInstance()->SetEnabled(false); | 653 TraceLog::GetInstance()->SetEnabled(false); |
644 | 654 |
645 ValidateAllTraceMacrosCreatedData(trace_parsed_); | 655 ValidateAllTraceMacrosCreatedData(trace_parsed_); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 TraceLog::GetInstance()->SetEnabled(true); | 846 TraceLog::GetInstance()->SetEnabled(true); |
837 | 847 |
838 // Test that events at the same level are properly filtered by threshold. | 848 // Test that events at the same level are properly filtered by threshold. |
839 { | 849 { |
840 TRACE_EVENT_IF_LONGER_THAN0(100, "time", "threshold 100"); | 850 TRACE_EVENT_IF_LONGER_THAN0(100, "time", "threshold 100"); |
841 TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "threshold 1000"); | 851 TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "threshold 1000"); |
842 TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "threshold 10000"); | 852 TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "threshold 10000"); |
843 // 100+ seconds to avoid flakiness. | 853 // 100+ seconds to avoid flakiness. |
844 TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "threshold long1"); | 854 TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "threshold long1"); |
845 TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "threshold long2"); | 855 TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "threshold long2"); |
846 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | 856 HighResSleepForTraceTest(base::TimeDelta::FromMilliseconds(20)); |
847 } | 857 } |
848 | 858 |
849 // Test that a normal nested event remains after it's parent event is dropped. | 859 // Test that a normal nested event remains after it's parent event is dropped. |
850 { | 860 { |
851 TRACE_EVENT_IF_LONGER_THAN0(1000000, "time", "2threshold10000"); | 861 TRACE_EVENT_IF_LONGER_THAN0(1000000, "time", "2threshold10000"); |
852 { | 862 { |
853 TRACE_EVENT0("time", "nonthreshold1"); | 863 TRACE_EVENT0("time", "nonthreshold1"); |
854 } | 864 } |
855 } | 865 } |
856 | 866 |
857 // Test that parent thresholded events are dropped while some nested events | 867 // Test that parent thresholded events are dropped while some nested events |
858 // remain. | 868 // remain. |
859 { | 869 { |
860 TRACE_EVENT0("time", "nonthreshold3"); | 870 TRACE_EVENT0("time", "nonthreshold3"); |
861 { | 871 { |
862 TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "3thresholdlong2"); | 872 TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", "3thresholdlong2"); |
863 { | 873 { |
864 TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "3thresholdlong1"); | 874 TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", "3thresholdlong1"); |
865 { | 875 { |
866 TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "3threshold10000"); | 876 TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "3threshold10000"); |
867 { | 877 { |
868 TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "3threshold1000"); | 878 TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "3threshold1000"); |
869 { | 879 { |
870 TRACE_EVENT_IF_LONGER_THAN0(100, "time", "3threshold100"); | 880 TRACE_EVENT_IF_LONGER_THAN0(100, "time", "3threshold100"); |
871 base::PlatformThread::Sleep( | 881 HighResSleepForTraceTest(base::TimeDelta::FromMilliseconds(20)); |
872 base::TimeDelta::FromMilliseconds(20)); | |
873 } | 882 } |
874 } | 883 } |
875 } | 884 } |
876 } | 885 } |
877 } | 886 } |
878 } | 887 } |
879 | 888 |
880 // Test that child thresholded events are dropped while some parent events | 889 // Test that child thresholded events are dropped while some parent events |
881 // remain. | 890 // remain. |
882 { | 891 { |
883 TRACE_EVENT0("time", "nonthreshold4"); | 892 TRACE_EVENT0("time", "nonthreshold4"); |
884 { | 893 { |
885 TRACE_EVENT_IF_LONGER_THAN0(100, "time", "4threshold100"); | 894 TRACE_EVENT_IF_LONGER_THAN0(100, "time", "4threshold100"); |
886 { | 895 { |
887 TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "4threshold1000"); | 896 TRACE_EVENT_IF_LONGER_THAN0(1000, "time", "4threshold1000"); |
888 { | 897 { |
889 TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "4threshold10000"); | 898 TRACE_EVENT_IF_LONGER_THAN0(10000, "time", "4threshold10000"); |
890 { | 899 { |
891 TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", | 900 TRACE_EVENT_IF_LONGER_THAN0(100000000, "time", |
892 "4thresholdlong1"); | 901 "4thresholdlong1"); |
893 { | 902 { |
894 TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", | 903 TRACE_EVENT_IF_LONGER_THAN0(200000000, "time", |
895 "4thresholdlong2"); | 904 "4thresholdlong2"); |
896 base::PlatformThread::Sleep( | 905 HighResSleepForTraceTest(base::TimeDelta::FromMilliseconds(20)); |
897 base::TimeDelta::FromMilliseconds(20)); | |
898 } | 906 } |
899 } | 907 } |
900 } | 908 } |
901 } | 909 } |
902 } | 910 } |
903 } | 911 } |
904 | 912 |
905 TraceLog::GetInstance()->SetEnabled(false); | 913 TraceLog::GetInstance()->SetEnabled(false); |
906 | 914 |
907 #define EXPECT_FIND_BE_(str) \ | 915 #define EXPECT_FIND_BE_(str) \ |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1367 Clear(); | 1375 Clear(); |
1368 | 1376 |
1369 trace_buffer_.Start(); | 1377 trace_buffer_.Start(); |
1370 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); | 1378 trace_buffer_.AddFragment("bla1,bla2,bla3,bla4"); |
1371 trace_buffer_.Finish(); | 1379 trace_buffer_.Finish(); |
1372 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); | 1380 EXPECT_STREQ(json_output_.json_output.c_str(), "[bla1,bla2,bla3,bla4]"); |
1373 } | 1381 } |
1374 | 1382 |
1375 } // namespace debug | 1383 } // namespace debug |
1376 } // namespace base | 1384 } // namespace base |
OLD | NEW |