OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/tracked_objects.h" |
| 7 #include "components/metrics/profiler/tracking_synchronizer.h" |
| 8 #include "components/metrics/profiler/tracking_synchronizer_observer.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 using tracked_objects::ProcessDataPhaseSnapshot; |
| 13 using tracked_objects::TaskSnapshot; |
| 14 |
| 15 namespace metrics { |
| 16 |
| 17 namespace { |
| 18 |
| 19 class TestObserver : public TrackingSynchronizerObserver { |
| 20 public: |
| 21 TestObserver() {} |
| 22 |
| 23 ~TestObserver() override { |
| 24 EXPECT_TRUE(got_phase_0_); |
| 25 EXPECT_TRUE(got_phase_1_); |
| 26 } |
| 27 |
| 28 void ReceivedProfilerData( |
| 29 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, |
| 30 base::ProcessId process_id, |
| 31 content::ProcessType process_type, |
| 32 int profiling_phase, |
| 33 base::TimeDelta phase_start, |
| 34 base::TimeDelta phase_finish, |
| 35 const ProfilerEvents& past_events) override { |
| 36 EXPECT_EQ(static_cast<base::ProcessId>(239), process_id); |
| 37 EXPECT_EQ(content::ProcessType::PROCESS_TYPE_PLUGIN, process_type); |
| 38 ASSERT_EQ(1u, process_data_phase.tasks.size()); |
| 39 |
| 40 switch (profiling_phase) { |
| 41 case 0: |
| 42 EXPECT_FALSE(got_phase_0_); |
| 43 got_phase_0_ = true; |
| 44 |
| 45 EXPECT_EQ(base::TimeDelta::FromMilliseconds(0), phase_start); |
| 46 EXPECT_EQ(base::TimeDelta::FromMilliseconds(222), phase_finish); |
| 47 |
| 48 EXPECT_EQ("death_thread0", |
| 49 process_data_phase.tasks[0].death_thread_name); |
| 50 EXPECT_EQ(0u, past_events.size()); |
| 51 break; |
| 52 |
| 53 case 1: |
| 54 EXPECT_FALSE(got_phase_1_); |
| 55 got_phase_1_ = true; |
| 56 |
| 57 EXPECT_EQ(base::TimeDelta::FromMilliseconds(222), phase_start); |
| 58 EXPECT_EQ(base::TimeDelta::FromMilliseconds(666), phase_finish); |
| 59 |
| 60 EXPECT_EQ("death_thread1", |
| 61 process_data_phase.tasks[0].death_thread_name); |
| 62 ASSERT_EQ(1u, past_events.size()); |
| 63 EXPECT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, |
| 64 past_events[0]); |
| 65 break; |
| 66 |
| 67 default: |
| 68 bool profiling_phase_is_neither_0_nor_1 = true; |
| 69 EXPECT_FALSE(profiling_phase_is_neither_0_nor_1); |
| 70 } |
| 71 } |
| 72 |
| 73 private: |
| 74 bool got_phase_0_ = false; |
| 75 bool got_phase_1_ = false; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 78 }; |
| 79 |
| 80 base::TimeTicks TestTimeFromMs(int64 ms) { |
| 81 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
| 82 } |
| 83 |
| 84 } // namespace |
| 85 |
| 86 TEST(TrackingSynchronizerTest, ProfilerData) { |
| 87 // Testing how TrackingSynchronizer reports 2 phases of profiling. |
| 88 #if !defined(OS_IOS) |
| 89 content::TestBrowserThreadBundle thread_bundle; |
| 90 #endif |
| 91 scoped_refptr<TrackingSynchronizer> tracking_synchronizer = |
| 92 new TrackingSynchronizer(TestTimeFromMs(111)); |
| 93 |
| 94 // Mimic a phase change event. |
| 95 tracking_synchronizer->phase_completion_events_sequence_.push_back( |
| 96 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
| 97 tracking_synchronizer->phase_start_times_.push_back(TestTimeFromMs(333)); |
| 98 |
| 99 tracked_objects::ProcessDataSnapshot profiler_data; |
| 100 ProcessDataPhaseSnapshot snapshot0; |
| 101 tracked_objects::TaskSnapshot task_snapshot0; |
| 102 task_snapshot0.death_thread_name = "death_thread0"; |
| 103 snapshot0.tasks.push_back(task_snapshot0); |
| 104 ProcessDataPhaseSnapshot snapshot1; |
| 105 profiler_data.phased_process_data_snapshots[0] = snapshot0; |
| 106 tracked_objects::TaskSnapshot task_snapshot1; |
| 107 task_snapshot1.death_thread_name = "death_thread1"; |
| 108 snapshot1.tasks.push_back(task_snapshot1); |
| 109 profiler_data.phased_process_data_snapshots[1] = snapshot1; |
| 110 profiler_data.process_id = 239; |
| 111 |
| 112 TestObserver test_observer; |
| 113 tracking_synchronizer->SendData(profiler_data, |
| 114 content::ProcessType::PROCESS_TYPE_PLUGIN, |
| 115 TestTimeFromMs(777), &test_observer); |
| 116 } |
| 117 |
| 118 } // namespace metrics |
OLD | NEW |