OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/test/simple_test_tick_clock.h" | |
6 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
7 #include "components/metrics/profiler/tracking_synchronizer.h" | 8 #include "components/metrics/profiler/tracking_synchronizer.h" |
8 #include "components/metrics/profiler/tracking_synchronizer_observer.h" | 9 #include "components/metrics/profiler/tracking_synchronizer_observer.h" |
9 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 using tracked_objects::ProcessDataPhaseSnapshot; | 13 using tracked_objects::ProcessDataPhaseSnapshot; |
13 using tracked_objects::TaskSnapshot; | 14 using tracked_objects::TaskSnapshot; |
14 | 15 |
15 namespace metrics { | 16 namespace metrics { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 71 } |
71 } | 72 } |
72 | 73 |
73 private: | 74 private: |
74 bool got_phase_0_ = false; | 75 bool got_phase_0_ = false; |
75 bool got_phase_1_ = false; | 76 bool got_phase_1_ = false; |
76 | 77 |
77 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 78 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
78 }; | 79 }; |
79 | 80 |
80 base::TimeTicks TestTimeFromMs(int64 ms) { | 81 class TestTrackingSynchronizer : public TrackingSynchronizer { |
81 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | 82 public: |
82 } | 83 explicit TestTrackingSynchronizer(base::TickClock* clock) |
84 : TrackingSynchronizer(clock) {} | |
85 | |
86 ~TestTrackingSynchronizer() {} | |
87 | |
88 void RegisterPhaseCompletion( | |
89 ProfilerEventProto::ProfilerEvent profiling_event) { | |
90 TrackingSynchronizer::RegisterPhaseCompletion(profiling_event); | |
91 } | |
92 | |
93 void SendData(const tracked_objects::ProcessDataSnapshot& profiler_data, | |
94 content::ProcessType process_type, | |
95 TrackingSynchronizerObserver* observer) const { | |
96 TrackingSynchronizer::SendData(profiler_data, process_type, observer); | |
97 } | |
98 }; | |
Ilya Sherman
2015/04/07 22:58:35
Can you test the public API of the class, rather t
vadimt
2015/04/08 01:09:50
Not sure it's worth the effort. The purpose of the
| |
83 | 99 |
84 } // namespace | 100 } // namespace |
85 | 101 |
86 TEST(TrackingSynchronizerTest, ProfilerData) { | 102 TEST(TrackingSynchronizerTest, ProfilerData) { |
87 // Testing how TrackingSynchronizer reports 2 phases of profiling. | 103 // Testing how TrackingSynchronizer reports 2 phases of profiling. |
88 #if !defined(OS_IOS) | 104 #if !defined(OS_IOS) |
89 content::TestBrowserThreadBundle thread_bundle; | 105 content::TestBrowserThreadBundle thread_bundle; |
90 #endif | 106 #endif |
91 scoped_refptr<TrackingSynchronizer> tracking_synchronizer = | |
92 new TrackingSynchronizer(TestTimeFromMs(111)); | |
93 | 107 |
94 // Mimic a phase change event. | 108 auto clock = new base::SimpleTestTickClock(); |
Ilya Sherman
2015/04/07 22:58:35
Please document why this isn't leaked, since it lo
vadimt
2015/04/08 01:09:50
Done.
| |
95 tracking_synchronizer->phase_completion_events_sequence_.push_back( | 109 clock->Advance(base::TimeDelta::FromMilliseconds(111)); |
110 | |
111 scoped_refptr<TestTrackingSynchronizer> tracking_synchronizer = | |
112 new TestTrackingSynchronizer(clock); | |
113 | |
114 clock->Advance(base::TimeDelta::FromMilliseconds(222)); | |
115 | |
116 tracking_synchronizer->RegisterPhaseCompletion( | |
96 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | 117 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
97 tracking_synchronizer->phase_start_times_.push_back(TestTimeFromMs(333)); | |
98 | 118 |
99 tracked_objects::ProcessDataSnapshot profiler_data; | 119 tracked_objects::ProcessDataSnapshot profiler_data; |
100 ProcessDataPhaseSnapshot snapshot0; | 120 ProcessDataPhaseSnapshot snapshot0; |
101 tracked_objects::TaskSnapshot task_snapshot0; | 121 tracked_objects::TaskSnapshot task_snapshot0; |
102 task_snapshot0.death_thread_name = "death_thread0"; | 122 task_snapshot0.death_thread_name = "death_thread0"; |
103 snapshot0.tasks.push_back(task_snapshot0); | 123 snapshot0.tasks.push_back(task_snapshot0); |
104 ProcessDataPhaseSnapshot snapshot1; | 124 ProcessDataPhaseSnapshot snapshot1; |
105 profiler_data.phased_process_data_snapshots[0] = snapshot0; | 125 profiler_data.phased_process_data_snapshots[0] = snapshot0; |
106 tracked_objects::TaskSnapshot task_snapshot1; | 126 tracked_objects::TaskSnapshot task_snapshot1; |
107 task_snapshot1.death_thread_name = "death_thread1"; | 127 task_snapshot1.death_thread_name = "death_thread1"; |
108 snapshot1.tasks.push_back(task_snapshot1); | 128 snapshot1.tasks.push_back(task_snapshot1); |
109 profiler_data.phased_process_data_snapshots[1] = snapshot1; | 129 profiler_data.phased_process_data_snapshots[1] = snapshot1; |
110 profiler_data.process_id = 239; | 130 profiler_data.process_id = 239; |
111 | 131 |
132 clock->Advance(base::TimeDelta::FromMilliseconds(444)); | |
112 TestObserver test_observer; | 133 TestObserver test_observer; |
113 tracking_synchronizer->SendData(profiler_data, | 134 tracking_synchronizer->SendData( |
114 content::ProcessType::PROCESS_TYPE_PLUGIN, | 135 profiler_data, content::ProcessType::PROCESS_TYPE_PLUGIN, &test_observer); |
115 TestTimeFromMs(777), &test_observer); | |
116 } | 136 } |
117 | 137 |
118 } // namespace metrics | 138 } // namespace metrics |
OLD | NEW |