for (size_t i = 0; i < total_entries; i++) { switch (entries[i].type) { case MALLOC:
ptrs[entries[i].idx] = malloc(entries[i].size); // Touch at least one byte of the allocation to make sure that // PSS for this allocation is counted. reinterpret_cast<uint8_t*>(ptrs[entries[i].idx])[0] = 10; break; case CALLOC:
ptrs[entries[i].idx] = calloc(entries[i].arg2, entries[i].size); // Touch at least one byte of the allocation to make sure that // PSS for this allocation is counted. reinterpret_cast<uint8_t*>(ptrs[entries[i].idx])[0] = 20; break; case MEMALIGN:
ptrs[entries[i].idx] = memalign(entries[i].arg2, entries[i].size); // Touch at least one byte of the allocation to make sure that // PSS for this allocation is counted. reinterpret_cast<uint8_t*>(ptrs[entries[i].idx])[0] = 30; break; case REALLOC: if (entries[i].arg2 == 0) {
ptrs[entries[i].idx] = realloc(nullptr, entries[i].size);
} else {
ptrs[entries[i].idx] = realloc(ptrs[entries[i].arg2 - 1], entries[i].size);
} // Touch at least one byte of the allocation to make sure that // PSS for this allocation is counted. reinterpret_cast<uint8_t*>(ptrs[entries[i].idx])[0] = 40; break; case FREE:
free(ptrs[entries[i].idx]); break;
}
}
}
// This codifies playing back a single threaded trace of the allocations // when running the SQLite BenchMark app. // Instructions for recreating: // - Enable malloc debug // setprop wrap.com.wtsang02.sqliteutil "LIBC_DEBUG_MALLOC_OPTIONS=record_allocs logwrapper" // - Start the SQLite BenchMark app // - Dump allocs using the signal to get rid of non sql allocs(kill -47 <SQLITE_PID>) // - Run the benchmark. // - Dump allocs using the signal again. // - Find the thread that has the most allocs and run the helper script // bionic/libc/malloc_debug/tools/gen_malloc.pl -i <THREAD_ID> g_sql_entries kMaxSqlAllocSlots < <ALLOC_FILE> > malloc_sql.h #include"malloc_sql.h"
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.