| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Test of classes in the tracked_objects.h classes. | 5 // Test of classes in the tracked_objects.h classes. |
| 6 | 6 |
| 7 #include "base/tracked_objects.h" | 7 #include "base/tracked_objects.h" |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 return; | 39 return; |
| 40 | 40 |
| 41 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 41 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 42 ThreadData* data = ThreadData::Get(); | 42 ThreadData* data = ThreadData::Get(); |
| 43 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 43 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 44 EXPECT_TRUE(data); | 44 EXPECT_TRUE(data); |
| 45 EXPECT_TRUE(!data->next()); | 45 EXPECT_TRUE(!data->next()); |
| 46 EXPECT_EQ(data, ThreadData::Get()); | 46 EXPECT_EQ(data, ThreadData::Get()); |
| 47 ThreadData::BirthMap birth_map; | 47 ThreadData::BirthMap birth_map; |
| 48 ThreadData::DeathMap death_map; | 48 ThreadData::DeathMap death_map; |
| 49 data->SnapshotMaps(false, &birth_map, &death_map); | 49 ThreadData::ParentChildSet parent_child_set; |
| 50 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 50 EXPECT_EQ(0u, birth_map.size()); | 51 EXPECT_EQ(0u, birth_map.size()); |
| 51 EXPECT_EQ(0u, death_map.size()); | 52 EXPECT_EQ(0u, death_map.size()); |
| 53 EXPECT_EQ(0u, parent_child_set.size()); |
| 52 // Cleanup with no leaking. | 54 // Cleanup with no leaking. |
| 53 ShutdownSingleThreadedCleanup(false); | 55 ShutdownSingleThreadedCleanup(false); |
| 54 | 56 |
| 55 // Do it again, just to be sure we reset state completely. | 57 // Do it again, just to be sure we reset state completely. |
| 56 ThreadData::InitializeAndSetTrackingStatus(true); | 58 ThreadData::InitializeAndSetTrackingStatus(true); |
| 57 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. | 59 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. |
| 58 data = ThreadData::Get(); | 60 data = ThreadData::Get(); |
| 59 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. | 61 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. |
| 60 EXPECT_TRUE(data); | 62 EXPECT_TRUE(data); |
| 61 EXPECT_TRUE(!data->next()); | 63 EXPECT_TRUE(!data->next()); |
| 62 EXPECT_EQ(data, ThreadData::Get()); | 64 EXPECT_EQ(data, ThreadData::Get()); |
| 63 birth_map.clear(); | 65 birth_map.clear(); |
| 64 death_map.clear(); | 66 death_map.clear(); |
| 65 data->SnapshotMaps(false, &birth_map, &death_map); | 67 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 66 EXPECT_EQ(0u, birth_map.size()); | 68 EXPECT_EQ(0u, birth_map.size()); |
| 67 EXPECT_EQ(0u, death_map.size()); | 69 EXPECT_EQ(0u, death_map.size()); |
| 70 EXPECT_EQ(0u, parent_child_set.size()); |
| 68 } | 71 } |
| 69 | 72 |
| 70 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { | 73 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { |
| 71 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 74 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
| 72 return; | 75 return; |
| 73 | 76 |
| 74 // Instigate tracking on a single tracked object, on our thread. | 77 // Instigate tracking on a single tracked object, on our thread. |
| 75 const Location& location = FROM_HERE; | 78 const Location& location = FROM_HERE; |
| 76 ThreadData::TallyABirthIfActive(location); | 79 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
| 77 | 80 |
| 78 ThreadData* data = ThreadData::first(); | 81 ThreadData* data = ThreadData::first(); |
| 79 ASSERT_TRUE(data); | 82 ASSERT_TRUE(data); |
| 80 EXPECT_TRUE(!data->next()); | 83 EXPECT_TRUE(!data->next()); |
| 81 EXPECT_EQ(data, ThreadData::Get()); | 84 EXPECT_EQ(data, ThreadData::Get()); |
| 82 ThreadData::BirthMap birth_map; | 85 ThreadData::BirthMap birth_map; |
| 83 ThreadData::DeathMap death_map; | 86 ThreadData::DeathMap death_map; |
| 84 data->SnapshotMaps(false, &birth_map, &death_map); | 87 ThreadData::ParentChildSet parent_child_set; |
| 88 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 85 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 89 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 86 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 90 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 87 EXPECT_EQ(0u, death_map.size()); // No deaths. | 91 EXPECT_EQ(0u, death_map.size()); // No deaths. |
| 92 EXPECT_EQ(0u, parent_child_set.size()); // No children. |
| 88 | 93 |
| 89 | 94 |
| 90 // Now instigate another birth, and a first death at the same location. | 95 // Now instigate another birth, while we are timing the run of the first |
| 96 // execution. |
| 97 TrackedTime start_time = |
| 98 ThreadData::NowForStartOfRun(first_birth); |
| 99 // Create a child (using the same birth location). |
| 91 // TrackingInfo will call TallyABirth() during construction. | 100 // TrackingInfo will call TallyABirth() during construction. |
| 92 base::TimeTicks kBogusStartTime; | 101 base::TimeTicks kBogusBirthTime; |
| 93 base::TrackingInfo pending_task(location, kBogusStartTime); | 102 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 94 TrackedTime kBogusStartRunTime; | 103 // Finally conclude the outer run. |
| 95 TrackedTime kBogusEndRunTime; | 104 TrackedTime end_time = ThreadData::NowForEndOfRun(); |
| 96 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, kBogusStartRunTime, | 105 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, start_time, |
| 97 kBogusEndRunTime); | 106 end_time); |
| 98 | 107 |
| 99 birth_map.clear(); | 108 birth_map.clear(); |
| 100 death_map.clear(); | 109 death_map.clear(); |
| 101 data->SnapshotMaps(false, &birth_map, &death_map); | 110 parent_child_set.clear(); |
| 111 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 102 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 112 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 103 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 113 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 104 EXPECT_EQ(1u, death_map.size()); // 1 location. | 114 EXPECT_EQ(1u, death_map.size()); // 1 location. |
| 105 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. | 115 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. |
| 116 if (ThreadData::tracking_parent_child_status()) { |
| 117 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 118 EXPECT_EQ(parent_child_set.begin()->first, |
| 119 parent_child_set.begin()->second); |
| 120 } else { |
| 121 EXPECT_EQ(0u, parent_child_set.size()); // no stats. |
| 122 } |
| 106 | 123 |
| 107 // The births were at the same location as the one known death. | 124 // The births were at the same location as the one known death. |
| 108 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); | 125 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); |
| 109 } | 126 } |
| 110 | 127 |
| 128 TEST_F(TrackedObjectsTest, ParentChildTest) { |
| 129 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
| 130 return; |
| 131 if (!ThreadData::tracking_parent_child_status()) |
| 132 return; // Feature not compiled in. |
| 133 |
| 134 // Instigate tracking on a single tracked object, on our thread. |
| 135 const int kFakeLineNumber = 1776; |
| 136 const char* kFile = "FixedUnitTestFileName"; |
| 137 const char* kFunction = "ParentChildTest"; |
| 138 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 139 Births* first_birth = ThreadData::TallyABirthIfActive(location); |
| 140 |
| 141 // Now instigate another birth, while we are timing the run of the first |
| 142 // execution. |
| 143 TrackedTime start_time = |
| 144 ThreadData::NowForStartOfRun(first_birth); |
| 145 // Create a child (using the same birth location). |
| 146 // TrackingInfo will call TallyABirth() during construction. |
| 147 base::TimeTicks kBogusBirthTime; |
| 148 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 149 |
| 150 // Don't conclude the run, so that we don't use the actual timer that we |
| 151 // started for the outer profile. This way the JSON will not include some |
| 152 // random time. |
| 153 ThreadData* data = ThreadData::first(); |
| 154 ASSERT_TRUE(data); |
| 155 EXPECT_TRUE(!data->next()); |
| 156 EXPECT_EQ(data, ThreadData::Get()); |
| 157 |
| 158 ThreadData::BirthMap birth_map; |
| 159 ThreadData::DeathMap death_map; |
| 160 ThreadData::ParentChildSet parent_child_set; |
| 161 |
| 162 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 163 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 164 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 165 EXPECT_EQ(0u, death_map.size()); // No status yet. |
| 166 // Just like TinyStartupShutdown test. |
| 167 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 168 EXPECT_EQ(parent_child_set.begin()->first, |
| 169 parent_child_set.begin()->second); |
| 170 |
| 171 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 172 std::string json; |
| 173 base::JSONWriter::Write(value.get(), false, &json); |
| 174 std::string birth_only_result = "{" |
| 175 "\"descendants\":[" |
| 176 "{" |
| 177 "\"child_location\":{" |
| 178 "\"file_name\":\"FixedUnitTestFileName\"," |
| 179 "\"function_name\":\"ParentChildTest\"," |
| 180 "\"line_number\":1776" |
| 181 "}," |
| 182 "\"child_thread\":\"WorkerThread-1\"," |
| 183 "\"parent_location\":{" |
| 184 "\"file_name\":\"FixedUnitTestFileName\"," |
| 185 "\"function_name\":\"ParentChildTest\"," |
| 186 "\"line_number\":1776" |
| 187 "}," |
| 188 "\"parent_thread\":\"WorkerThread-1\"" |
| 189 "}" |
| 190 "]," |
| 191 "\"list\":[" |
| 192 "{" |
| 193 "\"birth_thread\":\"WorkerThread-1\"," |
| 194 "\"death_data\":{" |
| 195 "\"count\":2," |
| 196 "\"queue_ms\":0," |
| 197 "\"queue_ms_max\":0," |
| 198 "\"queue_ms_sample\":0," |
| 199 "\"run_ms\":0," |
| 200 "\"run_ms_max\":0," |
| 201 "\"run_ms_sample\":0" |
| 202 "}," |
| 203 "\"death_thread\":\"Still_Alive\"," |
| 204 "\"location\":{" |
| 205 "\"file_name\":\"FixedUnitTestFileName\"," |
| 206 "\"function_name\":\"ParentChildTest\"," |
| 207 "\"line_number\":1776" |
| 208 "}" |
| 209 "}" |
| 210 "]" |
| 211 "}"; |
| 212 EXPECT_EQ(json, birth_only_result); |
| 213 } |
| 214 |
| 111 TEST_F(TrackedObjectsTest, DeathDataTest) { | 215 TEST_F(TrackedObjectsTest, DeathDataTest) { |
| 112 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 216 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
| 113 return; | 217 return; |
| 114 | 218 |
| 115 scoped_ptr<DeathData> data(new DeathData()); | 219 scoped_ptr<DeathData> data(new DeathData()); |
| 116 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); | 220 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); |
| 117 EXPECT_EQ(data->run_duration_sum(), 0); | 221 EXPECT_EQ(data->run_duration_sum(), 0); |
| 118 EXPECT_EQ(data->run_duration_sample(), 0); | 222 EXPECT_EQ(data->run_duration_sample(), 0); |
| 119 EXPECT_EQ(data->queue_duration_sum(), 0); | 223 EXPECT_EQ(data->queue_duration_sum(), 0); |
| 120 EXPECT_EQ(data->queue_duration_sample(), 0); | 224 EXPECT_EQ(data->queue_duration_sample(), 0); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 281 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
| 178 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 282 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 179 Births* birth = ThreadData::TallyABirthIfActive(location); | 283 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 180 // We should now see a NULL birth record. | 284 // We should now see a NULL birth record. |
| 181 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 285 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
| 182 | 286 |
| 183 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 287 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 184 std::string json; | 288 std::string json; |
| 185 base::JSONWriter::Write(value.get(), false, &json); | 289 base::JSONWriter::Write(value.get(), false, &json); |
| 186 std::string birth_only_result = "{" | 290 std::string birth_only_result = "{" |
| 291 "\"descendants\":[" |
| 292 "]," |
| 187 "\"list\":[" | 293 "\"list\":[" |
| 188 "]" | 294 "]" |
| 189 "}"; | 295 "}"; |
| 190 EXPECT_EQ(json, birth_only_result); | 296 EXPECT_EQ(json, birth_only_result); |
| 191 } | 297 } |
| 192 | 298 |
| 193 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { | 299 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { |
| 194 // Start in the deactivated state. | 300 // Start in the deactivated state. |
| 195 if (!ThreadData::InitializeAndSetTrackingStatus(false)) | 301 if (!ThreadData::InitializeAndSetTrackingStatus(false)) |
| 196 return; | 302 return; |
| 197 | 303 |
| 198 // Use a well named thread. | 304 // Use a well named thread. |
| 199 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 305 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
| 200 const int kFakeLineNumber = 173; | 306 const int kFakeLineNumber = 173; |
| 201 const char* kFile = "FixedFileName"; | 307 const char* kFile = "FixedFileName"; |
| 202 const char* kFunction = "BirthOnlyToValueMainThread"; | 308 const char* kFunction = "BirthOnlyToValueMainThread"; |
| 203 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 309 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 204 // Do not delete birth. We don't own it. | 310 // Do not delete birth. We don't own it. |
| 205 Births* birth = ThreadData::TallyABirthIfActive(location); | 311 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 206 // We expect to not get a birth record. | 312 // We expect to not get a birth record. |
| 207 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 313 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
| 208 | 314 |
| 209 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 315 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 210 std::string json; | 316 std::string json; |
| 211 base::JSONWriter::Write(value.get(), false, &json); | 317 base::JSONWriter::Write(value.get(), false, &json); |
| 212 std::string birth_only_result = "{" | 318 std::string birth_only_result = "{" |
| 319 "\"descendants\":[" |
| 320 "]," |
| 213 "\"list\":[" | 321 "\"list\":[" |
| 214 "]" | 322 "]" |
| 215 "}"; | 323 "}"; |
| 216 EXPECT_EQ(json, birth_only_result); | 324 EXPECT_EQ(json, birth_only_result); |
| 217 } | 325 } |
| 218 | 326 |
| 219 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { | 327 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { |
| 220 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 328 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
| 221 return; | 329 return; |
| 222 // We don't initialize system with a thread name, so we're viewed as a worker | 330 // We don't initialize system with a thread name, so we're viewed as a worker |
| 223 // thread. | 331 // thread. |
| 224 const int kFakeLineNumber = 173; | 332 const int kFakeLineNumber = 173; |
| 225 const char* kFile = "FixedFileName"; | 333 const char* kFile = "FixedFileName"; |
| 226 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 334 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
| 227 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 335 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 228 Births* birth = ThreadData::TallyABirthIfActive(location); | 336 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 229 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 337 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 230 | 338 |
| 231 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 339 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 232 std::string json; | 340 std::string json; |
| 233 base::JSONWriter::Write(value.get(), false, &json); | 341 base::JSONWriter::Write(value.get(), false, &json); |
| 234 std::string birth_only_result = "{" | 342 std::string birth_only_result = "{" |
| 343 "\"descendants\":[" |
| 344 "]," |
| 235 "\"list\":[" | 345 "\"list\":[" |
| 236 "{" | 346 "{" |
| 237 "\"birth_thread\":\"WorkerThread-1\"," | 347 "\"birth_thread\":\"WorkerThread-1\"," |
| 238 "\"death_data\":{" | 348 "\"death_data\":{" |
| 239 "\"count\":1," | 349 "\"count\":1," |
| 240 "\"queue_ms\":0," | 350 "\"queue_ms\":0," |
| 241 "\"queue_ms_max\":0," | 351 "\"queue_ms_max\":0," |
| 242 "\"queue_ms_sample\":0," | 352 "\"queue_ms_sample\":0," |
| 243 "\"run_ms\":0," | 353 "\"run_ms\":0," |
| 244 "\"run_ms_max\":0," | 354 "\"run_ms_max\":0," |
| (...skipping 22 matching lines...) Expand all Loading... |
| 267 const char* kFunction = "BirthOnlyToValueMainThread"; | 377 const char* kFunction = "BirthOnlyToValueMainThread"; |
| 268 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 378 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 269 // Do not delete birth. We don't own it. | 379 // Do not delete birth. We don't own it. |
| 270 Births* birth = ThreadData::TallyABirthIfActive(location); | 380 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 271 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 381 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 272 | 382 |
| 273 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 383 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 274 std::string json; | 384 std::string json; |
| 275 base::JSONWriter::Write(value.get(), false, &json); | 385 base::JSONWriter::Write(value.get(), false, &json); |
| 276 std::string birth_only_result = "{" | 386 std::string birth_only_result = "{" |
| 387 "\"descendants\":[" |
| 388 "]," |
| 277 "\"list\":[" | 389 "\"list\":[" |
| 278 "{" | 390 "{" |
| 279 "\"birth_thread\":\"SomeMainThreadName\"," | 391 "\"birth_thread\":\"SomeMainThreadName\"," |
| 280 "\"death_data\":{" | 392 "\"death_data\":{" |
| 281 "\"count\":1," | 393 "\"count\":1," |
| 282 "\"queue_ms\":0," | 394 "\"queue_ms\":0," |
| 283 "\"queue_ms_max\":0," | 395 "\"queue_ms_max\":0," |
| 284 "\"queue_ms_sample\":0," | 396 "\"queue_ms_sample\":0," |
| 285 "\"run_ms\":0," | 397 "\"run_ms\":0," |
| 286 "\"run_ms_max\":0," | 398 "\"run_ms_max\":0," |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 const TrackedTime kStartOfRun = TrackedTime() + | 434 const TrackedTime kStartOfRun = TrackedTime() + |
| 323 Duration::FromMilliseconds(5); | 435 Duration::FromMilliseconds(5); |
| 324 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 436 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 325 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 437 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 326 kStartOfRun, kEndOfRun); | 438 kStartOfRun, kEndOfRun); |
| 327 | 439 |
| 328 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 440 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 329 std::string json; | 441 std::string json; |
| 330 base::JSONWriter::Write(value.get(), false, &json); | 442 base::JSONWriter::Write(value.get(), false, &json); |
| 331 std::string one_line_result = "{" | 443 std::string one_line_result = "{" |
| 444 "\"descendants\":[" |
| 445 "]," |
| 332 "\"list\":[" | 446 "\"list\":[" |
| 333 "{" | 447 "{" |
| 334 "\"birth_thread\":\"SomeMainThreadName\"," | 448 "\"birth_thread\":\"SomeMainThreadName\"," |
| 335 "\"death_data\":{" | 449 "\"death_data\":{" |
| 336 "\"count\":1," | 450 "\"count\":1," |
| 337 "\"queue_ms\":4," | 451 "\"queue_ms\":4," |
| 338 "\"queue_ms_max\":4," | 452 "\"queue_ms_max\":4," |
| 339 "\"queue_ms_sample\":4," | 453 "\"queue_ms_sample\":4," |
| 340 "\"run_ms\":2," | 454 "\"run_ms\":2," |
| 341 "\"run_ms_max\":2," | 455 "\"run_ms_max\":2," |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 const TrackedTime kStartOfRun = TrackedTime() + | 498 const TrackedTime kStartOfRun = TrackedTime() + |
| 385 Duration::FromMilliseconds(5); | 499 Duration::FromMilliseconds(5); |
| 386 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 500 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 387 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 501 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 388 kStartOfRun, kEndOfRun); | 502 kStartOfRun, kEndOfRun); |
| 389 | 503 |
| 390 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 504 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 391 std::string json; | 505 std::string json; |
| 392 base::JSONWriter::Write(value.get(), false, &json); | 506 base::JSONWriter::Write(value.get(), false, &json); |
| 393 std::string one_line_result = "{" | 507 std::string one_line_result = "{" |
| 508 "\"descendants\":[" |
| 509 "]," |
| 394 "\"list\":[" | 510 "\"list\":[" |
| 395 "{" | 511 "{" |
| 396 "\"birth_thread\":\"SomeMainThreadName\"," | 512 "\"birth_thread\":\"SomeMainThreadName\"," |
| 397 "\"death_data\":{" | 513 "\"death_data\":{" |
| 398 "\"count\":1," | 514 "\"count\":1," |
| 399 "\"queue_ms\":4," | 515 "\"queue_ms\":4," |
| 400 "\"queue_ms_max\":4," | 516 "\"queue_ms_max\":4," |
| 401 "\"queue_ms_sample\":4," | 517 "\"queue_ms_sample\":4," |
| 402 "\"run_ms\":2," | 518 "\"run_ms\":2," |
| 403 "\"run_ms_max\":2," | 519 "\"run_ms_max\":2," |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 const TrackedTime kStartOfRun = TrackedTime() + | 557 const TrackedTime kStartOfRun = TrackedTime() + |
| 442 Duration::FromMilliseconds(5); | 558 Duration::FromMilliseconds(5); |
| 443 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 559 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 444 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 560 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 445 kStartOfRun, kEndOfRun); | 561 kStartOfRun, kEndOfRun); |
| 446 | 562 |
| 447 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 563 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 448 std::string json; | 564 std::string json; |
| 449 base::JSONWriter::Write(value.get(), false, &json); | 565 base::JSONWriter::Write(value.get(), false, &json); |
| 450 std::string one_line_result = "{" | 566 std::string one_line_result = "{" |
| 567 "\"descendants\":[" |
| 568 "]," |
| 451 "\"list\":[" | 569 "\"list\":[" |
| 452 "]" | 570 "]" |
| 453 "}"; | 571 "}"; |
| 454 EXPECT_EQ(one_line_result, json); | 572 EXPECT_EQ(one_line_result, json); |
| 455 } | 573 } |
| 456 | 574 |
| 457 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { | 575 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { |
| 458 if (!ThreadData::InitializeAndSetTrackingStatus(true)) | 576 if (!ThreadData::InitializeAndSetTrackingStatus(true)) |
| 459 return; | 577 return; |
| 460 | 578 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 474 Duration::FromMilliseconds(5); | 592 Duration::FromMilliseconds(5); |
| 475 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 593 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 476 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, | 594 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, |
| 477 kStartOfRun, kEndOfRun); | 595 kStartOfRun, kEndOfRun); |
| 478 | 596 |
| 479 // Call for the ToValue, but tell it to not the maxes after scanning. | 597 // Call for the ToValue, but tell it to not the maxes after scanning. |
| 480 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 598 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 481 std::string json; | 599 std::string json; |
| 482 base::JSONWriter::Write(value.get(), false, &json); | 600 base::JSONWriter::Write(value.get(), false, &json); |
| 483 std::string one_line_result = "{" | 601 std::string one_line_result = "{" |
| 602 "\"descendants\":[" |
| 603 "]," |
| 484 "\"list\":[" | 604 "\"list\":[" |
| 485 "{" | 605 "{" |
| 486 "\"birth_thread\":\"WorkerThread-1\"," | 606 "\"birth_thread\":\"WorkerThread-1\"," |
| 487 "\"death_data\":{" | 607 "\"death_data\":{" |
| 488 "\"count\":1," | 608 "\"count\":1," |
| 489 "\"queue_ms\":4," | 609 "\"queue_ms\":4," |
| 490 "\"queue_ms_max\":4," | 610 "\"queue_ms_max\":4," |
| 491 "\"queue_ms_sample\":4," | 611 "\"queue_ms_sample\":4," |
| 492 "\"run_ms\":2," | 612 "\"run_ms\":2," |
| 493 "\"run_ms_max\":2," | 613 "\"run_ms_max\":2," |
| (...skipping 16 matching lines...) Expand all Loading... |
| 510 value.reset(ThreadData::ToValue(true)); | 630 value.reset(ThreadData::ToValue(true)); |
| 511 base::JSONWriter::Write(value.get(), false, &json); | 631 base::JSONWriter::Write(value.get(), false, &json); |
| 512 // Result should be unchanged. | 632 // Result should be unchanged. |
| 513 EXPECT_EQ(one_line_result, json); | 633 EXPECT_EQ(one_line_result, json); |
| 514 | 634 |
| 515 // Call for the ToValue, and now we'll see the result of the last translation, | 635 // Call for the ToValue, and now we'll see the result of the last translation, |
| 516 // as the max will have been pushed back to zero. | 636 // as the max will have been pushed back to zero. |
| 517 value.reset(ThreadData::ToValue(false)); | 637 value.reset(ThreadData::ToValue(false)); |
| 518 base::JSONWriter::Write(value.get(), false, &json); | 638 base::JSONWriter::Write(value.get(), false, &json); |
| 519 std::string one_line_result_with_zeros = "{" | 639 std::string one_line_result_with_zeros = "{" |
| 640 "\"descendants\":[" |
| 641 "]," |
| 520 "\"list\":[" | 642 "\"list\":[" |
| 521 "{" | 643 "{" |
| 522 "\"birth_thread\":\"WorkerThread-1\"," | 644 "\"birth_thread\":\"WorkerThread-1\"," |
| 523 "\"death_data\":{" | 645 "\"death_data\":{" |
| 524 "\"count\":1," | 646 "\"count\":1," |
| 525 "\"queue_ms\":4," | 647 "\"queue_ms\":4," |
| 526 "\"queue_ms_max\":0," // Note zero here. | 648 "\"queue_ms_max\":0," // Note zero here. |
| 527 "\"queue_ms_sample\":4," | 649 "\"queue_ms_sample\":4," |
| 528 "\"run_ms\":2," | 650 "\"run_ms\":2," |
| 529 "\"run_ms_max\":0," // Note zero here. | 651 "\"run_ms_max\":0," // Note zero here. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 base::TrackingInfo pending_task2(location, kDelayedStartTime); | 695 base::TrackingInfo pending_task2(location, kDelayedStartTime); |
| 574 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 696 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 575 | 697 |
| 576 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, | 698 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, |
| 577 kStartOfRun, kEndOfRun); | 699 kStartOfRun, kEndOfRun); |
| 578 | 700 |
| 579 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 701 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 580 std::string json; | 702 std::string json; |
| 581 base::JSONWriter::Write(value.get(), false, &json); | 703 base::JSONWriter::Write(value.get(), false, &json); |
| 582 std::string one_line_result = "{" | 704 std::string one_line_result = "{" |
| 705 "\"descendants\":[" |
| 706 "]," |
| 583 "\"list\":[" | 707 "\"list\":[" |
| 584 "{" | 708 "{" |
| 585 "\"birth_thread\":\"SomeFileThreadName\"," | 709 "\"birth_thread\":\"SomeFileThreadName\"," |
| 586 "\"death_data\":{" | 710 "\"death_data\":{" |
| 587 "\"count\":2," | 711 "\"count\":2," |
| 588 "\"queue_ms\":8," | 712 "\"queue_ms\":8," |
| 589 "\"queue_ms_max\":4," | 713 "\"queue_ms_max\":4," |
| 590 "\"queue_ms_sample\":4," | 714 "\"queue_ms_sample\":4," |
| 591 "\"run_ms\":4," | 715 "\"run_ms\":4," |
| 592 "\"run_ms_max\":2," | 716 "\"run_ms_max\":2," |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 756 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 633 | 757 |
| 634 // TrackingInfo will call TallyABirth() during construction. | 758 // TrackingInfo will call TallyABirth() during construction. |
| 635 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 759 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 636 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 760 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 637 | 761 |
| 638 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 762 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); |
| 639 std::string json; | 763 std::string json; |
| 640 base::JSONWriter::Write(value.get(), false, &json); | 764 base::JSONWriter::Write(value.get(), false, &json); |
| 641 std::string one_line_result = "{" | 765 std::string one_line_result = "{" |
| 766 "\"descendants\":[" |
| 767 "]," |
| 642 "\"list\":[" | 768 "\"list\":[" |
| 643 "{" | 769 "{" |
| 644 "\"birth_thread\":\"SomeFileThreadName\"," | 770 "\"birth_thread\":\"SomeFileThreadName\"," |
| 645 "\"death_data\":{" | 771 "\"death_data\":{" |
| 646 "\"count\":1," | 772 "\"count\":1," |
| 647 "\"queue_ms\":4," | 773 "\"queue_ms\":4," |
| 648 "\"queue_ms_max\":4," | 774 "\"queue_ms_max\":4," |
| 649 "\"queue_ms_sample\":4," | 775 "\"queue_ms_sample\":4," |
| 650 "\"run_ms\":2," | 776 "\"run_ms\":2," |
| 651 "\"run_ms_max\":2," | 777 "\"run_ms_max\":2," |
| (...skipping 24 matching lines...) Expand all Loading... |
| 676 "\"line_number\":999" | 802 "\"line_number\":999" |
| 677 "}" | 803 "}" |
| 678 "}" | 804 "}" |
| 679 "]" | 805 "]" |
| 680 "}"; | 806 "}"; |
| 681 EXPECT_EQ(one_line_result, json); | 807 EXPECT_EQ(one_line_result, json); |
| 682 } | 808 } |
| 683 | 809 |
| 684 | 810 |
| 685 } // namespace tracked_objects | 811 } // namespace tracked_objects |
| OLD | NEW |