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

Side by Side Diff: third_party/tcmalloc/chromium/src/heap-profile-table.cc

Issue 15418002: Record Chrome trace events in tcmalloc heap profiles (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup, run in all renderers Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006, Google Inc. 1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 reinterpret_cast<uintptr_t>(b.stack[d])); 321 reinterpret_cast<uintptr_t>(b.stack[d]));
322 if (printed < 0 || printed >= bufsize - buflen) return buflen; 322 if (printed < 0 || printed >= bufsize - buflen) return buflen;
323 buflen += printed; 323 buflen += printed;
324 } 324 }
325 printed = snprintf(buf + buflen, bufsize - buflen, "\n"); 325 printed = snprintf(buf + buflen, bufsize - buflen, "\n");
326 if (printed < 0 || printed >= bufsize - buflen) return buflen; 326 if (printed < 0 || printed >= bufsize - buflen) return buflen;
327 buflen += printed; 327 buflen += printed;
328 return buflen; 328 return buflen;
329 } 329 }
330 330
331 int HeapProfileTable::UnparsePseudoStackBucket(
332 const Bucket& bucket,
333 char* buf, int buflen, int bufsize,
334 Stats* profile_stats) {
335 if (profile_stats != NULL) {
336 profile_stats->allocs += bucket.allocs;
337 profile_stats->alloc_size += bucket.alloc_size;
338 profile_stats->frees += bucket.frees;
339 profile_stats->free_size += bucket.free_size;
340 }
341 int printed = snprintf(buf + buflen,
342 bufsize - buflen,
343 "{"
344 "\"trace\": \"");
345 buflen += printed;
346 for (int d = 0; d < bucket.depth; d++) {
347 printed = snprintf(buf + buflen, bufsize - buflen, "%s ",
348 reinterpret_cast<const char*>(bucket.stack[d]));
349 // Brute-force replace any " with ' to keep the JSON correct.
350 for (int i = 0; i < printed; ++i) {
351 char* c = buf + buflen + i;
352 if (*c == '"')
353 *c = '\'';
354 }
355 if (printed < 0 || printed >= bufsize - buflen) return buflen;
356 buflen += printed;
357 }
358 printed = snprintf(buf + buflen,
359 bufsize - buflen,
360 "\", "
361 "\"current_allocs\": %d, "
362 "\"current_bytes\": %" PRId64 ", "
363 "\"total_allocs\": %d, "
364 "\"total_bytes\": %" PRId64
365 "}",
366 bucket.allocs - bucket.frees,
367 bucket.alloc_size - bucket.free_size,
368 bucket.allocs,
369 bucket.alloc_size);
370 // If it looks like the snprintf failed, ignore the fact we printed anything
371 if (printed < 0 || printed >= bufsize - buflen) return buflen;
372 buflen += printed;
373 return buflen;
374 }
375
331 HeapProfileTable::Bucket** 376 HeapProfileTable::Bucket**
332 HeapProfileTable::MakeSortedBucketList() const { 377 HeapProfileTable::MakeSortedBucketList() const {
333 Bucket** list = static_cast<Bucket**>(alloc_(sizeof(Bucket) * num_buckets_)); 378 Bucket** list = static_cast<Bucket**>(alloc_(sizeof(Bucket) * num_buckets_));
334 379
335 int bucket_count = 0; 380 int bucket_count = 0;
336 for (int i = 0; i < kHashTableSize; i++) { 381 for (int i = 0; i < kHashTableSize; i++) {
337 for (Bucket* curr = bucket_table_[i]; curr != 0; curr = curr->next) { 382 for (Bucket* curr = bucket_table_[i]; curr != 0; curr = curr->next) {
338 list[bucket_count++] = curr; 383 list[bucket_count++] = curr;
339 } 384 }
340 } 385 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 RAW_DCHECK(bucket_length < size, ""); 478 RAW_DCHECK(bucket_length < size, "");
434 479
435 dealloc_(list); 480 dealloc_(list);
436 481
437 RAW_DCHECK(buf + bucket_length <= map_start, ""); 482 RAW_DCHECK(buf + bucket_length <= map_start, "");
438 memmove(buf + bucket_length, map_start, map_length); // close the gap 483 memmove(buf + bucket_length, map_start, map_length); // close the gap
439 484
440 return bucket_length + map_length; 485 return bucket_length + map_length;
441 } 486 }
442 487
488 int HeapProfileTable::FillPseudoStackProfile(char buffer[],
489 int buffer_size) const {
490 Bucket** list = MakeSortedBucketList();
491
492 Stats stats;
493 memset(&stats, 0, sizeof(stats));
494 int written = snprintf(buffer, buffer_size, "[\n");
495 written = UnparsePseudoStackBucket(
496 total_, buffer, written, buffer_size, &stats);
497
498 for (int i = 0; i < num_buckets_; i++) {
499 written += snprintf(buffer + written, buffer_size - written, ",\n");
500 written = UnparsePseudoStackBucket(
501 *list[i], buffer, written, buffer_size, &stats);
502 }
503 RAW_DCHECK(written < buffer_size, "");
504
505 written += snprintf(buffer + written, buffer_size - written, "\n]\n");
506
507 dealloc_(list);
508
509 return written;
510 }
511
443 // static 512 // static
444 void HeapProfileTable::DumpBucketIterator(const Bucket* bucket, 513 void HeapProfileTable::DumpBucketIterator(const Bucket* bucket,
445 BufferArgs* args) { 514 BufferArgs* args) {
446 args->buflen = UnparseBucket(*bucket, args->buf, args->buflen, args->bufsize, 515 args->buflen = UnparseBucket(*bucket, args->buf, args->buflen, args->bufsize,
447 "", NULL); 516 "", NULL);
448 } 517 }
449 518
450 #if defined(TYPE_PROFILING) 519 #if defined(TYPE_PROFILING)
451 // static 520 // static
452 void HeapProfileTable::TallyTypesItererator( 521 void HeapProfileTable::TallyTypesItererator(
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 char* unused) { 810 char* unused) {
742 // Perhaps also log the allocation stack trace (unsymbolized) 811 // Perhaps also log the allocation stack trace (unsymbolized)
743 // on this line in case somebody finds it useful. 812 // on this line in case somebody finds it useful.
744 RAW_LOG(ERROR, "leaked %"PRIuS" byte object %p", v->bytes, ptr); 813 RAW_LOG(ERROR, "leaked %"PRIuS" byte object %p", v->bytes, ptr);
745 } 814 }
746 815
747 void HeapProfileTable::Snapshot::ReportIndividualObjects() { 816 void HeapProfileTable::Snapshot::ReportIndividualObjects() {
748 char unused; 817 char unused;
749 map_.Iterate(ReportObject, &unused); 818 map_.Iterate(ReportObject, &unused);
750 } 819 }
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/heap-profile-table.h ('k') | third_party/tcmalloc/chromium/src/heap-profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698