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