| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
| 11 #include "base/process_util.h" |
| 12 #include "base/string_number_conversions.h" |
| 11 #include "base/time.h" | 13 #include "base/time.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 15 |
| 16 namespace { |
| 17 |
| 18 std::string GetProcessIdString() { |
| 19 return base::IntToString(base::GetCurrentProcId()); |
| 20 } |
| 21 |
| 22 } // anonymous namespace |
| 23 |
| 14 namespace tracked_objects { | 24 namespace tracked_objects { |
| 15 | 25 |
| 16 class TrackedObjectsTest : public testing::Test { | 26 class TrackedObjectsTest : public testing::Test { |
| 17 protected: | 27 protected: |
| 18 TrackedObjectsTest() { | 28 TrackedObjectsTest() { |
| 19 // On entry, leak any database structures in case they are still in use by | 29 // On entry, leak any database structures in case they are still in use by |
| 20 // prior threads. | 30 // prior threads. |
| 21 ThreadData::ShutdownSingleThreadedCleanup(true); | 31 ThreadData::ShutdownSingleThreadedCleanup(true); |
| 22 } | 32 } |
| 23 | 33 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 173 |
| 164 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); | 174 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set); |
| 165 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 175 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 166 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 176 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| 167 EXPECT_EQ(0u, death_map.size()); // No status yet. | 177 EXPECT_EQ(0u, death_map.size()); // No status yet. |
| 168 // Just like TinyStartupShutdown test. | 178 // Just like TinyStartupShutdown test. |
| 169 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. | 179 EXPECT_EQ(1u, parent_child_set.size()); // 1 child. |
| 170 EXPECT_EQ(parent_child_set.begin()->first, | 180 EXPECT_EQ(parent_child_set.begin()->first, |
| 171 parent_child_set.begin()->second); | 181 parent_child_set.begin()->second); |
| 172 | 182 |
| 173 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 183 SerializedProcessData process_data; |
| 184 ThreadData::ToSerializedProcessData(false, &process_data); |
| 185 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 186 process_data.ToValue(value.get()); |
| 187 |
| 174 std::string json; | 188 std::string json; |
| 175 base::JSONWriter::Write(value.get(), false, &json); | 189 base::JSONWriter::Write(value.get(), false, &json); |
| 176 std::string birth_only_result = "{" | 190 std::string birth_only_result = "{" |
| 177 "\"descendants\":[" | 191 "\"descendants\":[" |
| 178 "{" | 192 "{" |
| 179 "\"child_location\":{" | 193 "\"child_location\":{" |
| 180 "\"file_name\":\"FixedUnitTestFileName\"," | 194 "\"file_name\":\"FixedUnitTestFileName\"," |
| 181 "\"function_name\":\"ParentChildTest\"," | 195 "\"function_name\":\"ParentChildTest\"," |
| 182 "\"line_number\":1776" | 196 "\"line_number\":1776" |
| 183 "}," | 197 "}," |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 252 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 239 EXPECT_EQ(data->count(), 1); | 253 EXPECT_EQ(data->count(), 1); |
| 240 | 254 |
| 241 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 255 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 242 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); | 256 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); |
| 243 EXPECT_EQ(data->run_duration_sample(), run_ms); | 257 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 244 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); | 258 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 245 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 259 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 246 EXPECT_EQ(data->count(), 2); | 260 EXPECT_EQ(data->count(), 2); |
| 247 | 261 |
| 248 scoped_ptr<base::DictionaryValue> dictionary(data->ToValue()); | 262 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 263 SerializedDeathData(*data).ToValue(dictionary.get()); |
| 249 int integer; | 264 int integer; |
| 250 EXPECT_TRUE(dictionary->GetInteger("run_ms", &integer)); | 265 EXPECT_TRUE(dictionary->GetInteger("run_ms", &integer)); |
| 251 EXPECT_EQ(integer, 2 * run_ms); | 266 EXPECT_EQ(integer, 2 * run_ms); |
| 252 EXPECT_TRUE(dictionary->GetInteger("run_ms_sample", &integer)); | 267 EXPECT_TRUE(dictionary->GetInteger("run_ms_sample", &integer)); |
| 253 EXPECT_EQ(integer, run_ms); | 268 EXPECT_EQ(integer, run_ms); |
| 254 EXPECT_TRUE(dictionary->GetInteger("queue_ms", &integer)); | 269 EXPECT_TRUE(dictionary->GetInteger("queue_ms", &integer)); |
| 255 EXPECT_EQ(integer, 2 * queue_ms); | 270 EXPECT_EQ(integer, 2 * queue_ms); |
| 256 EXPECT_TRUE(dictionary->GetInteger("queue_ms_sample", &integer)); | 271 EXPECT_TRUE(dictionary->GetInteger("queue_ms_sample", &integer)); |
| 257 EXPECT_EQ(integer, queue_ms); | 272 EXPECT_EQ(integer, queue_ms); |
| 258 EXPECT_TRUE(dictionary->GetInteger("count", &integer)); | 273 EXPECT_TRUE(dictionary->GetInteger("count", &integer)); |
| 259 EXPECT_EQ(integer, 2); | 274 EXPECT_EQ(integer, 2); |
| 260 | 275 |
| 261 scoped_ptr<base::Value> value(data->ToValue()); | 276 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 277 SerializedDeathData(*data).ToValue(value.get()); |
| 262 std::string json; | 278 std::string json; |
| 263 base::JSONWriter::Write(value.get(), false, &json); | 279 base::JSONWriter::Write(value.get(), false, &json); |
| 264 std::string birth_only_result = "{" | 280 std::string birth_only_result = "{" |
| 265 "\"count\":2," | 281 "\"count\":2," |
| 266 "\"queue_ms\":16," | 282 "\"queue_ms\":16," |
| 267 "\"queue_ms_max\":8," | 283 "\"queue_ms_max\":8," |
| 268 "\"queue_ms_sample\":8," | 284 "\"queue_ms_sample\":8," |
| 269 "\"run_ms\":84," | 285 "\"run_ms\":84," |
| 270 "\"run_ms_max\":42," | 286 "\"run_ms_max\":42," |
| 271 "\"run_ms_sample\":42" | 287 "\"run_ms_sample\":42" |
| 272 "}"; | 288 "}"; |
| 273 EXPECT_EQ(birth_only_result, json); | 289 EXPECT_EQ(birth_only_result, json); |
| 274 } | 290 } |
| 275 | 291 |
| 276 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueWorkerThread) { | 292 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueWorkerThread) { |
| 277 // Transition to Deactivated state before doing anything. | 293 // Transition to Deactivated state before doing anything. |
| 278 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 294 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
| 279 return; | 295 return; |
| 280 // We don't initialize system with a thread name, so we're viewed as a worker | 296 // We don't initialize system with a thread name, so we're viewed as a worker |
| 281 // thread. | 297 // thread. |
| 282 const int kFakeLineNumber = 173; | 298 const int kFakeLineNumber = 173; |
| 283 const char* kFile = "FixedFileName"; | 299 const char* kFile = "FixedFileName"; |
| 284 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 300 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
| 285 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 301 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 286 Births* birth = ThreadData::TallyABirthIfActive(location); | 302 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 287 // We should now see a NULL birth record. | 303 // We should now see a NULL birth record. |
| 288 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 304 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
| 289 | 305 |
| 290 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 306 SerializedProcessData process_data; |
| 307 ThreadData::ToSerializedProcessData(false, &process_data); |
| 308 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 309 process_data.ToValue(value.get()); |
| 310 |
| 291 std::string json; | 311 std::string json; |
| 292 base::JSONWriter::Write(value.get(), false, &json); | 312 base::JSONWriter::Write(value.get(), false, &json); |
| 293 std::string birth_only_result = "{" | 313 std::string birth_only_result = "{" |
| 294 "\"descendants\":[" | 314 "\"descendants\":[" |
| 295 "]," | 315 "]," |
| 296 "\"list\":[" | 316 "\"list\":[" |
| 297 "]" | 317 "]," |
| 318 "\"process_id\":" + GetProcessIdString() + |
| 298 "}"; | 319 "}"; |
| 299 EXPECT_EQ(json, birth_only_result); | 320 EXPECT_EQ(birth_only_result, json); |
| 300 } | 321 } |
| 301 | 322 |
| 302 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { | 323 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { |
| 303 // Start in the deactivated state. | 324 // Start in the deactivated state. |
| 304 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 325 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
| 305 return; | 326 return; |
| 306 | 327 |
| 307 // Use a well named thread. | 328 // Use a well named thread. |
| 308 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 329 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
| 309 const int kFakeLineNumber = 173; | 330 const int kFakeLineNumber = 173; |
| 310 const char* kFile = "FixedFileName"; | 331 const char* kFile = "FixedFileName"; |
| 311 const char* kFunction = "BirthOnlyToValueMainThread"; | 332 const char* kFunction = "BirthOnlyToValueMainThread"; |
| 312 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 333 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 313 // Do not delete birth. We don't own it. | 334 // Do not delete birth. We don't own it. |
| 314 Births* birth = ThreadData::TallyABirthIfActive(location); | 335 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 315 // We expect to not get a birth record. | 336 // We expect to not get a birth record. |
| 316 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); | 337 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); |
| 317 | 338 |
| 318 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 339 SerializedProcessData process_data; |
| 340 ThreadData::ToSerializedProcessData(false, &process_data); |
| 341 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 342 process_data.ToValue(value.get()); |
| 343 |
| 319 std::string json; | 344 std::string json; |
| 320 base::JSONWriter::Write(value.get(), false, &json); | 345 base::JSONWriter::Write(value.get(), false, &json); |
| 321 std::string birth_only_result = "{" | 346 std::string birth_only_result = "{" |
| 322 "\"descendants\":[" | 347 "\"descendants\":[" |
| 323 "]," | 348 "]," |
| 324 "\"list\":[" | 349 "\"list\":[" |
| 325 "]" | 350 "]," |
| 351 "\"process_id\":" + GetProcessIdString() + |
| 326 "}"; | 352 "}"; |
| 327 EXPECT_EQ(json, birth_only_result); | 353 EXPECT_EQ(birth_only_result, json); |
| 328 } | 354 } |
| 329 | 355 |
| 330 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { | 356 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { |
| 331 if (!ThreadData::InitializeAndSetTrackingStatus( | 357 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 332 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 358 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 333 return; | 359 return; |
| 334 // We don't initialize system with a thread name, so we're viewed as a worker | 360 // We don't initialize system with a thread name, so we're viewed as a worker |
| 335 // thread. | 361 // thread. |
| 336 const int kFakeLineNumber = 173; | 362 const int kFakeLineNumber = 173; |
| 337 const char* kFile = "FixedFileName"; | 363 const char* kFile = "FixedFileName"; |
| 338 const char* kFunction = "BirthOnlyToValueWorkerThread"; | 364 const char* kFunction = "BirthOnlyToValueWorkerThread"; |
| 339 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 365 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 340 Births* birth = ThreadData::TallyABirthIfActive(location); | 366 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 341 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 367 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 342 | 368 |
| 343 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 369 SerializedProcessData process_data; |
| 370 ThreadData::ToSerializedProcessData(false, &process_data); |
| 371 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 372 process_data.ToValue(value.get()); |
| 373 |
| 344 std::string json; | 374 std::string json; |
| 345 base::JSONWriter::Write(value.get(), false, &json); | 375 base::JSONWriter::Write(value.get(), false, &json); |
| 346 std::string birth_only_result = "{" | 376 std::string birth_only_result = "{" |
| 347 "\"descendants\":[" | 377 "\"descendants\":[" |
| 348 "]," | 378 "]," |
| 349 "\"list\":[" | 379 "\"list\":[" |
| 350 "{" | 380 "{" |
| 351 "\"birth_thread\":\"WorkerThread-1\"," | 381 "\"birth_thread\":\"WorkerThread-1\"," |
| 352 "\"death_data\":{" | 382 "\"death_data\":{" |
| 353 "\"count\":1," | 383 "\"count\":1," |
| 354 "\"queue_ms\":0," | 384 "\"queue_ms\":0," |
| 355 "\"queue_ms_max\":0," | 385 "\"queue_ms_max\":0," |
| 356 "\"queue_ms_sample\":0," | 386 "\"queue_ms_sample\":0," |
| 357 "\"run_ms\":0," | 387 "\"run_ms\":0," |
| 358 "\"run_ms_max\":0," | 388 "\"run_ms_max\":0," |
| 359 "\"run_ms_sample\":0" | 389 "\"run_ms_sample\":0" |
| 360 "}," | 390 "}," |
| 361 "\"death_thread\":\"Still_Alive\"," | 391 "\"death_thread\":\"Still_Alive\"," |
| 362 "\"location\":{" | 392 "\"location\":{" |
| 363 "\"file_name\":\"FixedFileName\"," | 393 "\"file_name\":\"FixedFileName\"," |
| 364 "\"function_name\":\"BirthOnlyToValueWorkerThread\"," | 394 "\"function_name\":\"BirthOnlyToValueWorkerThread\"," |
| 365 "\"line_number\":173" | 395 "\"line_number\":173" |
| 366 "}" | 396 "}" |
| 367 "}" | 397 "}" |
| 368 "]" | 398 "]," |
| 399 "\"process_id\":" + GetProcessIdString() + |
| 369 "}"; | 400 "}"; |
| 370 EXPECT_EQ(json, birth_only_result); | 401 EXPECT_EQ(birth_only_result, json); |
| 371 } | 402 } |
| 372 | 403 |
| 373 TEST_F(TrackedObjectsTest, BirthOnlyToValueMainThread) { | 404 TEST_F(TrackedObjectsTest, BirthOnlyToValueMainThread) { |
| 374 if (!ThreadData::InitializeAndSetTrackingStatus( | 405 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 375 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 406 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 376 return; | 407 return; |
| 377 | 408 |
| 378 // Use a well named thread. | 409 // Use a well named thread. |
| 379 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 410 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
| 380 const int kFakeLineNumber = 173; | 411 const int kFakeLineNumber = 173; |
| 381 const char* kFile = "FixedFileName"; | 412 const char* kFile = "FixedFileName"; |
| 382 const char* kFunction = "BirthOnlyToValueMainThread"; | 413 const char* kFunction = "BirthOnlyToValueMainThread"; |
| 383 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 414 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 384 // Do not delete birth. We don't own it. | 415 // Do not delete birth. We don't own it. |
| 385 Births* birth = ThreadData::TallyABirthIfActive(location); | 416 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 386 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 417 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 387 | 418 |
| 388 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 419 SerializedProcessData process_data; |
| 420 ThreadData::ToSerializedProcessData(false, &process_data); |
| 421 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 422 process_data.ToValue(value.get()); |
| 423 |
| 389 std::string json; | 424 std::string json; |
| 390 base::JSONWriter::Write(value.get(), false, &json); | 425 base::JSONWriter::Write(value.get(), false, &json); |
| 391 std::string birth_only_result = "{" | 426 std::string birth_only_result = "{" |
| 392 "\"descendants\":[" | 427 "\"descendants\":[" |
| 393 "]," | 428 "]," |
| 394 "\"list\":[" | 429 "\"list\":[" |
| 395 "{" | 430 "{" |
| 396 "\"birth_thread\":\"SomeMainThreadName\"," | 431 "\"birth_thread\":\"SomeMainThreadName\"," |
| 397 "\"death_data\":{" | 432 "\"death_data\":{" |
| 398 "\"count\":1," | 433 "\"count\":1," |
| 399 "\"queue_ms\":0," | 434 "\"queue_ms\":0," |
| 400 "\"queue_ms_max\":0," | 435 "\"queue_ms_max\":0," |
| 401 "\"queue_ms_sample\":0," | 436 "\"queue_ms_sample\":0," |
| 402 "\"run_ms\":0," | 437 "\"run_ms\":0," |
| 403 "\"run_ms_max\":0," | 438 "\"run_ms_max\":0," |
| 404 "\"run_ms_sample\":0" | 439 "\"run_ms_sample\":0" |
| 405 "}," | 440 "}," |
| 406 "\"death_thread\":\"Still_Alive\"," | 441 "\"death_thread\":\"Still_Alive\"," |
| 407 "\"location\":{" | 442 "\"location\":{" |
| 408 "\"file_name\":\"FixedFileName\"," | 443 "\"file_name\":\"FixedFileName\"," |
| 409 "\"function_name\":\"BirthOnlyToValueMainThread\"," | 444 "\"function_name\":\"BirthOnlyToValueMainThread\"," |
| 410 "\"line_number\":173" | 445 "\"line_number\":173" |
| 411 "}" | 446 "}" |
| 412 "}" | 447 "}" |
| 413 "]" | 448 "]," |
| 449 "\"process_id\":" + GetProcessIdString() + |
| 414 "}"; | 450 "}"; |
| 415 EXPECT_EQ(json, birth_only_result); | 451 EXPECT_EQ(birth_only_result, json); |
| 416 } | 452 } |
| 417 | 453 |
| 418 TEST_F(TrackedObjectsTest, LifeCycleToValueMainThread) { | 454 TEST_F(TrackedObjectsTest, LifeCycleToValueMainThread) { |
| 419 if (!ThreadData::InitializeAndSetTrackingStatus( | 455 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 420 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 456 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 421 return; | 457 return; |
| 422 | 458 |
| 423 // Use a well named thread. | 459 // Use a well named thread. |
| 424 ThreadData::InitializeThreadContext("SomeMainThreadName"); | 460 ThreadData::InitializeThreadContext("SomeMainThreadName"); |
| 425 const int kFakeLineNumber = 236; | 461 const int kFakeLineNumber = 236; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 436 // TrackingInfo will call TallyABirth() during construction. | 472 // TrackingInfo will call TallyABirth() during construction. |
| 437 base::TrackingInfo pending_task(location, kDelayedStartTime); | 473 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 438 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 474 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 439 | 475 |
| 440 const TrackedTime kStartOfRun = TrackedTime() + | 476 const TrackedTime kStartOfRun = TrackedTime() + |
| 441 Duration::FromMilliseconds(5); | 477 Duration::FromMilliseconds(5); |
| 442 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 478 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 443 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 479 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 444 kStartOfRun, kEndOfRun); | 480 kStartOfRun, kEndOfRun); |
| 445 | 481 |
| 446 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 482 SerializedProcessData process_data; |
| 483 ThreadData::ToSerializedProcessData(false, &process_data); |
| 484 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 485 process_data.ToValue(value.get()); |
| 486 |
| 447 std::string json; | 487 std::string json; |
| 448 base::JSONWriter::Write(value.get(), false, &json); | 488 base::JSONWriter::Write(value.get(), false, &json); |
| 449 std::string one_line_result = "{" | 489 std::string one_line_result = "{" |
| 450 "\"descendants\":[" | 490 "\"descendants\":[" |
| 451 "]," | 491 "]," |
| 452 "\"list\":[" | 492 "\"list\":[" |
| 453 "{" | 493 "{" |
| 454 "\"birth_thread\":\"SomeMainThreadName\"," | 494 "\"birth_thread\":\"SomeMainThreadName\"," |
| 455 "\"death_data\":{" | 495 "\"death_data\":{" |
| 456 "\"count\":1," | 496 "\"count\":1," |
| 457 "\"queue_ms\":4," | 497 "\"queue_ms\":4," |
| 458 "\"queue_ms_max\":4," | 498 "\"queue_ms_max\":4," |
| 459 "\"queue_ms_sample\":4," | 499 "\"queue_ms_sample\":4," |
| 460 "\"run_ms\":2," | 500 "\"run_ms\":2," |
| 461 "\"run_ms_max\":2," | 501 "\"run_ms_max\":2," |
| 462 "\"run_ms_sample\":2" | 502 "\"run_ms_sample\":2" |
| 463 "}," | 503 "}," |
| 464 "\"death_thread\":\"SomeMainThreadName\"," | 504 "\"death_thread\":\"SomeMainThreadName\"," |
| 465 "\"location\":{" | 505 "\"location\":{" |
| 466 "\"file_name\":\"FixedFileName\"," | 506 "\"file_name\":\"FixedFileName\"," |
| 467 "\"function_name\":\"LifeCycleToValueMainThread\"," | 507 "\"function_name\":\"LifeCycleToValueMainThread\"," |
| 468 "\"line_number\":236" | 508 "\"line_number\":236" |
| 469 "}" | 509 "}" |
| 470 "}" | 510 "}" |
| 471 "]" | 511 "]," |
| 512 "\"process_id\":" + GetProcessIdString() + |
| 472 "}"; | 513 "}"; |
| 473 EXPECT_EQ(one_line_result, json); | 514 EXPECT_EQ(one_line_result, json); |
| 474 } | 515 } |
| 475 | 516 |
| 476 // We will deactivate tracking after the birth, and before the death, and | 517 // We will deactivate tracking after the birth, and before the death, and |
| 477 // demonstrate that the lifecycle is completely tallied. This ensures that | 518 // demonstrate that the lifecycle is completely tallied. This ensures that |
| 478 // our tallied births are matched by tallied deaths (except for when the | 519 // our tallied births are matched by tallied deaths (except for when the |
| 479 // task is still running, or is queued). | 520 // task is still running, or is queued). |
| 480 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToValueMainThread) { | 521 TEST_F(TrackedObjectsTest, LifeCycleMidDeactivatedToValueMainThread) { |
| 481 if (!ThreadData::InitializeAndSetTrackingStatus( | 522 if (!ThreadData::InitializeAndSetTrackingStatus( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 502 // Turn off tracking now that we have births. | 543 // Turn off tracking now that we have births. |
| 503 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( | 544 EXPECT_TRUE(ThreadData::InitializeAndSetTrackingStatus( |
| 504 ThreadData::DEACTIVATED)); | 545 ThreadData::DEACTIVATED)); |
| 505 | 546 |
| 506 const TrackedTime kStartOfRun = TrackedTime() + | 547 const TrackedTime kStartOfRun = TrackedTime() + |
| 507 Duration::FromMilliseconds(5); | 548 Duration::FromMilliseconds(5); |
| 508 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 549 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 509 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 550 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 510 kStartOfRun, kEndOfRun); | 551 kStartOfRun, kEndOfRun); |
| 511 | 552 |
| 512 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 553 SerializedProcessData process_data; |
| 554 ThreadData::ToSerializedProcessData(false, &process_data); |
| 555 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 556 process_data.ToValue(value.get()); |
| 557 |
| 513 std::string json; | 558 std::string json; |
| 514 base::JSONWriter::Write(value.get(), false, &json); | 559 base::JSONWriter::Write(value.get(), false, &json); |
| 515 std::string one_line_result = "{" | 560 std::string one_line_result = "{" |
| 516 "\"descendants\":[" | 561 "\"descendants\":[" |
| 517 "]," | 562 "]," |
| 518 "\"list\":[" | 563 "\"list\":[" |
| 519 "{" | 564 "{" |
| 520 "\"birth_thread\":\"SomeMainThreadName\"," | 565 "\"birth_thread\":\"SomeMainThreadName\"," |
| 521 "\"death_data\":{" | 566 "\"death_data\":{" |
| 522 "\"count\":1," | 567 "\"count\":1," |
| 523 "\"queue_ms\":4," | 568 "\"queue_ms\":4," |
| 524 "\"queue_ms_max\":4," | 569 "\"queue_ms_max\":4," |
| 525 "\"queue_ms_sample\":4," | 570 "\"queue_ms_sample\":4," |
| 526 "\"run_ms\":2," | 571 "\"run_ms\":2," |
| 527 "\"run_ms_max\":2," | 572 "\"run_ms_max\":2," |
| 528 "\"run_ms_sample\":2" | 573 "\"run_ms_sample\":2" |
| 529 "}," | 574 "}," |
| 530 "\"death_thread\":\"SomeMainThreadName\"," | 575 "\"death_thread\":\"SomeMainThreadName\"," |
| 531 "\"location\":{" | 576 "\"location\":{" |
| 532 "\"file_name\":\"FixedFileName\"," | 577 "\"file_name\":\"FixedFileName\"," |
| 533 "\"function_name\":\"LifeCycleToValueMainThread\"," | 578 "\"function_name\":\"LifeCycleToValueMainThread\"," |
| 534 "\"line_number\":236" | 579 "\"line_number\":236" |
| 535 "}" | 580 "}" |
| 536 "}" | 581 "}" |
| 537 "]" | 582 "]," |
| 583 "\"process_id\":" + GetProcessIdString() + |
| 538 "}"; | 584 "}"; |
| 539 EXPECT_EQ(one_line_result, json); | 585 EXPECT_EQ(one_line_result, json); |
| 540 } | 586 } |
| 541 | 587 |
| 542 // We will deactivate tracking before starting a life cycle, and neither | 588 // We will deactivate tracking before starting a life cycle, and neither |
| 543 // the birth nor the death will be recorded. | 589 // the birth nor the death will be recorded. |
| 544 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToValueMainThread) { | 590 TEST_F(TrackedObjectsTest, LifeCyclePreDeactivatedToValueMainThread) { |
| 545 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) | 591 if (!ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED)) |
| 546 return; | 592 return; |
| 547 | 593 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 561 // TrackingInfo will call TallyABirth() during construction. | 607 // TrackingInfo will call TallyABirth() during construction. |
| 562 base::TrackingInfo pending_task(location, kDelayedStartTime); | 608 base::TrackingInfo pending_task(location, kDelayedStartTime); |
| 563 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). | 609 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). |
| 564 | 610 |
| 565 const TrackedTime kStartOfRun = TrackedTime() + | 611 const TrackedTime kStartOfRun = TrackedTime() + |
| 566 Duration::FromMilliseconds(5); | 612 Duration::FromMilliseconds(5); |
| 567 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 613 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 568 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 614 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 569 kStartOfRun, kEndOfRun); | 615 kStartOfRun, kEndOfRun); |
| 570 | 616 |
| 571 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 617 SerializedProcessData process_data; |
| 618 ThreadData::ToSerializedProcessData(false, &process_data); |
| 619 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 620 process_data.ToValue(value.get()); |
| 621 |
| 572 std::string json; | 622 std::string json; |
| 573 base::JSONWriter::Write(value.get(), false, &json); | 623 base::JSONWriter::Write(value.get(), false, &json); |
| 574 std::string one_line_result = "{" | 624 std::string one_line_result = "{" |
| 575 "\"descendants\":[" | 625 "\"descendants\":[" |
| 576 "]," | 626 "]," |
| 577 "\"list\":[" | 627 "\"list\":[" |
| 578 "]" | 628 "]," |
| 629 "\"process_id\":" + GetProcessIdString() + |
| 579 "}"; | 630 "}"; |
| 580 EXPECT_EQ(one_line_result, json); | 631 EXPECT_EQ(one_line_result, json); |
| 581 } | 632 } |
| 582 | 633 |
| 583 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { | 634 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { |
| 584 if (!ThreadData::InitializeAndSetTrackingStatus( | 635 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 585 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 636 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 586 return; | 637 return; |
| 587 | 638 |
| 588 // Don't initialize thread, so that we appear as a worker thread. | 639 // Don't initialize thread, so that we appear as a worker thread. |
| 589 // ThreadData::InitializeThreadContext("SomeMainThreadName"); | 640 // ThreadData::InitializeThreadContext("SomeMainThreadName"); |
| 590 | 641 |
| 591 const int kFakeLineNumber = 236; | 642 const int kFakeLineNumber = 236; |
| 592 const char* kFile = "FixedFileName"; | 643 const char* kFile = "FixedFileName"; |
| 593 const char* kFunction = "LifeCycleToValueWorkerThread"; | 644 const char* kFunction = "LifeCycleToValueWorkerThread"; |
| 594 Location location(kFunction, kFile, kFakeLineNumber, NULL); | 645 Location location(kFunction, kFile, kFakeLineNumber, NULL); |
| 595 // Do not delete birth. We don't own it. | 646 // Do not delete birth. We don't own it. |
| 596 Births* birth = ThreadData::TallyABirthIfActive(location); | 647 Births* birth = ThreadData::TallyABirthIfActive(location); |
| 597 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); | 648 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); |
| 598 | 649 |
| 599 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); | 650 const TrackedTime kTimePosted = TrackedTime() + Duration::FromMilliseconds(1); |
| 600 const TrackedTime kStartOfRun = TrackedTime() + | 651 const TrackedTime kStartOfRun = TrackedTime() + |
| 601 Duration::FromMilliseconds(5); | 652 Duration::FromMilliseconds(5); |
| 602 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); | 653 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); |
| 603 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, | 654 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, |
| 604 kStartOfRun, kEndOfRun); | 655 kStartOfRun, kEndOfRun); |
| 605 | 656 |
| 606 // Call for the ToValue, but tell it to not the maxes after scanning. | 657 // Call for the ToValue, but tell it to not the maxes after scanning. |
| 607 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 658 SerializedProcessData process_data; |
| 659 ThreadData::ToSerializedProcessData(false, &process_data); |
| 660 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 661 process_data.ToValue(value.get()); |
| 662 |
| 608 std::string json; | 663 std::string json; |
| 609 base::JSONWriter::Write(value.get(), false, &json); | 664 base::JSONWriter::Write(value.get(), false, &json); |
| 610 std::string one_line_result = "{" | 665 std::string one_line_result = "{" |
| 611 "\"descendants\":[" | 666 "\"descendants\":[" |
| 612 "]," | 667 "]," |
| 613 "\"list\":[" | 668 "\"list\":[" |
| 614 "{" | 669 "{" |
| 615 "\"birth_thread\":\"WorkerThread-1\"," | 670 "\"birth_thread\":\"WorkerThread-1\"," |
| 616 "\"death_data\":{" | 671 "\"death_data\":{" |
| 617 "\"count\":1," | 672 "\"count\":1," |
| 618 "\"queue_ms\":4," | 673 "\"queue_ms\":4," |
| 619 "\"queue_ms_max\":4," | 674 "\"queue_ms_max\":4," |
| 620 "\"queue_ms_sample\":4," | 675 "\"queue_ms_sample\":4," |
| 621 "\"run_ms\":2," | 676 "\"run_ms\":2," |
| 622 "\"run_ms_max\":2," | 677 "\"run_ms_max\":2," |
| 623 "\"run_ms_sample\":2" | 678 "\"run_ms_sample\":2" |
| 624 "}," | 679 "}," |
| 625 "\"death_thread\":\"WorkerThread-1\"," | 680 "\"death_thread\":\"WorkerThread-1\"," |
| 626 "\"location\":{" | 681 "\"location\":{" |
| 627 "\"file_name\":\"FixedFileName\"," | 682 "\"file_name\":\"FixedFileName\"," |
| 628 "\"function_name\":\"LifeCycleToValueWorkerThread\"," | 683 "\"function_name\":\"LifeCycleToValueWorkerThread\"," |
| 629 "\"line_number\":236" | 684 "\"line_number\":236" |
| 630 "}" | 685 "}" |
| 631 "}" | 686 "}" |
| 632 "]" | 687 "]," |
| 688 "\"process_id\":" + GetProcessIdString() + |
| 633 "}"; | 689 "}"; |
| 634 EXPECT_EQ(one_line_result, json); | 690 EXPECT_EQ(one_line_result, json); |
| 635 | 691 |
| 636 // Call for the ToValue, but tell it to reset the maxes after scanning. | 692 // Call for the ToValue, but tell it to reset the maxes after scanning. |
| 637 // We'll still get the same values, but the data will be reset (which we'll | 693 // We'll still get the same values, but the data will be reset (which we'll |
| 638 // see in a moment). | 694 // see in a moment). |
| 639 value.reset(ThreadData::ToValue(true)); | 695 SerializedProcessData process_data_pre_reset; |
| 696 ThreadData::ToSerializedProcessData(true, &process_data_pre_reset); |
| 697 value.reset(new base::DictionaryValue); |
| 698 process_data_pre_reset.ToValue(value.get()); |
| 699 |
| 640 base::JSONWriter::Write(value.get(), false, &json); | 700 base::JSONWriter::Write(value.get(), false, &json); |
| 641 // Result should be unchanged. | 701 // Result should be unchanged. |
| 642 EXPECT_EQ(one_line_result, json); | 702 EXPECT_EQ(one_line_result, json); |
| 643 | 703 |
| 644 // Call for the ToValue, and now we'll see the result of the last translation, | 704 // Call for the ToValue, and now we'll see the result of the last translation, |
| 645 // as the max will have been pushed back to zero. | 705 // as the max will have been pushed back to zero. |
| 646 value.reset(ThreadData::ToValue(false)); | 706 SerializedProcessData process_data_post_reset; |
| 707 ThreadData::ToSerializedProcessData(true, &process_data_post_reset); |
| 708 value.reset(new base::DictionaryValue); |
| 709 process_data_post_reset.ToValue(value.get()); |
| 710 |
| 647 base::JSONWriter::Write(value.get(), false, &json); | 711 base::JSONWriter::Write(value.get(), false, &json); |
| 648 std::string one_line_result_with_zeros = "{" | 712 std::string one_line_result_with_zeros = "{" |
| 649 "\"descendants\":[" | 713 "\"descendants\":[" |
| 650 "]," | 714 "]," |
| 651 "\"list\":[" | 715 "\"list\":[" |
| 652 "{" | 716 "{" |
| 653 "\"birth_thread\":\"WorkerThread-1\"," | 717 "\"birth_thread\":\"WorkerThread-1\"," |
| 654 "\"death_data\":{" | 718 "\"death_data\":{" |
| 655 "\"count\":1," | 719 "\"count\":1," |
| 656 "\"queue_ms\":4," | 720 "\"queue_ms\":4," |
| 657 "\"queue_ms_max\":0," // Note zero here. | 721 "\"queue_ms_max\":0," // Note zero here. |
| 658 "\"queue_ms_sample\":4," | 722 "\"queue_ms_sample\":4," |
| 659 "\"run_ms\":2," | 723 "\"run_ms\":2," |
| 660 "\"run_ms_max\":0," // Note zero here. | 724 "\"run_ms_max\":0," // Note zero here. |
| 661 "\"run_ms_sample\":2" | 725 "\"run_ms_sample\":2" |
| 662 "}," | 726 "}," |
| 663 "\"death_thread\":\"WorkerThread-1\"," | 727 "\"death_thread\":\"WorkerThread-1\"," |
| 664 "\"location\":{" | 728 "\"location\":{" |
| 665 "\"file_name\":\"FixedFileName\"," | 729 "\"file_name\":\"FixedFileName\"," |
| 666 "\"function_name\":\"LifeCycleToValueWorkerThread\"," | 730 "\"function_name\":\"LifeCycleToValueWorkerThread\"," |
| 667 "\"line_number\":236" | 731 "\"line_number\":236" |
| 668 "}" | 732 "}" |
| 669 "}" | 733 "}" |
| 670 "]" | 734 "]," |
| 735 "\"process_id\":" + GetProcessIdString() + |
| 671 "}"; | 736 "}"; |
| 672 EXPECT_EQ(one_line_result_with_zeros, json); | 737 EXPECT_EQ(one_line_result_with_zeros, json); |
| 673 } | 738 } |
| 674 | 739 |
| 675 TEST_F(TrackedObjectsTest, TwoLives) { | 740 TEST_F(TrackedObjectsTest, TwoLives) { |
| 676 if (!ThreadData::InitializeAndSetTrackingStatus( | 741 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 677 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 742 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 678 return; | 743 return; |
| 679 | 744 |
| 680 // Use a well named thread. | 745 // Use a well named thread. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 701 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 766 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 702 kStartOfRun, kEndOfRun); | 767 kStartOfRun, kEndOfRun); |
| 703 | 768 |
| 704 // TrackingInfo will call TallyABirth() during construction. | 769 // TrackingInfo will call TallyABirth() during construction. |
| 705 base::TrackingInfo pending_task2(location, kDelayedStartTime); | 770 base::TrackingInfo pending_task2(location, kDelayedStartTime); |
| 706 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 771 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 707 | 772 |
| 708 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, | 773 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, |
| 709 kStartOfRun, kEndOfRun); | 774 kStartOfRun, kEndOfRun); |
| 710 | 775 |
| 711 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 776 SerializedProcessData process_data; |
| 777 ThreadData::ToSerializedProcessData(false, &process_data); |
| 778 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 779 process_data.ToValue(value.get()); |
| 780 |
| 712 std::string json; | 781 std::string json; |
| 713 base::JSONWriter::Write(value.get(), false, &json); | 782 base::JSONWriter::Write(value.get(), false, &json); |
| 714 std::string one_line_result = "{" | 783 std::string one_line_result = "{" |
| 715 "\"descendants\":[" | 784 "\"descendants\":[" |
| 716 "]," | 785 "]," |
| 717 "\"list\":[" | 786 "\"list\":[" |
| 718 "{" | 787 "{" |
| 719 "\"birth_thread\":\"SomeFileThreadName\"," | 788 "\"birth_thread\":\"SomeFileThreadName\"," |
| 720 "\"death_data\":{" | 789 "\"death_data\":{" |
| 721 "\"count\":2," | 790 "\"count\":2," |
| 722 "\"queue_ms\":8," | 791 "\"queue_ms\":8," |
| 723 "\"queue_ms_max\":4," | 792 "\"queue_ms_max\":4," |
| 724 "\"queue_ms_sample\":4," | 793 "\"queue_ms_sample\":4," |
| 725 "\"run_ms\":4," | 794 "\"run_ms\":4," |
| 726 "\"run_ms_max\":2," | 795 "\"run_ms_max\":2," |
| 727 "\"run_ms_sample\":2" | 796 "\"run_ms_sample\":2" |
| 728 "}," | 797 "}," |
| 729 "\"death_thread\":\"SomeFileThreadName\"," | 798 "\"death_thread\":\"SomeFileThreadName\"," |
| 730 "\"location\":{" | 799 "\"location\":{" |
| 731 "\"file_name\":\"AnotherFileName\"," | 800 "\"file_name\":\"AnotherFileName\"," |
| 732 "\"function_name\":\"TwoLives\"," | 801 "\"function_name\":\"TwoLives\"," |
| 733 "\"line_number\":222" | 802 "\"line_number\":222" |
| 734 "}" | 803 "}" |
| 735 "}" | 804 "}" |
| 736 "]" | 805 "]," |
| 806 "\"process_id\":" + GetProcessIdString() + |
| 737 "}"; | 807 "}"; |
| 738 EXPECT_EQ(one_line_result, json); | 808 EXPECT_EQ(one_line_result, json); |
| 739 } | 809 } |
| 740 | 810 |
| 741 TEST_F(TrackedObjectsTest, DifferentLives) { | 811 TEST_F(TrackedObjectsTest, DifferentLives) { |
| 742 if (!ThreadData::InitializeAndSetTrackingStatus( | 812 if (!ThreadData::InitializeAndSetTrackingStatus( |
| 743 ThreadData::PROFILING_CHILDREN_ACTIVE)) | 813 ThreadData::PROFILING_CHILDREN_ACTIVE)) |
| 744 return; | 814 return; |
| 745 | 815 |
| 746 // Use a well named thread. | 816 // Use a well named thread. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 763 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, | 833 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, |
| 764 kStartOfRun, kEndOfRun); | 834 kStartOfRun, kEndOfRun); |
| 765 | 835 |
| 766 const int kSecondFakeLineNumber = 999; | 836 const int kSecondFakeLineNumber = 999; |
| 767 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); | 837 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); |
| 768 | 838 |
| 769 // TrackingInfo will call TallyABirth() during construction. | 839 // TrackingInfo will call TallyABirth() during construction. |
| 770 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); | 840 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); |
| 771 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). | 841 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). |
| 772 | 842 |
| 773 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); | 843 SerializedProcessData process_data; |
| 844 ThreadData::ToSerializedProcessData(false, &process_data); |
| 845 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 846 process_data.ToValue(value.get()); |
| 847 |
| 774 std::string json; | 848 std::string json; |
| 775 base::JSONWriter::Write(value.get(), false, &json); | 849 base::JSONWriter::Write(value.get(), false, &json); |
| 776 std::string one_line_result = "{" | 850 std::string one_line_result = "{" |
| 777 "\"descendants\":[" | 851 "\"descendants\":[" |
| 778 "]," | 852 "]," |
| 779 "\"list\":[" | 853 "\"list\":[" |
| 780 "{" | 854 "{" |
| 781 "\"birth_thread\":\"SomeFileThreadName\"," | 855 "\"birth_thread\":\"SomeFileThreadName\"," |
| 782 "\"death_data\":{" | 856 "\"death_data\":{" |
| 783 "\"count\":1," | 857 "\"count\":1," |
| (...skipping 22 matching lines...) Expand all Loading... |
| 806 "\"run_ms_max\":0," | 880 "\"run_ms_max\":0," |
| 807 "\"run_ms_sample\":0" | 881 "\"run_ms_sample\":0" |
| 808 "}," | 882 "}," |
| 809 "\"death_thread\":\"Still_Alive\"," | 883 "\"death_thread\":\"Still_Alive\"," |
| 810 "\"location\":{" | 884 "\"location\":{" |
| 811 "\"file_name\":\"AnotherFileName\"," | 885 "\"file_name\":\"AnotherFileName\"," |
| 812 "\"function_name\":\"DifferentLives\"," | 886 "\"function_name\":\"DifferentLives\"," |
| 813 "\"line_number\":999" | 887 "\"line_number\":999" |
| 814 "}" | 888 "}" |
| 815 "}" | 889 "}" |
| 816 "]" | 890 "]," |
| 891 "\"process_id\":" + GetProcessIdString() + |
| 817 "}"; | 892 "}"; |
| 818 EXPECT_EQ(one_line_result, json); | 893 EXPECT_EQ(one_line_result, json); |
| 819 } | 894 } |
| 820 | 895 |
| 821 | 896 |
| 822 } // namespace tracked_objects | 897 } // namespace tracked_objects |
| OLD | NEW |