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/tracked_objects.h" | 6 #include "base/tracked_objects.h" |
7 #include "components/metrics/profiler/tracking_synchronizer.h" | 7 #include "components/metrics/profiler/tracking_synchronizer.h" |
8 #include "components/metrics/profiler/tracking_synchronizer_observer.h" | 8 #include "components/metrics/profiler/tracking_synchronizer_observer.h" |
9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 private: | 72 private: |
73 bool got_phase_0_ = false; | 73 bool got_phase_0_ = false; |
74 bool got_phase_1_ = false; | 74 bool got_phase_1_ = false; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 76 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
77 }; | 77 }; |
78 | 78 |
79 class TestTrackingSynchronizer : public TrackingSynchronizer { | |
80 public: | |
81 explicit TestTrackingSynchronizer(const base::TimeTicks& now) | |
Alexei Svitkine (slow)
2015/03/30 18:31:21
I think this should be passed by value. Same below
| |
82 : TrackingSynchronizer(now) {} | |
83 | |
84 void RegisterPhaseCompletion( | |
85 ProfilerEventProto::ProfilerEvent profiling_event, | |
86 const base::TimeTicks& now) { | |
87 TrackingSynchronizer::RegisterPhaseCompletion(profiling_event, now); | |
88 } | |
89 | |
90 ~TestTrackingSynchronizer() {} | |
91 | |
92 void SendData(const tracked_objects::ProcessDataSnapshot& profiler_data, | |
93 content::ProcessType process_type, | |
94 const base::TimeTicks& now, | |
95 TrackingSynchronizerObserver* observer) const { | |
96 TrackingSynchronizer::SendData(profiler_data, process_type, now, observer); | |
97 } | |
98 }; | |
99 | |
79 base::TimeTicks TestTimeFromMs(int64 ms) { | 100 base::TimeTicks TestTimeFromMs(int64 ms) { |
80 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | 101 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
81 } | 102 } |
82 | 103 |
83 } // namespace | 104 } // namespace |
84 | 105 |
85 TEST(TrackingSynchronizerTest, ProfilerData) { | 106 TEST(TrackingSynchronizerTest, ProfilerData) { |
86 // Testing how TrackingSynchronizer reports 2 phases of profiling. | 107 // Testing how TrackingSynchronizer reports 2 phases of profiling. |
87 | 108 |
88 content::TestBrowserThreadBundle thread_bundle; | 109 content::TestBrowserThreadBundle thread_bundle; |
89 | 110 |
90 scoped_refptr<TrackingSynchronizer> tracking_synchronizer = | 111 scoped_refptr<TestTrackingSynchronizer> tracking_synchronizer = |
91 new TrackingSynchronizer(TestTimeFromMs(111)); | 112 new TestTrackingSynchronizer(TestTimeFromMs(111)); |
92 | 113 |
93 // Mimic a phase change event. | 114 tracking_synchronizer->RegisterPhaseCompletion( |
94 tracking_synchronizer->phase_completion_events_sequence_.push_back( | 115 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, TestTimeFromMs(333)); |
95 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | |
96 tracking_synchronizer->phase_start_times_.push_back(TestTimeFromMs(333)); | |
97 | 116 |
98 tracked_objects::ProcessDataSnapshot profiler_data; | 117 tracked_objects::ProcessDataSnapshot profiler_data; |
99 ProcessDataPhaseSnapshot snapshot0; | 118 ProcessDataPhaseSnapshot snapshot0; |
100 tracked_objects::TaskSnapshot task_snapshot0; | 119 tracked_objects::TaskSnapshot task_snapshot0; |
101 task_snapshot0.death_thread_name = "death_thread0"; | 120 task_snapshot0.death_thread_name = "death_thread0"; |
102 snapshot0.tasks.push_back(task_snapshot0); | 121 snapshot0.tasks.push_back(task_snapshot0); |
103 ProcessDataPhaseSnapshot snapshot1; | 122 ProcessDataPhaseSnapshot snapshot1; |
104 profiler_data.phased_process_data_snapshots[0] = snapshot0; | 123 profiler_data.phased_process_data_snapshots[0] = snapshot0; |
105 tracked_objects::TaskSnapshot task_snapshot1; | 124 tracked_objects::TaskSnapshot task_snapshot1; |
106 task_snapshot1.death_thread_name = "death_thread1"; | 125 task_snapshot1.death_thread_name = "death_thread1"; |
107 snapshot1.tasks.push_back(task_snapshot1); | 126 snapshot1.tasks.push_back(task_snapshot1); |
108 profiler_data.phased_process_data_snapshots[1] = snapshot1; | 127 profiler_data.phased_process_data_snapshots[1] = snapshot1; |
109 profiler_data.process_id = 239; | 128 profiler_data.process_id = 239; |
110 | 129 |
111 TestObserver test_observer; | 130 TestObserver test_observer; |
112 tracking_synchronizer->SendData(profiler_data, | 131 tracking_synchronizer->SendData(profiler_data, |
113 content::ProcessType::PROCESS_TYPE_PLUGIN, | 132 content::ProcessType::PROCESS_TYPE_PLUGIN, |
114 TestTimeFromMs(777), &test_observer); | 133 TestTimeFromMs(777), &test_observer); |
115 } | 134 } |
116 | 135 |
117 } // namespace metrics | 136 } // namespace metrics |
OLD | NEW |