OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 class TestObserver : public TrackingSynchronizerObserver { | |
18 public: | |
19 ~TestObserver() { | |
20 EXPECT_TRUE(got0); | |
21 EXPECT_TRUE(got1); | |
22 } | |
23 | |
24 virtual void ReceivedProfilerData( | |
25 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, | |
26 base::ProcessId process_id, | |
27 content::ProcessType process_type, | |
28 int profiling_phase, | |
29 const base::TimeDelta& phase_start, | |
30 const base::TimeDelta& phase_finish, | |
31 const ProfilerEvents& past_events) override { | |
32 ASSERT_EQ(239, process_id); | |
33 ASSERT_EQ(content::ProcessType::PROCESS_TYPE_PLUGIN, process_type); | |
34 | |
35 switch (profiling_phase) { | |
36 case 0: | |
37 ASSERT_FALSE(got0); | |
38 got0 = true; | |
39 | |
40 ASSERT_EQ(base::TimeDelta::FromMilliseconds(0), phase_start); | |
41 ASSERT_EQ(base::TimeDelta::FromMilliseconds(222), phase_finish); | |
42 | |
43 ASSERT_EQ("death_thread0", | |
44 process_data_phase.tasks[0].death_thread_name); | |
45 ASSERT_EQ(0, past_events.size()); | |
46 break; | |
47 | |
48 case 1: | |
49 ASSERT_FALSE(got1); | |
50 got1 = true; | |
51 | |
52 ASSERT_EQ(base::TimeDelta::FromMilliseconds(222), phase_start); | |
53 ASSERT_EQ(base::TimeDelta::FromMilliseconds(666), phase_finish); | |
54 | |
55 ASSERT_EQ("death_thread1", | |
56 process_data_phase.tasks[0].death_thread_name); | |
57 ASSERT_EQ(1, past_events.size()); | |
58 ASSERT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, | |
59 past_events[0]); | |
60 break; | |
61 | |
62 default: | |
63 ASSERT_FALSE("profiling_phase is neither 0 nor 1"); | |
64 } | |
65 } | |
66 | |
67 private: | |
68 bool got0 = false; | |
Alexei Svitkine (slow)
2015/03/16 22:00:15
I'm not sure this syntax is allowed yet. Is it? If
vadimt
2015/03/16 23:09:14
Worked for me.
Alexei Svitkine (slow)
2015/03/17 14:53:41
Sorry, I don't mean whether it compiles, but wheth
vadimt
2015/03/17 15:12:53
Not even allowed, but seems like encouraged:
"Use
Alexei Svitkine (slow)
2015/03/17 15:16:43
Great! Thanks for checking.
| |
69 bool got1 = false; | |
70 }; | |
Alexei Svitkine (slow)
2015/03/16 22:00:15
Nit: DISALLOW_COPY()
vadimt
2015/03/16 23:09:14
Done.
| |
71 | |
72 base::TimeTicks TestTimeFromMs(int64 ms) { | |
73 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); | |
74 } | |
75 | |
76 TEST(TrackingSynchronizerTest, ProfilerData) { | |
77 // Testing how TrackingSynchronizer reports 2 phases of profiling to | |
78 // TrackingSynchronizerObserver. | |
79 content::TestBrowserThreadBundle thread_bundle; | |
80 | |
81 scoped_refptr<TrackingSynchronizer> ts = | |
82 new TrackingSynchronizer(TestTimeFromMs(111)); | |
83 | |
84 // Mimic a phase change event. | |
85 ts->phase_completion_events_sequence_.push_back( | |
86 ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); | |
87 ts->phase_start_times_.push_back(TestTimeFromMs(333)); | |
88 | |
89 tracked_objects::ProcessDataSnapshot profiler_data; | |
90 ProcessDataPhaseSnapshot snapshot0; | |
91 tracked_objects::TaskSnapshot task_snapshot0; | |
92 task_snapshot0.death_thread_name = "death_thread0"; | |
93 snapshot0.tasks.push_back(task_snapshot0); | |
94 ProcessDataPhaseSnapshot snapshot1; | |
95 profiler_data.phased_process_data_snapshots[0] = snapshot0; | |
96 tracked_objects::TaskSnapshot task_snapshot1; | |
97 task_snapshot1.death_thread_name = "death_thread1"; | |
98 snapshot1.tasks.push_back(task_snapshot1); | |
99 profiler_data.phased_process_data_snapshots[1] = snapshot1; | |
100 profiler_data.process_id = 239; | |
101 | |
102 TestObserver to; | |
103 ts->SendData(profiler_data, content::ProcessType::PROCESS_TYPE_PLUGIN, | |
104 TestTimeFromMs(777), &to); | |
105 } | |
106 | |
107 } // namespace metrics | |
OLD | NEW |