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 "mojo/common/task_tracker.h" | 5 #include "mojo/common/task_tracker.h" |
6 | 6 |
7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 namespace common { | 11 namespace common { |
12 namespace test { | 12 namespace test { |
13 | 13 |
14 class TaskTrackerTest : public testing::Test { | 14 class TaskTrackerTest : public testing::Test { |
15 public: | 15 public: |
16 void SetUp() override { | 16 void SetUp() override { |
17 tracked_objects::ThreadData::InitializeAndSetTrackingStatus( | 17 tracked_objects::ThreadData::InitializeAndSetTrackingStatus( |
18 tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE); | 18 tracked_objects::ThreadData::PROFILING_ACTIVE); |
19 } | 19 } |
20 | 20 |
21 void TearDown() override { | 21 void TearDown() override { |
22 tracked_objects::ThreadData::InitializeAndSetTrackingStatus( | 22 tracked_objects::ThreadData::InitializeAndSetTrackingStatus( |
23 tracked_objects::ThreadData::DEACTIVATED); | 23 tracked_objects::ThreadData::DEACTIVATED); |
24 } | 24 } |
25 }; | 25 }; |
26 | 26 |
27 TEST_F(TaskTrackerTest, Nesting) { | 27 TEST_F(TaskTrackerTest, Nesting) { |
28 intptr_t id0 = TaskTracker::StartTracking("Foo", "foo.cc", 1, nullptr); | 28 intptr_t id0 = TaskTracker::StartTracking("Foo", "foo.cc", 1, nullptr); |
29 intptr_t id1 = TaskTracker::StartTracking("Bar", "bar.cc", 1, nullptr); | 29 intptr_t id1 = TaskTracker::StartTracking("Bar", "bar.cc", 1, nullptr); |
30 TaskTracker::EndTracking(id1); | 30 TaskTracker::EndTracking(id1); |
31 TaskTracker::EndTracking(id0); | 31 TaskTracker::EndTracking(id0); |
32 | 32 |
33 tracked_objects::ProcessDataSnapshot snapshot; | 33 tracked_objects::ProcessDataSnapshot snapshot; |
34 tracked_objects::ThreadData::Snapshot(&snapshot); | 34 tracked_objects::ThreadData::Snapshot(0, &snapshot); |
35 | 35 |
36 // Nested one is ignored. | 36 // Nested one is ignored. |
37 EXPECT_EQ(1U, snapshot.phased_process_data_snapshots[0].tasks.size()); | 37 EXPECT_EQ(1U, snapshot.phased_snapshots[0].tasks.size()); |
38 } | 38 } |
39 | 39 |
40 TEST_F(TaskTrackerTest, Twice) { | 40 TEST_F(TaskTrackerTest, Twice) { |
41 intptr_t id0 = TaskTracker::StartTracking("Foo", "foo.cc", 1, nullptr); | 41 intptr_t id0 = TaskTracker::StartTracking("Foo", "foo.cc", 1, nullptr); |
42 TaskTracker::EndTracking(id0); | 42 TaskTracker::EndTracking(id0); |
43 intptr_t id1 = TaskTracker::StartTracking("Bar", "bar.cc", 1, nullptr); | 43 intptr_t id1 = TaskTracker::StartTracking("Bar", "bar.cc", 1, nullptr); |
44 TaskTracker::EndTracking(id1); | 44 TaskTracker::EndTracking(id1); |
45 | 45 |
46 tracked_objects::ProcessDataSnapshot snapshot; | 46 tracked_objects::ProcessDataSnapshot snapshot; |
47 tracked_objects::ThreadData::Snapshot(&snapshot); | 47 tracked_objects::ThreadData::Snapshot(0, &snapshot); |
48 | 48 |
49 EXPECT_EQ(2U, snapshot.phased_process_data_snapshots[0].tasks.size()); | 49 EXPECT_EQ(2U, snapshot.phased_snapshots[0].tasks.size()); |
50 } | 50 } |
51 | 51 |
52 } // namespace test | 52 } // namespace test |
53 } // namespace common | 53 } // namespace common |
54 } // namespace mojo | 54 } // namespace mojo |
OLD | NEW |