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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 private: | 73 private: |
74 bool got_phase_0_ = false; | 74 bool got_phase_0_ = false; |
75 bool got_phase_1_ = false; | 75 bool got_phase_1_ = false; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 77 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
78 }; | 78 }; |
79 | 79 |
80 class TestTrackingSynchronizer : public TrackingSynchronizer { | |
81 public: | |
82 explicit TestTrackingSynchronizer(base::TimeTicks now) | |
83 : TrackingSynchronizer(now) {} | |
84 | |
85 void RegisterPhaseCompletion( | |
86 ProfilerEventProto::ProfilerEvent profiling_event, | |
87 base::TimeTicks now) { | |
88 TrackingSynchronizer::RegisterPhaseCompletion(profiling_event, now); | |
89 } | |
Ilya Sherman
2015/04/07 01:15:30
nit: Can this be written simply as "using Tracking
vadimt
2015/04/07 21:44:14
Technically, this works, at least on Windows, but
Ilya Sherman
2015/04/07 22:58:35
Can you please link to the section of the guide wh
vadimt
2015/04/08 01:09:50
https://chromium-cpp.appspot.com/, Inherited Const
Ilya Sherman
2015/04/08 23:36:14
This isn't a C++11 feature, so that list is not re
vadimt
2015/04/09 00:15:03
Done.
| |
90 | |
91 ~TestTrackingSynchronizer() {} | |
Ilya Sherman
2015/04/07 01:15:30
nit: Please move this up to the constructor.
vadimt
2015/04/07 21:44:14
Done.
| |
92 | |
93 void SendData(const tracked_objects::ProcessDataSnapshot& profiler_data, | |
94 content::ProcessType process_type, | |
95 base::TimeTicks now, | |
96 TrackingSynchronizerObserver* observer) const { | |
97 TrackingSynchronizer::SendData(profiler_data, process_type, now, observer); | |
98 } | |
99 }; | |
Ilya Sherman
2015/04/07 01:15:30
I would strongly prefer to use a TickClock in the
vadimt
2015/04/07 21:44:14
Done.
| |
100 | |
80 base::TimeTicks TestTimeFromMs(int64 ms) { | 101 base::TimeTicks TestTimeFromMs(int64 ms) { |
81 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | 102 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
82 } | 103 } |
83 | 104 |
84 } // namespace | 105 } // namespace |
85 | 106 |
86 TEST(TrackingSynchronizerTest, ProfilerData) { | 107 TEST(TrackingSynchronizerTest, ProfilerData) { |
87 // Testing how TrackingSynchronizer reports 2 phases of profiling. | 108 // Testing how TrackingSynchronizer reports 2 phases of profiling. |
88 #if !defined(OS_IOS) | 109 #if !defined(OS_IOS) |
89 content::TestBrowserThreadBundle thread_bundle; | 110 content::TestBrowserThreadBundle thread_bundle; |
90 #endif | 111 #endif |
91 scoped_refptr<TrackingSynchronizer> tracking_synchronizer = | |
92 new TrackingSynchronizer(TestTimeFromMs(111)); | |
93 | 112 |
94 // Mimic a phase change event. | 113 scoped_refptr<TestTrackingSynchronizer> tracking_synchronizer = |
95 tracking_synchronizer->phase_completion_events_sequence_.push_back( | 114 new TestTrackingSynchronizer(TestTimeFromMs(111)); |
96 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | 115 |
97 tracking_synchronizer->phase_start_times_.push_back(TestTimeFromMs(333)); | 116 tracking_synchronizer->RegisterPhaseCompletion( |
117 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, 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 |
112 TestObserver test_observer; | 132 TestObserver test_observer; |
113 tracking_synchronizer->SendData(profiler_data, | 133 tracking_synchronizer->SendData(profiler_data, |
114 content::ProcessType::PROCESS_TYPE_PLUGIN, | 134 content::ProcessType::PROCESS_TYPE_PLUGIN, |
115 TestTimeFromMs(777), &test_observer); | 135 TestTimeFromMs(777), &test_observer); |
116 } | 136 } |
117 | 137 |
118 } // namespace metrics | 138 } // namespace metrics |
OLD | NEW |