[PATCH] [lsan] Prettify LSan reports and add a summary
Sergey Matveev
earthdok at google.com
Fri May 24 07:17:11 PDT 2013
- Prettified the output some more
Hi kcc, glider,
http://llvm-reviews.chandlerc.com/D859
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D859?vs=2116&id=2117#toc
Files:
lib/lsan/lsan_common.cc
lib/lsan/lsan_common.h
Index: lib/lsan/lsan_common.cc
===================================================================
--- lib/lsan/lsan_common.cc
+++ lib/lsan/lsan_common.cc
@@ -267,8 +267,10 @@
}
static void PrintLeaked() {
- Printf("\nReporting individual blocks:\n");
+ Printf("Reporting individual blocks:\n");
+ Printf("============================\n");
ForEachChunk(PrintLeakedCb());
+ Printf("\n");
}
enum LeakCheckResult {
@@ -290,9 +292,16 @@
*result = kNoLeaks;
return;
}
+ Printf("\n");
+ Printf("=================================================================\n");
+ Report("ERROR: LeakSanitizer: detected leaks.\n");
leak_report.PrintLargest(flags()->max_leaks);
if (flags()->report_blocks)
PrintLeaked();
+ Printf("LeakSanitizer summary:\n");
+ Printf("======================\n");
+ leak_report.PrintStats();
+ Printf("\n");
ForEachChunk(ClearTagCb());
*result = kLeaksFound;
}
@@ -387,17 +396,39 @@
InternalSort(&leaks_, leaks_.size(), IsLarger);
max_leaks = max_leaks > 0 ? Min(max_leaks, leaks_.size()) : leaks_.size();
for (uptr i = 0; i < max_leaks; i++) {
- Printf("\n%s leak of %llu bytes in %llu objects allocated from:\n",
+ Printf("%s leak of %llu bytes in %llu object%s allocated from:\n",
leaks_[i].is_directly_leaked ? "Direct" : "Indirect",
- leaks_[i].total_size, leaks_[i].hit_count);
+ leaks_[i].total_size, leaks_[i].hit_count,
+ leaks_[i].hit_count == 1 ? "" : "s");
PrintStackTraceById(leaks_[i].stack_trace_id);
+ Printf("\n");
}
if (max_leaks < leaks_.size()) {
uptr remaining = leaks_.size() - max_leaks;
- Printf("\nOmitting %llu more leak%s.\n", remaining,
+ Printf("Omitting %llu more leak%s.\n", remaining,
remaining > 1 ? "s" : "");
}
}
+void LeakReport::PrintStats() {
+ CHECK(leaks_.size() <= kMaxLeaksConsidered);
+ uptr direct_blocks = 0, direct_bytes = 0, direct_leaks = 0;
+ uptr indirect_blocks = 0, indirect_bytes = 0, indirect_leaks = 0;
+ for (uptr i = 0; i < leaks_.size(); i++) {
+ if (leaks_[i].is_directly_leaked) {
+ direct_leaks++;
+ direct_blocks += leaks_[i].hit_count;
+ direct_bytes += leaks_[i].total_size;
+ } else {
+ indirect_leaks++;
+ indirect_blocks += leaks_[i].hit_count;
+ indirect_bytes += leaks_[i].total_size;
+ }
+ }
+ Printf("Directly leaked %llu bytes in %llu blocks (%llu leaks).\n",
+ direct_bytes, direct_blocks, direct_leaks);
+ Printf("Indirectly leaked %llu bytes in %llu blocks (%llu leaks).\n",
+ indirect_bytes, indirect_blocks, indirect_leaks);
+}
} // namespace __lsan
#endif // CAN_SANITIZE_LEAKS
Index: lib/lsan/lsan_common.h
===================================================================
--- lib/lsan/lsan_common.h
+++ lib/lsan/lsan_common.h
@@ -98,6 +98,7 @@
LeakReport() : leaks_(1) {}
void Add(u32 stack_trace_id, uptr leaked_size, ChunkTag tag);
void PrintLargest(uptr max_leaks);
+ void PrintStats();
bool IsEmpty() { return leaks_.size() == 0; }
private:
InternalVector<Leak> leaks_;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D859.2.patch
Type: text/x-patch
Size: 3107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/6dc9308d/attachment.bin>
More information about the llvm-commits
mailing list