bump heap profiler stats fields to 64 bit

People actually seen overflows there. Fixes github issue #1303
This commit is contained in:
Aliaksey Kandratsenka 2023-07-03 12:47:35 -04:00
parent 972c12f77d
commit 44eb0ee83c
4 changed files with 19 additions and 19 deletions

View File

@ -1635,10 +1635,10 @@ void HeapLeakChecker::Create(const char *name, bool make_start_snapshot) {
}
const HeapProfileTable::Stats& t = heap_profile->total();
const size_t start_inuse_bytes = t.alloc_size - t.free_size;
const size_t start_inuse_allocs = t.allocs - t.frees;
RAW_VLOG(10, "Start check \"%s\" profile: %zu bytes "
"in %zu objects",
const int64_t start_inuse_bytes = t.alloc_size - t.free_size;
const int64_t start_inuse_allocs = t.allocs - t.frees;
RAW_VLOG(10, "Start check \"%s\" profile: %" PRId64 " bytes "
"in %" PRId64 " objects",
name_, start_inuse_bytes, start_inuse_allocs);
} else {
RAW_LOG(WARNING, "Heap checker is not active, "
@ -1869,8 +1869,8 @@ bool HeapLeakChecker::DoNoLeaks(ShouldSymbolize should_symbolize) {
"(but no 100%% guarantee that there aren't any): "
"found %" PRId64 " reachable heap objects of %" PRId64 " bytes",
name_,
int64(stats.allocs - stats.frees),
int64(stats.alloc_size - stats.free_size));
stats.allocs - stats.frees,
stats.alloc_size - stats.free_size);
} else {
if (should_symbolize == SYMBOLIZE) {
// To turn addresses into symbols, we need to fork, which is a

View File

@ -58,10 +58,10 @@ struct HeapProfileStats {
alloc_size - free_size == other.alloc_size - other.free_size;
}
int32 allocs; // Number of allocation calls.
int32 frees; // Number of free calls.
int64 alloc_size; // Total size of all allocated objects so far.
int64 free_size; // Total size of all freed objects so far.
int64_t allocs; // Number of allocation calls.
int64_t frees; // Number of free calls.
int64_t alloc_size; // Total size of all allocated objects so far.
int64_t free_size; // Total size of all freed objects so far.
};
// Allocation and deallocation statistics per each stack trace.

View File

@ -288,7 +288,7 @@ int HeapProfileTable::UnparseBucket(const Bucket& b,
profile_stats->free_size += b.free_size;
}
int printed =
snprintf(buf + buflen, bufsize - buflen, "%6d: %8" PRId64 " [%6d: %8" PRId64 "] @%s",
snprintf(buf + buflen, bufsize - buflen, "%6" PRId64 ": %8" PRId64 " [%6" PRId64 ": %8" PRId64 "] @%s",
b.allocs - b.frees,
b.alloc_size - b.free_size,
b.allocs,
@ -499,18 +499,18 @@ void HeapProfileTable::AddToSnapshot(const void* ptr, AllocValue* v,
HeapProfileTable::Snapshot* HeapProfileTable::NonLiveSnapshot(
Snapshot* base) {
RAW_VLOG(2, "NonLiveSnapshot input: %d %d\n",
int(total_.allocs - total_.frees),
int(total_.alloc_size - total_.free_size));
RAW_VLOG(2, "NonLiveSnapshot input: %" PRId64 " %" PRId64 "\n",
total_.allocs - total_.frees,
total_.alloc_size - total_.free_size);
Snapshot* s = new (alloc_(sizeof(Snapshot))) Snapshot(alloc_, dealloc_);
AddNonLiveArgs args;
args.dest = s;
args.base = base;
address_map_->Iterate<AddNonLiveArgs*>(AddIfNonLive, &args);
RAW_VLOG(2, "NonLiveSnapshot output: %d %d\n",
int(s->total_.allocs - s->total_.frees),
int(s->total_.alloc_size - s->total_.free_size));
RAW_VLOG(2, "NonLiveSnapshot output: %" PRId64 " %" PRId64 "\n",
s->total_.allocs - s->total_.frees,
s->total_.alloc_size - s->total_.free_size);
return s;
}

View File

@ -269,7 +269,7 @@ static void DumpProfileLocked(const char* reason) {
static void MaybeDumpProfileLocked() {
if (!dumping) {
const HeapProfileTable::Stats& total = heap_profile->total();
const int64 inuse_bytes = total.alloc_size - total.free_size;
const int64_t inuse_bytes = total.alloc_size - total.free_size;
bool need_to_dump = false;
char buf[128];
@ -597,7 +597,7 @@ struct HeapProfileEndWriter {
char buf[128];
if (heap_profile) {
const HeapProfileTable::Stats& total = heap_profile->total();
const int64 inuse_bytes = total.alloc_size - total.free_size;
const int64_t inuse_bytes = total.alloc_size - total.free_size;
if ((inuse_bytes >> 20) > 0) {
snprintf(buf, sizeof(buf), ("Exiting, %" PRId64 " MB in use"),