Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Side by Side Diff: components/metrics/profiler/tracking_synchronizer_unittest.cc

Issue 985773002: Introducing phased profiling framework (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@write_to_file
Patch Set: Additional isherman@ comments. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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() {
24 EXPECT_TRUE(got_phase_0_);
25 EXPECT_TRUE(got_phase_1_);
26 }
27
28 virtual 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 const base::TimeDelta& phase_start,
34 const base::TimeDelta& phase_finish,
35 const ProfilerEvents& past_events) override {
36 EXPECT_EQ(239ul, 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 EXPECT_FALSE("profiling_phase is neither 0 nor 1");
69 }
70 }
71
72 private:
73 bool got_phase_0_ = false;
74 bool got_phase_1_ = false;
75
76 DISALLOW_COPY_AND_ASSIGN(TestObserver);
77 };
78
79 base::TimeTicks TestTimeFromMs(int64 ms) {
80 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms);
81 }
82
83 } // namespace
84
85 TEST(TrackingSynchronizerTest, ProfilerData) {
86 // Testing how TrackingSynchronizer reports 2 phases of profiling
87 // test_observer
88 // TrackingSynchronizerObserver.
Ilya Sherman 2015/03/19 01:00:51 nit: re-wrap?
vadimt 2015/03/19 18:01:47 Done.
89 content::TestBrowserThreadBundle thread_bundle;
90
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698