| OLD | NEW |
| 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 sort(entries, entries + n); | 542 sort(entries, entries + n); |
| 543 | 543 |
| 544 // Report a bounded number of leaks to keep the leak report from | 544 // Report a bounded number of leaks to keep the leak report from |
| 545 // growing too long. | 545 // growing too long. |
| 546 const int to_report = | 546 const int to_report = |
| 547 (FLAGS_heap_check_max_leaks > 0 && | 547 (FLAGS_heap_check_max_leaks > 0 && |
| 548 n > FLAGS_heap_check_max_leaks) ? FLAGS_heap_check_max_leaks : n; | 548 n > FLAGS_heap_check_max_leaks) ? FLAGS_heap_check_max_leaks : n; |
| 549 RAW_LOG(ERROR, "The %d largest leaks:", to_report); | 549 RAW_LOG(ERROR, "The %d largest leaks:", to_report); |
| 550 | 550 |
| 551 // Print | 551 // Print |
| 552 SymbolMap symbolization_table; | 552 SymbolTable symbolization_table; |
| 553 int num_symbols = 0; | |
| 554 for (int i = 0; i < to_report; i++) { | 553 for (int i = 0; i < to_report; i++) { |
| 555 const Entry& e = entries[i]; | 554 const Entry& e = entries[i]; |
| 556 for (int j = 0; j < e.bucket->depth; j++) { | 555 for (int j = 0; j < e.bucket->depth; j++) { |
| 557 const void* pc = e.bucket->stack[j]; | 556 symbolization_table.Add(e.bucket->stack[j]); |
| 558 symbolization_table[reinterpret_cast<uintptr_t>(pc)] = ""; | |
| 559 num_symbols++; | |
| 560 } | 557 } |
| 561 } | 558 } |
| 562 static const int kBufSize = 2<<10; | 559 static const int kBufSize = 2<<10; |
| 563 char buffer[kBufSize]; | 560 char buffer[kBufSize]; |
| 564 int sym_buffer_len = kSymbolSize * num_symbols; | |
| 565 char *sym_buffer = new char[sym_buffer_len]; | |
| 566 if (should_symbolize) | 561 if (should_symbolize) |
| 567 Symbolize(sym_buffer, sym_buffer_len, &symbolization_table); | 562 symbolization_table.Symbolize(); |
| 568 for (int i = 0; i < to_report; i++) { | 563 for (int i = 0; i < to_report; i++) { |
| 569 const Entry& e = entries[i]; | 564 const Entry& e = entries[i]; |
| 570 base::RawPrinter printer(buffer, kBufSize); | 565 base::RawPrinter printer(buffer, kBufSize); |
| 571 printer.Printf("Leak of %d bytes in %d objects allocated from:\n", | 566 printer.Printf("Leak of %d bytes in %d objects allocated from:\n", |
| 572 e.bytes, e.count); | 567 e.bytes, e.count); |
| 573 for (int j = 0; j < e.bucket->depth; j++) { | 568 for (int j = 0; j < e.bucket->depth; j++) { |
| 574 const void* pc = e.bucket->stack[j]; | 569 const void* pc = e.bucket->stack[j]; |
| 575 printer.Printf("\t@ %p %s\n", | 570 printer.Printf("\t@ %"PRIxPTR" %s\n", |
| 576 pc, symbolization_table[reinterpret_cast<uintptr_t>(pc)]); | 571 reinterpret_cast<uintptr_t>(pc), symbolization_table.GetSymbol(pc)); |
| 577 } | 572 } |
| 578 RAW_LOG(ERROR, "%s", buffer); | 573 RAW_LOG(ERROR, "%s", buffer); |
| 579 } | 574 } |
| 580 delete[] sym_buffer; | |
| 581 | 575 |
| 582 if (to_report < n) { | 576 if (to_report < n) { |
| 583 RAW_LOG(ERROR, "Skipping leaks numbered %d..%d", | 577 RAW_LOG(ERROR, "Skipping leaks numbered %d..%d", |
| 584 to_report, n-1); | 578 to_report, n-1); |
| 585 } | 579 } |
| 586 delete[] entries; | 580 delete[] entries; |
| 587 | 581 |
| 588 // TODO: Dump the sorted Entry list instead of dumping raw data? | 582 // TODO: Dump the sorted Entry list instead of dumping raw data? |
| 589 // (should be much shorter) | 583 // (should be much shorter) |
| 590 if (!HeapProfileTable::WriteProfile(filename, total_, &map_)) { | 584 if (!HeapProfileTable::WriteProfile(filename, total_, &map_)) { |
| 591 RAW_LOG(ERROR, "Could not write pprof profile to %s", filename); | 585 RAW_LOG(ERROR, "Could not write pprof profile to %s", filename); |
| 592 } | 586 } |
| 593 } | 587 } |
| 594 | 588 |
| 595 void HeapProfileTable::Snapshot::ReportObject(const void* ptr, | 589 void HeapProfileTable::Snapshot::ReportObject(const void* ptr, |
| 596 AllocValue* v, | 590 AllocValue* v, |
| 597 char* unused) { | 591 char* unused) { |
| 598 // Perhaps also log the allocation stack trace (unsymbolized) | 592 // Perhaps also log the allocation stack trace (unsymbolized) |
| 599 // on this line in case somebody finds it useful. | 593 // on this line in case somebody finds it useful. |
| 600 RAW_LOG(ERROR, "leaked %"PRIuS" byte object %p", v->bytes, ptr); | 594 RAW_LOG(ERROR, "leaked %"PRIuS" byte object %p", v->bytes, ptr); |
| 601 } | 595 } |
| 602 | 596 |
| 603 void HeapProfileTable::Snapshot::ReportIndividualObjects() { | 597 void HeapProfileTable::Snapshot::ReportIndividualObjects() { |
| 604 char unused; | 598 char unused; |
| 605 map_.Iterate(ReportObject, &unused); | 599 map_.Iterate(ReportObject, &unused); |
| 606 } | 600 } |
| OLD | NEW |