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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 2386123003: Add heap allocator usage to task profiler. (Closed)
Patch Set: Figure out where the @#$%! corruption is coming from. Move heap tracking to TaskStopwatch." Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include <memory> 12 #include <memory>
13 13
14 #include "base/debug/scoped_thread_heap_usage.h"
14 #include "base/process/process_handle.h" 15 #include "base/process/process_handle.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "base/tracking_info.h" 17 #include "base/tracking_info.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 const int kLineNumber = 1776; 20 const int kLineNumber = 1776;
20 const char kFile[] = "FixedUnitTestFileName"; 21 const char kFile[] = "FixedUnitTestFileName";
21 const char kWorkerThreadName[] = "WorkerThread-1"; 22 const char kWorkerThreadName[] = "WorkerThread-1";
22 const char kMainThreadName[] = "SomeMainThreadName"; 23 const char kMainThreadName[] = "SomeMainThreadName";
23 const char kStillAlive[] = "Still_Alive"; 24 const char kStillAlive[] = "Still_Alive";
24 25
26 const uint32_t kAllocOps = 23;
27 const uint32_t kFreeOps = 27;
28 const uint32_t kAllocatedBytes = 59934;
29 const uint32_t kFreedBytes = 2 * kAllocatedBytes;
30 const uint32_t kAllocOverheadBytes = kAllocOps * 8;
31 const uint32_t kMaxAllocatedBytes = kAllocatedBytes / 2;
32
25 namespace tracked_objects { 33 namespace tracked_objects {
26 34
27 class TrackedObjectsTest : public testing::Test { 35 class TrackedObjectsTest : public testing::Test {
28 protected: 36 protected:
29 TrackedObjectsTest() { 37 TrackedObjectsTest() {
30 // On entry, leak any database structures in case they are still in use by 38 // On entry, leak any database structures in case they are still in use by
31 // prior threads. 39 // prior threads.
32 ThreadData::ShutdownSingleThreadedCleanup(true); 40 ThreadData::ShutdownSingleThreadedCleanup(true);
33 41
34 test_time_ = 0; 42 test_time_ = 0;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 EXPECT_EQ(time_elapsed, 238 EXPECT_EQ(time_elapsed,
231 process_data_phase.tasks[0].death_data.run_duration_max); 239 process_data_phase.tasks[0].death_data.run_duration_max);
232 EXPECT_EQ(time_elapsed, 240 EXPECT_EQ(time_elapsed,
233 process_data_phase.tasks[0].death_data.run_duration_sample); 241 process_data_phase.tasks[0].death_data.run_duration_sample);
234 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum); 242 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sum);
235 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max); 243 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_max);
236 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample); 244 EXPECT_EQ(0, process_data_phase.tasks[0].death_data.queue_duration_sample);
237 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name); 245 EXPECT_EQ(kWorkerThreadName, process_data_phase.tasks[0].death_thread_name);
238 } 246 }
239 247
240 TEST_F(TrackedObjectsTest, DeathDataTestRecordDeath) { 248 TEST_F(TrackedObjectsTest, DeathDataTestRecordDurations) {
241 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); 249 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
242 250
243 std::unique_ptr<DeathData> data(new DeathData()); 251 std::unique_ptr<DeathData> data(new DeathData());
244 ASSERT_NE(data, nullptr); 252 ASSERT_NE(data, nullptr);
245 EXPECT_EQ(data->run_duration_sum(), 0); 253 EXPECT_EQ(data->run_duration_sum(), 0);
246 EXPECT_EQ(data->run_duration_max(), 0); 254 EXPECT_EQ(data->run_duration_max(), 0);
247 EXPECT_EQ(data->run_duration_sample(), 0); 255 EXPECT_EQ(data->run_duration_sample(), 0);
248 EXPECT_EQ(data->queue_duration_sum(), 0); 256 EXPECT_EQ(data->queue_duration_sum(), 0);
249 EXPECT_EQ(data->queue_duration_max(), 0); 257 EXPECT_EQ(data->queue_duration_max(), 0);
250 EXPECT_EQ(data->queue_duration_sample(), 0); 258 EXPECT_EQ(data->queue_duration_sample(), 0);
251 EXPECT_EQ(data->count(), 0); 259 EXPECT_EQ(data->count(), 0);
252 EXPECT_EQ(nullptr, data->last_phase_snapshot()); 260 EXPECT_EQ(nullptr, data->last_phase_snapshot());
253 261
254 int32_t run_ms = 42; 262 int32_t run_ms = 42;
255 int32_t queue_ms = 8; 263 int32_t queue_ms = 8;
256 264
257 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. 265 const int kUnrandomInt = 0; // Fake random int that ensure we sample data.
258 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); 266 data->RecordDurations(queue_ms, run_ms, kUnrandomInt);
259 EXPECT_EQ(data->run_duration_sum(), run_ms); 267 EXPECT_EQ(data->run_duration_sum(), run_ms);
260 EXPECT_EQ(data->run_duration_max(), run_ms); 268 EXPECT_EQ(data->run_duration_max(), run_ms);
261 EXPECT_EQ(data->run_duration_sample(), run_ms); 269 EXPECT_EQ(data->run_duration_sample(), run_ms);
262 EXPECT_EQ(data->queue_duration_sum(), queue_ms); 270 EXPECT_EQ(data->queue_duration_sum(), queue_ms);
263 EXPECT_EQ(data->queue_duration_max(), queue_ms); 271 EXPECT_EQ(data->queue_duration_max(), queue_ms);
264 EXPECT_EQ(data->queue_duration_sample(), queue_ms); 272 EXPECT_EQ(data->queue_duration_sample(), queue_ms);
265 EXPECT_EQ(data->count(), 1); 273 EXPECT_EQ(data->count(), 1);
266 EXPECT_EQ(nullptr, data->last_phase_snapshot()); 274 EXPECT_EQ(nullptr, data->last_phase_snapshot());
267 275
268 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); 276 data->RecordDurations(queue_ms, run_ms, kUnrandomInt);
269 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); 277 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms);
270 EXPECT_EQ(data->run_duration_max(), run_ms); 278 EXPECT_EQ(data->run_duration_max(), run_ms);
271 EXPECT_EQ(data->run_duration_sample(), run_ms); 279 EXPECT_EQ(data->run_duration_sample(), run_ms);
272 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); 280 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms);
273 EXPECT_EQ(data->queue_duration_max(), queue_ms); 281 EXPECT_EQ(data->queue_duration_max(), queue_ms);
274 EXPECT_EQ(data->queue_duration_sample(), queue_ms); 282 EXPECT_EQ(data->queue_duration_sample(), queue_ms);
275 EXPECT_EQ(data->count(), 2); 283 EXPECT_EQ(data->count(), 2);
276 EXPECT_EQ(nullptr, data->last_phase_snapshot()); 284 EXPECT_EQ(nullptr, data->last_phase_snapshot());
277 } 285 }
278 286
287 TEST_F(TrackedObjectsTest, DeathDataTestRecordAllocations) {
288 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
289
290 std::unique_ptr<DeathData> data(new DeathData());
291 ASSERT_NE(data, nullptr);
292
293 EXPECT_EQ(data->alloc_ops(), 0);
294 EXPECT_EQ(data->free_ops(), 0);
295 EXPECT_EQ(data->allocated_bytes(), 0);
296 EXPECT_EQ(data->freed_bytes(), 0);
297 EXPECT_EQ(data->alloc_overhead_bytes(), 0);
298 EXPECT_EQ(data->max_allocated_bytes(), 0);
299
300 EXPECT_EQ(nullptr, data->last_phase_snapshot());
301
302 data->RecordAllocations(kAllocOps, kFreeOps, kAllocatedBytes, kFreedBytes,
303 kAllocOverheadBytes, kMaxAllocatedBytes);
304 EXPECT_EQ(data->alloc_ops(), kAllocOps);
305 EXPECT_EQ(data->free_ops(), kFreeOps);
306 EXPECT_EQ(data->allocated_bytes(), kAllocatedBytes);
307 EXPECT_EQ(data->freed_bytes(), kFreedBytes);
308 EXPECT_EQ(data->alloc_overhead_bytes(), kAllocOverheadBytes);
309 EXPECT_EQ(data->max_allocated_bytes(), kMaxAllocatedBytes);
310
311 // Record another batch, with a smaller max.
312 const uint32_t kSmallerMaxAllocatedBytes = kMaxAllocatedBytes / 2;
313 data->RecordAllocations(kAllocOps, kFreeOps, kAllocatedBytes, kFreedBytes,
314 kAllocOverheadBytes, kSmallerMaxAllocatedBytes);
315 EXPECT_EQ(data->alloc_ops(), 2 * kAllocOps);
316 EXPECT_EQ(data->free_ops(), 2 * kFreeOps);
317 EXPECT_EQ(data->allocated_bytes(), 2 * kAllocatedBytes);
318 EXPECT_EQ(data->freed_bytes(), 2 * kFreedBytes);
319 EXPECT_EQ(data->alloc_overhead_bytes(), 2 * kAllocOverheadBytes);
320 EXPECT_EQ(data->max_allocated_bytes(), kMaxAllocatedBytes);
321
322 // Now with a larger max.
323 const uint32_t kLargerMaxAllocatedBytes = kMaxAllocatedBytes * 2;
324 data->RecordAllocations(kAllocOps, kFreeOps, kAllocatedBytes, kFreedBytes,
325 kAllocOverheadBytes, kLargerMaxAllocatedBytes);
326 EXPECT_EQ(data->alloc_ops(), 3 * kAllocOps);
327 EXPECT_EQ(data->free_ops(), 3 * kFreeOps);
328 EXPECT_EQ(data->allocated_bytes(), 3 * kAllocatedBytes);
329 EXPECT_EQ(data->freed_bytes(), 3 * kFreedBytes);
330 EXPECT_EQ(data->alloc_overhead_bytes(), 3 * kAllocOverheadBytes);
331 EXPECT_EQ(data->max_allocated_bytes(), kLargerMaxAllocatedBytes);
332
333 // Saturate everything.
334 data->RecordAllocations(INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX);
335 EXPECT_EQ(data->alloc_ops(), INT_MAX);
336 EXPECT_EQ(data->free_ops(), INT_MAX);
337 EXPECT_EQ(data->allocated_bytes(), INT_MAX);
338 EXPECT_EQ(data->freed_bytes(), INT_MAX);
339 EXPECT_EQ(data->alloc_overhead_bytes(), INT_MAX);
340 EXPECT_EQ(data->max_allocated_bytes(), INT_MAX);
341 }
342
279 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { 343 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) {
280 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); 344 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
281 345
282 std::unique_ptr<DeathData> data(new DeathData()); 346 std::unique_ptr<DeathData> data(new DeathData());
283 ASSERT_NE(data, nullptr); 347 ASSERT_NE(data, nullptr);
284 348
285 int32_t run_ms = 42; 349 const int32_t run_ms = 42;
286 int32_t queue_ms = 8; 350 const int32_t queue_ms = 8;
287 351
288 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. 352 const int kUnrandomInt = 0; // Fake random int that ensure we sample data.
289 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); 353 data->RecordDurations(queue_ms, run_ms, kUnrandomInt);
290 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); 354 data->RecordDurations(queue_ms, run_ms, kUnrandomInt);
355
356 data->RecordAllocations(kAllocOps, kFreeOps, kAllocatedBytes, kFreedBytes,
357 kAllocOverheadBytes, kMaxAllocatedBytes);
291 358
292 data->OnProfilingPhaseCompleted(123); 359 data->OnProfilingPhaseCompleted(123);
293 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); 360 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms);
294 EXPECT_EQ(data->run_duration_max(), 0); 361 EXPECT_EQ(data->run_duration_max(), 0);
295 EXPECT_EQ(data->run_duration_sample(), run_ms); 362 EXPECT_EQ(data->run_duration_sample(), run_ms);
296 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); 363 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms);
297 EXPECT_EQ(data->queue_duration_max(), 0); 364 EXPECT_EQ(data->queue_duration_max(), 0);
298 EXPECT_EQ(data->queue_duration_sample(), queue_ms); 365 EXPECT_EQ(data->queue_duration_sample(), queue_ms);
299 EXPECT_EQ(data->count(), 2); 366 EXPECT_EQ(data->count(), 2);
367
368 EXPECT_EQ(data->alloc_ops(), kAllocOps);
369 EXPECT_EQ(data->free_ops(), kFreeOps);
370 EXPECT_EQ(data->allocated_bytes(), kAllocatedBytes);
371 EXPECT_EQ(data->freed_bytes(), kFreedBytes);
372 EXPECT_EQ(data->alloc_overhead_bytes(), kAllocOverheadBytes);
373 EXPECT_EQ(data->max_allocated_bytes(), kMaxAllocatedBytes);
374
300 ASSERT_NE(nullptr, data->last_phase_snapshot()); 375 ASSERT_NE(nullptr, data->last_phase_snapshot());
301 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase); 376 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase);
302 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count); 377 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count);
303 EXPECT_EQ(2 * run_ms, 378 EXPECT_EQ(2 * run_ms,
304 data->last_phase_snapshot()->death_data.run_duration_sum); 379 data->last_phase_snapshot()->death_data.run_duration_sum);
305 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max); 380 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max);
306 EXPECT_EQ(run_ms, 381 EXPECT_EQ(run_ms,
307 data->last_phase_snapshot()->death_data.run_duration_sample); 382 data->last_phase_snapshot()->death_data.run_duration_sample);
308 EXPECT_EQ(2 * queue_ms, 383 EXPECT_EQ(2 * queue_ms,
309 data->last_phase_snapshot()->death_data.queue_duration_sum); 384 data->last_phase_snapshot()->death_data.queue_duration_sum);
310 EXPECT_EQ(queue_ms, 385 EXPECT_EQ(queue_ms,
311 data->last_phase_snapshot()->death_data.queue_duration_max); 386 data->last_phase_snapshot()->death_data.queue_duration_max);
312 EXPECT_EQ(queue_ms, 387 EXPECT_EQ(queue_ms,
313 data->last_phase_snapshot()->death_data.queue_duration_sample); 388 data->last_phase_snapshot()->death_data.queue_duration_sample);
389
390 EXPECT_EQ(kAllocOps, data->last_phase_snapshot()->death_data.alloc_ops);
391 EXPECT_EQ(kFreeOps, data->last_phase_snapshot()->death_data.free_ops);
392 EXPECT_EQ(kAllocatedBytes,
393 data->last_phase_snapshot()->death_data.allocated_bytes);
394 EXPECT_EQ(kFreedBytes, data->last_phase_snapshot()->death_data.freed_bytes);
395 EXPECT_EQ(kAllocOverheadBytes,
396 data->last_phase_snapshot()->death_data.alloc_overhead_bytes);
397 EXPECT_EQ(kMaxAllocatedBytes,
398 data->last_phase_snapshot()->death_data.max_allocated_bytes);
399
314 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); 400 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev);
315 401
316 int32_t run_ms1 = 21; 402 const int32_t run_ms1 = 21;
317 int32_t queue_ms1 = 4; 403 const int32_t queue_ms1 = 4;
318 404
319 data->RecordDeath(queue_ms1, run_ms1, kUnrandomInt); 405 data->RecordDurations(queue_ms1, run_ms1, kUnrandomInt);
406 data->RecordAllocations(kAllocOps, kFreeOps, kAllocatedBytes, kFreedBytes,
407 kAllocOverheadBytes, kMaxAllocatedBytes);
408
320 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms + run_ms1); 409 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms + run_ms1);
321 EXPECT_EQ(data->run_duration_max(), run_ms1); 410 EXPECT_EQ(data->run_duration_max(), run_ms1);
322 EXPECT_EQ(data->run_duration_sample(), run_ms1); 411 EXPECT_EQ(data->run_duration_sample(), run_ms1);
323 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms + queue_ms1); 412 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms + queue_ms1);
324 EXPECT_EQ(data->queue_duration_max(), queue_ms1); 413 EXPECT_EQ(data->queue_duration_max(), queue_ms1);
325 EXPECT_EQ(data->queue_duration_sample(), queue_ms1); 414 EXPECT_EQ(data->queue_duration_sample(), queue_ms1);
326 EXPECT_EQ(data->count(), 3); 415 EXPECT_EQ(data->count(), 3);
416
417 EXPECT_EQ(data->alloc_ops(), 2 * kAllocOps);
418 EXPECT_EQ(data->free_ops(), 2 * kFreeOps);
419 EXPECT_EQ(data->allocated_bytes(), 2 * kAllocatedBytes);
420 EXPECT_EQ(data->freed_bytes(), 2 * kFreedBytes);
421 EXPECT_EQ(data->alloc_overhead_bytes(), 2 * kAllocOverheadBytes);
422 EXPECT_EQ(data->max_allocated_bytes(), kMaxAllocatedBytes);
423
327 ASSERT_NE(nullptr, data->last_phase_snapshot()); 424 ASSERT_NE(nullptr, data->last_phase_snapshot());
328 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase); 425 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase);
329 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count); 426 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count);
330 EXPECT_EQ(2 * run_ms, 427 EXPECT_EQ(2 * run_ms,
331 data->last_phase_snapshot()->death_data.run_duration_sum); 428 data->last_phase_snapshot()->death_data.run_duration_sum);
332 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max); 429 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max);
333 EXPECT_EQ(run_ms, 430 EXPECT_EQ(run_ms,
334 data->last_phase_snapshot()->death_data.run_duration_sample); 431 data->last_phase_snapshot()->death_data.run_duration_sample);
335 EXPECT_EQ(2 * queue_ms, 432 EXPECT_EQ(2 * queue_ms,
336 data->last_phase_snapshot()->death_data.queue_duration_sum); 433 data->last_phase_snapshot()->death_data.queue_duration_sum);
337 EXPECT_EQ(queue_ms, 434 EXPECT_EQ(queue_ms,
338 data->last_phase_snapshot()->death_data.queue_duration_max); 435 data->last_phase_snapshot()->death_data.queue_duration_max);
339 EXPECT_EQ(queue_ms, 436 EXPECT_EQ(queue_ms,
340 data->last_phase_snapshot()->death_data.queue_duration_sample); 437 data->last_phase_snapshot()->death_data.queue_duration_sample);
438
439 EXPECT_EQ(kAllocOps, data->last_phase_snapshot()->death_data.alloc_ops);
440 EXPECT_EQ(kFreeOps, data->last_phase_snapshot()->death_data.free_ops);
441 EXPECT_EQ(kAllocatedBytes,
442 data->last_phase_snapshot()->death_data.allocated_bytes);
443 EXPECT_EQ(kFreedBytes, data->last_phase_snapshot()->death_data.freed_bytes);
444 EXPECT_EQ(kAllocOverheadBytes,
445 data->last_phase_snapshot()->death_data.alloc_overhead_bytes);
446 EXPECT_EQ(kMaxAllocatedBytes,
447 data->last_phase_snapshot()->death_data.max_allocated_bytes);
448
341 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); 449 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev);
342 } 450 }
343 451
344 TEST_F(TrackedObjectsTest, Delta) { 452 TEST_F(TrackedObjectsTest, Delta) {
345 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); 453 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE);
346 454
347 DeathDataSnapshot snapshot; 455 DeathDataSnapshot snapshot;
348 snapshot.count = 10; 456 snapshot.count = 10;
349 snapshot.run_duration_sum = 100; 457 snapshot.run_duration_sum = 100;
350 snapshot.run_duration_max = 50; 458 snapshot.run_duration_max = 50;
351 snapshot.run_duration_sample = 25; 459 snapshot.run_duration_sample = 25;
352 snapshot.queue_duration_sum = 200; 460 snapshot.queue_duration_sum = 200;
353 snapshot.queue_duration_max = 101; 461 snapshot.queue_duration_max = 101;
354 snapshot.queue_duration_sample = 26; 462 snapshot.queue_duration_sample = 26;
355 463
464 snapshot.alloc_ops = 95;
465 snapshot.free_ops = 90;
466 snapshot.allocated_bytes = 10240;
467 snapshot.freed_bytes = 4096;
468 snapshot.alloc_overhead_bytes = 950;
469 snapshot.max_allocated_bytes = 10240;
470
356 DeathDataSnapshot older_snapshot; 471 DeathDataSnapshot older_snapshot;
357 older_snapshot.count = 2; 472 older_snapshot.count = 2;
358 older_snapshot.run_duration_sum = 95; 473 older_snapshot.run_duration_sum = 95;
359 older_snapshot.run_duration_max = 48; 474 older_snapshot.run_duration_max = 48;
360 older_snapshot.run_duration_sample = 22; 475 older_snapshot.run_duration_sample = 22;
361 older_snapshot.queue_duration_sum = 190; 476 older_snapshot.queue_duration_sum = 190;
362 older_snapshot.queue_duration_max = 99; 477 older_snapshot.queue_duration_max = 99;
363 older_snapshot.queue_duration_sample = 21; 478 older_snapshot.queue_duration_sample = 21;
364 479
480 older_snapshot.alloc_ops = 45;
481 older_snapshot.free_ops = 40;
482 older_snapshot.allocated_bytes = 4096;
483 older_snapshot.freed_bytes = 2048;
484 older_snapshot.alloc_overhead_bytes = 450;
485 older_snapshot.max_allocated_bytes = 10200;
486
365 const DeathDataSnapshot& delta = snapshot.Delta(older_snapshot); 487 const DeathDataSnapshot& delta = snapshot.Delta(older_snapshot);
366 EXPECT_EQ(8, delta.count); 488 EXPECT_EQ(8, delta.count);
367 EXPECT_EQ(5, delta.run_duration_sum); 489 EXPECT_EQ(5, delta.run_duration_sum);
368 EXPECT_EQ(50, delta.run_duration_max); 490 EXPECT_EQ(50, delta.run_duration_max);
369 EXPECT_EQ(25, delta.run_duration_sample); 491 EXPECT_EQ(25, delta.run_duration_sample);
370 EXPECT_EQ(10, delta.queue_duration_sum); 492 EXPECT_EQ(10, delta.queue_duration_sum);
371 EXPECT_EQ(101, delta.queue_duration_max); 493 EXPECT_EQ(101, delta.queue_duration_max);
372 EXPECT_EQ(26, delta.queue_duration_sample); 494 EXPECT_EQ(26, delta.queue_duration_sample);
495
496 EXPECT_EQ(50, delta.alloc_ops);
497 EXPECT_EQ(50, delta.free_ops);
498 EXPECT_EQ(6144, delta.allocated_bytes);
499 EXPECT_EQ(2048, delta.freed_bytes);
500 EXPECT_EQ(500, delta.alloc_overhead_bytes);
501 EXPECT_EQ(10240, delta.max_allocated_bytes);
373 } 502 }
374 503
375 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) { 504 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToSnapshotWorkerThread) {
376 // Start in the deactivated state. 505 // Start in the deactivated state.
377 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED); 506 ThreadData::InitializeAndSetTrackingStatus(ThreadData::DEACTIVATED);
378 507
379 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread"; 508 const char kFunction[] = "DeactivatedBirthOnlyToSnapshotWorkerThread";
380 Location location(kFunction, kFile, kLineNumber, NULL); 509 Location location(kFunction, kFile, kLineNumber, NULL);
381 TallyABirth(location, std::string()); 510 TallyABirth(location, std::string());
382 511
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 pending_task.time_posted = kTimePosted; // Overwrite implied Now(). 854 pending_task.time_posted = kTimePosted; // Overwrite implied Now().
726 855
727 const unsigned int kStartOfRun = 5; 856 const unsigned int kStartOfRun = 5;
728 const unsigned int kEndOfRun = 7; 857 const unsigned int kEndOfRun = 7;
729 SetTestTime(kStartOfRun); 858 SetTestTime(kStartOfRun);
730 TaskStopwatch stopwatch; 859 TaskStopwatch stopwatch;
731 stopwatch.Start(); 860 stopwatch.Start();
732 SetTestTime(kEndOfRun); 861 SetTestTime(kEndOfRun);
733 stopwatch.Stop(); 862 stopwatch.Stop();
734 863
864 // DO NOT SUBMIT
735 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); 865 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
736 866
737 ThreadData::OnProfilingPhaseCompleted(0); 867 ThreadData::OnProfilingPhaseCompleted(0);
738 868
739 ProcessDataSnapshot process_data; 869 ProcessDataSnapshot process_data;
740 ThreadData::Snapshot(1, &process_data); 870 ThreadData::Snapshot(1, &process_data);
741 871
742 ASSERT_EQ(2u, process_data.phased_snapshots.size()); 872 ASSERT_EQ(2u, process_data.phased_snapshots.size());
743 873
744 auto it0 = process_data.phased_snapshots.find(0); 874 auto it0 = process_data.phased_snapshots.find(0);
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); 1308 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max);
1179 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); 1309 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample);
1180 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); 1310 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum);
1181 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); 1311 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max);
1182 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); 1312 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample);
1183 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); 1313 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name);
1184 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); 1314 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
1185 } 1315 }
1186 1316
1187 } // namespace tracked_objects 1317 } // namespace tracked_objects
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698