Add the timestamps for each alloc data
With timestamps, we are able to tell the details of allocator
performance such as the average time for malloc() in different size
class, the potential contention time by examing the overlap between
operations, .etc.
Not all malloc et al. operations are recorded with timestamp. Only
operations relates to memory usage change will have them.
Test: All unit tests pass.
Change-Id: I5c2016246a6f10b221387001bb44778969bb26ae
diff --git a/libc/malloc_debug/RecordData.h b/libc/malloc_debug/RecordData.h
index 43dba6a..484d73b 100644
--- a/libc/malloc_debug/RecordData.h
+++ b/libc/malloc_debug/RecordData.h
@@ -68,19 +68,23 @@
class AllocEntry : public RecordEntry {
public:
- explicit AllocEntry(void* pointer);
+ explicit AllocEntry(void* pointer, uint64_t st, uint64_t et);
virtual ~AllocEntry() = default;
protected:
void* pointer_;
+ // The start/end time of this operation.
+ uint64_t start_ns_;
+ uint64_t end_ns_;
+
private:
BIONIC_DISALLOW_COPY_AND_ASSIGN(AllocEntry);
};
class MallocEntry : public AllocEntry {
public:
- MallocEntry(void* pointer, size_t size);
+ MallocEntry(void* pointer, size_t size, uint64_t st, uint64_t et);
virtual ~MallocEntry() = default;
bool Write(int fd) const override;
@@ -94,7 +98,7 @@
class FreeEntry : public AllocEntry {
public:
- explicit FreeEntry(void* pointer);
+ explicit FreeEntry(void* pointer, uint64_t st, uint64_t et);
virtual ~FreeEntry() = default;
bool Write(int fd) const override;
@@ -105,7 +109,7 @@
class CallocEntry : public MallocEntry {
public:
- CallocEntry(void* pointer, size_t size, size_t nmemb);
+ CallocEntry(void* pointer, size_t size, size_t nmemb, uint64_t st, uint64_t et);
virtual ~CallocEntry() = default;
bool Write(int fd) const override;
@@ -119,7 +123,7 @@
class ReallocEntry : public MallocEntry {
public:
- ReallocEntry(void* pointer, size_t size, void* old_pointer);
+ ReallocEntry(void* pointer, size_t size, void* old_pointer, uint64_t st, uint64_t et);
virtual ~ReallocEntry() = default;
bool Write(int fd) const override;
@@ -134,7 +138,7 @@
// aligned_alloc, posix_memalign, memalign, pvalloc, valloc all recorded with this class.
class MemalignEntry : public MallocEntry {
public:
- MemalignEntry(void* pointer, size_t size, size_t alignment);
+ MemalignEntry(void* pointer, size_t size, size_t alignment, uint64_t st, uint64_t et);
virtual ~MemalignEntry() = default;
bool Write(int fd) const override;