Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
Ilya Sherman
2015/03/17 23:57:39
nit: 2015
vadimt
2015/03/19 00:20:44
Done.
| |
| 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 class TestObserver : public TrackingSynchronizerObserver { | |
| 18 public: | |
| 19 TestObserver() { | |
| 20 } | |
|
Ilya Sherman
2015/03/17 23:57:39
nit: Could you please "git cl format" this file if
vadimt
2015/03/19 00:20:44
I'm using it. Just it was OK. I placed {} on the s
| |
| 21 | |
| 22 ~TestObserver() { | |
| 23 EXPECT_TRUE(got_phase_0_); | |
| 24 EXPECT_TRUE(got_phase_1_); | |
| 25 } | |
| 26 | |
| 27 virtual void ReceivedProfilerData( | |
| 28 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, | |
| 29 base::ProcessId process_id, | |
| 30 content::ProcessType process_type, | |
| 31 int profiling_phase, | |
| 32 const base::TimeDelta& phase_start, | |
| 33 const base::TimeDelta& phase_finish, | |
| 34 const ProfilerEvents& past_events) override { | |
| 35 ASSERT_EQ(239, process_id); | |
| 36 ASSERT_EQ(content::ProcessType::PROCESS_TYPE_PLUGIN, process_type); | |
|
Ilya Sherman
2015/03/17 23:57:39
nit: Can the ASSERT_*'s be EXPECT_*'s throughout t
| |
| 37 | |
| 38 switch (profiling_phase) { | |
| 39 case 0: | |
| 40 ASSERT_FALSE(got_phase_0_); | |
| 41 got_phase_0_ = true; | |
| 42 | |
| 43 ASSERT_EQ(base::TimeDelta::FromMilliseconds(0), phase_start); | |
| 44 ASSERT_EQ(base::TimeDelta::FromMilliseconds(222), phase_finish); | |
| 45 | |
| 46 ASSERT_EQ("death_thread0", | |
| 47 process_data_phase.tasks[0].death_thread_name); | |
| 48 ASSERT_EQ(0, past_events.size()); | |
| 49 break; | |
| 50 | |
| 51 case 1: | |
| 52 ASSERT_FALSE(got_phase_1_); | |
| 53 got_phase_1_ = true; | |
| 54 | |
| 55 ASSERT_EQ(base::TimeDelta::FromMilliseconds(222), phase_start); | |
| 56 ASSERT_EQ(base::TimeDelta::FromMilliseconds(666), phase_finish); | |
| 57 | |
| 58 ASSERT_EQ("death_thread1", | |
| 59 process_data_phase.tasks[0].death_thread_name); | |
| 60 ASSERT_EQ(1, past_events.size()); | |
| 61 ASSERT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, | |
| 62 past_events[0]); | |
| 63 break; | |
| 64 | |
| 65 default: | |
| 66 ASSERT_FALSE("profiling_phase is neither 0 nor 1"); | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 private: | |
| 71 bool got_phase_0_ = false; | |
| 72 bool got_phase_1_ = false; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(TestObserver); | |
| 75 }; | |
| 76 | |
| 77 base::TimeTicks TestTimeFromMs(int64 ms) { | |
| 78 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | |
| 79 } | |
|
Ilya Sherman
2015/03/17 23:57:39
nit: Please move the code above this line into an
vadimt
2015/03/19 00:20:44
Done.
| |
| 80 | |
| 81 TEST(TrackingSynchronizerTest, ProfilerData) { | |
| 82 // Testing how TrackingSynchronizer reports 2 phases of profiling to | |
| 83 // TrackingSynchronizerObserver. | |
| 84 content::TestBrowserThreadBundle thread_bundle; | |
| 85 | |
| 86 scoped_refptr<TrackingSynchronizer> ts = | |
|
Ilya Sherman
2015/03/17 23:57:39
nit: Please use complete variable names, rather th
vadimt
2015/03/19 00:20:44
Done.
| |
| 87 new TrackingSynchronizer(TestTimeFromMs(111)); | |
| 88 | |
| 89 // Mimic a phase change event. | |
| 90 ts->phase_completion_events_sequence_.push_back( | |
| 91 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | |
| 92 ts->phase_start_times_.push_back(TestTimeFromMs(333)); | |
| 93 | |
| 94 tracked_objects::ProcessDataSnapshot profiler_data; | |
| 95 ProcessDataPhaseSnapshot snapshot0; | |
| 96 tracked_objects::TaskSnapshot task_snapshot0; | |
| 97 task_snapshot0.death_thread_name = "death_thread0"; | |
| 98 snapshot0.tasks.push_back(task_snapshot0); | |
| 99 ProcessDataPhaseSnapshot snapshot1; | |
| 100 profiler_data.phased_process_data_snapshots[0] = snapshot0; | |
| 101 tracked_objects::TaskSnapshot task_snapshot1; | |
| 102 task_snapshot1.death_thread_name = "death_thread1"; | |
| 103 snapshot1.tasks.push_back(task_snapshot1); | |
| 104 profiler_data.phased_process_data_snapshots[1] = snapshot1; | |
| 105 profiler_data.process_id = 239; | |
| 106 | |
| 107 TestObserver to; | |
|
Ilya Sherman
2015/03/17 23:57:38
nit: Please use complete variable names, rather th
vadimt
2015/03/19 00:20:44
Done.
| |
| 108 ts->SendData(profiler_data, content::ProcessType::PROCESS_TYPE_PLUGIN, | |
| 109 TestTimeFromMs(777), &to); | |
| 110 } | |
| 111 | |
| 112 } // namespace metrics | |
| OLD | NEW |