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