Change naming for heapprofd API.
Bug: 160400319
Bug: 141241849
Bug: 166599930
Change-Id: I8c0d63c91d9e81f2fdd9dfd96cd6f436758ff7c3
diff --git a/docs/instrumentation/heapprofd-api.md b/docs/instrumentation/heapprofd-api.md
index 8140d4a..91540a4 100644
--- a/docs/instrumentation/heapprofd-api.md
+++ b/docs/instrumentation/heapprofd-api.md
@@ -88,16 +88,16 @@
```
#include "path/to/client_ext.h"
-static HeapprofdHeapInfo g_info{"invalid.example", nullptr};
-static uint32_t g_heap_id = heapprofd_register_heap(&g_info, sizeof(g_info));
+static uint32_t g_heap_id = AHeapProfile_registerHeap(
+ AHeapInfo_create("invalid.example"));
void* my_malloc(size_t size) {
void* ptr = [code to somehow allocate get size bytes];
- heapprofd_report_allocation(g_heap_id, static_cast<uintptr_t>(ptr), size);
+ AHeapProfile_reportAllocation(g_heap_id, static_cast<uintptr_t>(ptr), size);
return ptr;
}
void my_free(void* ptr) {
- heapprofd_report_free(g_heap_id, static_cast<uintptr_t>(ptr));
+ AHeapProfile_reportFree(g_heap_id, static_cast<uintptr_t>(ptr));
[code to somehow free ptr]
}
```
diff --git a/include/perfetto/profiling/memory/client_ext.h b/include/perfetto/profiling/memory/client_ext.h
index a4d6307..4cadd8d 100644
--- a/include/perfetto/profiling/memory/client_ext.h
+++ b/include/perfetto/profiling/memory/client_ext.h
@@ -35,16 +35,17 @@
// To find out where in a program these two functions get called, we instrument
// the allocator using this API:
//
-// static HeapprofdHeapInfo g_info{"invalid.example", nullptr};
-// static uint32_t g_heap_id = heapprofd_register_heap(&g_info, sizeof(g_info));
+// static uint32_t g_heap_id =
+// AHeapProfile_registerHeap(AHeapInfo_create("invalid.example"));
+//
// void* my_malloc(size_t size) {
// void* ptr = [code to somehow allocate get size bytes];
-// heapprofd_report_allocation(g_heap_id, static_cast<uintptr_t>(ptr), size);
-// return ptr;
+// AHeapProfile_reportAllocation(g_heap_id, static_cast<uintptr_t>(ptr),
+// size); return ptr;
// }
//
// void my_free(void* ptr) {
-// heapprofd_report_free(g_heap_id, static_cast<uintptr_t>(ptr));
+// AHeapProfile_reportFree(g_heap_id, static_cast<uintptr_t>(ptr));
// [code to somehow free ptr]
// }
//
@@ -67,37 +68,37 @@
extern "C" {
#endif
-typedef struct HeapprofdHeapInfo HeapprofdHeapInfo;
+typedef struct AHeapInfo AHeapInfo;
-// Create new HeapprofdHeapInfo, a struct describing a heap.
+// Create new AHeapInfo, a struct describing a heap.
//
// Takes name of the heap, up to 64 bytes including NUL-terminator. To
// guarantee uniqueness, this should include the caller's domain name,
// e.g. "com.android.malloc".
//
-// Must eventually be passed to heapprofd_heap_register.
-HeapprofdHeapInfo* heapprofd_heapinfo_create(const char* heap_name);
+// Must eventually be passed to AHeapProfile_registerHeap.
+AHeapInfo* AHeapInfo_create(const char* heap_name);
-// Set callback in HeapprofdHeapInfo.
+// Set callback in AHeapInfo.
//
-// After this HeapprofdHeapInfo is registered via heapprofd_heap_register,
+// After this AHeapInfo is registered via AHeapProfile_registerHeap,
// this callback is called when profiling of the heap is requested.
-HeapprofdHeapInfo* heapprofd_heapinfo_set_callback(
- HeapprofdHeapInfo* info,
- void (*callback)(bool enabled));
+AHeapInfo* AHeapInfo_setCallback(AHeapInfo* info,
+ void (*callback)(bool enabled));
-// Register heap described in HeapprofdHeapInfo.
+// Register heap described in AHeapInfo.
//
-// The returned heap_id can be used in heapprofd_report_allocation and
-// heapprofd_report_free.
+// The returned heap_id can be used in AHeapProfile_reportAllocation and
+// AHeapProfile_reportFree.
//
// Takes ownership of info.
-uint32_t heapprofd_heap_register(HeapprofdHeapInfo* info);
+uint32_t AHeapProfile_registerHeap(AHeapInfo* info);
// Called by libc upon receipt of the profiling signal.
// DO NOT CALL EXCEPT FROM LIBC!
// TODO(fmayer): Maybe move this out of this header.
-bool heapprofd_init_session(void* (*malloc_fn)(size_t), void (*free_fn)(void*));
+bool AHeapProfile_initSession(void* (*malloc_fn)(size_t),
+ void (*free_fn)(void*));
// Reports an allocation of |size| on the given |heap_id|.
//
@@ -106,19 +107,20 @@
// associated to the current callstack in the profile.
//
// Returns whether the allocation was sampled.
-bool heapprofd_report_allocation(uint32_t heap_id,
- uint64_t alloc_id,
- uint64_t size);
+bool AHeapProfile_reportAllocation(uint32_t heap_id,
+ uint64_t alloc_id,
+ uint64_t size);
// Report allocation was freed on the given heap.
//
-// If |alloc_id| was sampled in a previous call to heapprofd_report_allocation,
-// this allocation is marked as freed in the profile.
+// If |alloc_id| was sampled in a previous call to
+// AHeapProfile_reportAllocation, this allocation is marked as freed in the
+// profile.
//
// It is allowed to call with an |alloc_id| that was either not sampled or never
-// passed to heapprofd_report_allocation, in which case the call will not
+// passed to AHeapProfile_reportAllocation, in which case the call will not
// change the output.
-void heapprofd_report_free(uint32_t heap_id, uint64_t alloc_id);
+void AHeapProfile_reportFree(uint32_t heap_id, uint64_t alloc_id);
#ifdef __cplusplus
}
diff --git a/src/profiling/memory/client_ext.cc b/src/profiling/memory/client_ext.cc
index 03e5d6f..80b0db9 100644
--- a/src/profiling/memory/client_ext.cc
+++ b/src/profiling/memory/client_ext.cc
@@ -46,7 +46,7 @@
using perfetto::profiling::ScopedSpinlock;
using perfetto::profiling::UnhookedAllocator;
-struct HeapprofdHeapInfo {
+struct AHeapInfo {
// Fields set by user.
char heap_name[HEAPPROFD_HEAP_NAME_SZ];
void (*callback)(bool enabled);
@@ -100,9 +100,9 @@
constexpr auto kMinHeapId = 1;
-HeapprofdHeapInfo g_heaps[256];
+AHeapInfo g_heaps[256];
-HeapprofdHeapInfo& GetHeap(uint32_t id) {
+AHeapInfo& GetHeap(uint32_t id) {
return g_heaps[id];
}
@@ -137,7 +137,7 @@
void DisableAllHeaps() {
for (uint32_t i = kMinHeapId; i < g_next_heap_id.load(); ++i) {
- HeapprofdHeapInfo& info = GetHeap(i);
+ AHeapInfo& info = GetHeap(i);
if (!info.ready.load(std::memory_order_acquire))
continue;
if (info.enabled.load(std::memory_order_acquire)) {
@@ -212,10 +212,10 @@
} // namespace
-__attribute__((visibility("default"))) HeapprofdHeapInfo*
-heapprofd_heapinfo_create(const char* heap_name) {
+__attribute__((visibility("default"))) AHeapInfo* AHeapInfo_create(
+ const char* heap_name) {
size_t len = strlen(heap_name);
- if (len >= sizeof(HeapprofdHeapInfo::heap_name)) {
+ if (len >= sizeof(AHeapInfo::heap_name)) {
return nullptr;
}
@@ -227,14 +227,14 @@
if (next_id == kMinHeapId)
perfetto::profiling::StartHeapprofdIfStatic();
- HeapprofdHeapInfo& info = GetHeap(next_id);
+ AHeapInfo& info = GetHeap(next_id);
strncpy(info.heap_name, heap_name, sizeof(info.heap_name));
return &info;
}
-__attribute__((visibility("default"))) HeapprofdHeapInfo*
-heapprofd_heapinfo_set_callback(HeapprofdHeapInfo* info,
- void (*callback)(bool enabled)) {
+__attribute__((visibility("default"))) AHeapInfo* AHeapInfo_setCallback(
+ AHeapInfo* info,
+ void (*callback)(bool enabled)) {
if (info == nullptr)
return nullptr;
if (info->ready.load(std::memory_order_relaxed))
@@ -243,8 +243,8 @@
return info;
}
-__attribute__((visibility("default"))) uint32_t heapprofd_heap_register(
- HeapprofdHeapInfo* info) {
+__attribute__((visibility("default"))) uint32_t AHeapProfile_registerHeap(
+ AHeapInfo* info) {
if (info == nullptr)
return 0;
info->ready.store(true, std::memory_order_release);
@@ -252,8 +252,8 @@
}
__attribute__((visibility("default"))) bool
-heapprofd_report_allocation(uint32_t heap_id, uint64_t id, uint64_t size) {
- const HeapprofdHeapInfo& heap = GetHeap(heap_id);
+AHeapProfile_reportAllocation(uint32_t heap_id, uint64_t id, uint64_t size) {
+ const AHeapInfo& heap = GetHeap(heap_id);
if (!heap.enabled.load(std::memory_order_acquire)) {
return false;
}
@@ -282,10 +282,10 @@
return true;
}
-__attribute__((visibility("default"))) void heapprofd_report_free(
+__attribute__((visibility("default"))) void AHeapProfile_reportFree(
uint32_t heap_id,
uint64_t id) {
- const HeapprofdHeapInfo& heap = GetHeap(heap_id);
+ const AHeapInfo& heap = GetHeap(heap_id);
if (!heap.enabled.load(std::memory_order_acquire)) {
return;
}
@@ -304,7 +304,7 @@
}
}
-__attribute__((visibility("default"))) bool heapprofd_init_session(
+__attribute__((visibility("default"))) bool AHeapProfile_initSession(
void* (*malloc_fn)(size_t),
void (*free_fn)(void*)) {
static bool first_init = true;
@@ -357,7 +357,7 @@
client->client_config();
for (uint32_t i = kMinHeapId; i < g_next_heap_id.load(); ++i) {
- HeapprofdHeapInfo& heap = GetHeap(i);
+ AHeapInfo& heap = GetHeap(i);
if (!heap.ready.load(std::memory_order_acquire))
continue;
diff --git a/src/profiling/memory/client_ext_noop.cc b/src/profiling/memory/client_ext_noop.cc
index 96bfacb..ed9cb0a 100644
--- a/src/profiling/memory/client_ext_noop.cc
+++ b/src/profiling/memory/client_ext_noop.cc
@@ -18,30 +18,31 @@
#include <inttypes.h>
-__attribute__((visibility("default"))) HeapprofdHeapInfo*
-heapprofd_heapinfo_create(const char*) {
+__attribute__((visibility("default"))) AHeapInfo* AHeapInfo_create(
+ const char*) {
return nullptr;
}
-__attribute__((visibility("default"))) HeapprofdHeapInfo*
-heapprofd_heapinfo_set_callback(HeapprofdHeapInfo*, void (*)(bool enabled)) {
+__attribute__((visibility("default"))) AHeapInfo* AHeapInfo_setCallback(
+ AHeapInfo*,
+ void (*)(bool enabled)) {
return nullptr;
}
-__attribute__((visibility("default"))) uint32_t heapprofd_heap_register(
- HeapprofdHeapInfo*) {
+__attribute__((visibility("default"))) uint32_t AHeapProfile_registerHeap(
+ AHeapInfo*) {
return 0;
}
__attribute__((visibility("default"))) bool
-heapprofd_report_allocation(uint32_t, uint64_t, uint64_t) {
+AHeapProfile_reportAllocation(uint32_t, uint64_t, uint64_t) {
return false;
}
-__attribute__((visibility("default"))) void heapprofd_report_free(uint32_t,
- uint64_t) {}
+__attribute__((visibility("default"))) void AHeapProfile_reportFree(uint32_t,
+ uint64_t) {}
-__attribute__((visibility("default"))) bool heapprofd_init_session(
+__attribute__((visibility("default"))) bool AHeapProfile_initSession(
void* (*)(size_t),
void (*)(void*)) {
return false;
diff --git a/src/profiling/memory/client_ext_standalone.cc b/src/profiling/memory/client_ext_standalone.cc
index 08618c9..f935090 100644
--- a/src/profiling/memory/client_ext_standalone.cc
+++ b/src/profiling/memory/client_ext_standalone.cc
@@ -54,7 +54,7 @@
char buf[1];
ssize_t r = g_client_sock->Receive(buf, sizeof(buf));
if (r >= 1) {
- heapprofd_init_session(malloc, free);
+ AHeapProfile_initSession(malloc, free);
} else if (r == 0) {
PERFETTO_ELOG("Server disconneced.");
break;
@@ -149,7 +149,7 @@
task_runner.Run();
}
-// This is called by heapprofd_init_session (client_ext.cc) to construct a
+// This is called by AHeapProfile_initSession (client_ext.cc) to construct a
// client.
std::shared_ptr<Client> ConstructClient(
UnhookedAllocator<perfetto::profiling::Client> unhooked_allocator) {
diff --git a/src/profiling/memory/heapprofd_client_api.map.txt b/src/profiling/memory/heapprofd_client_api.map.txt
index 40c8de0..f5861d0 100644
--- a/src/profiling/memory/heapprofd_client_api.map.txt
+++ b/src/profiling/memory/heapprofd_client_api.map.txt
@@ -1,11 +1,11 @@
{
global:
- heapprofd_heapinfo_create;
- heapprofd_heapinfo_set_callback;
- heapprofd_heap_register;
- heapprofd_init_session;
- heapprofd_report_allocation;
- heapprofd_report_free;
+ AHeapInfo_create;
+ AHeapInfo_setCallback;
+ AHeapProfile_registerHeap;
+ AHeapProfile_initSession;
+ AHeapProfile_reportAllocation;
+ AHeapProfile_reportFree;
local:
*;
};
diff --git a/src/profiling/memory/heapprofd_end_to_end_test.cc b/src/profiling/memory/heapprofd_end_to_end_test.cc
index fd70c61..51ec9cb 100644
--- a/src/profiling/memory/heapprofd_end_to_end_test.cc
+++ b/src/profiling/memory/heapprofd_end_to_end_test.cc
@@ -165,17 +165,16 @@
#endif
void CustomAllocateAndFree(size_t bytes) {
- static uint32_t heap_id =
- heapprofd_heap_register(heapprofd_heapinfo_create("test"));
- heapprofd_report_allocation(heap_id, 0x1234abc, bytes);
- heapprofd_report_free(heap_id, 0x1234abc);
+ static uint32_t heap_id = AHeapProfile_registerHeap(AHeapInfo_create("test"));
+ AHeapProfile_reportAllocation(heap_id, 0x1234abc, bytes);
+ AHeapProfile_reportFree(heap_id, 0x1234abc);
}
void SecondaryAllocAndFree(size_t bytes) {
static uint32_t heap_id =
- heapprofd_heap_register(heapprofd_heapinfo_create("secondary"));
- heapprofd_report_allocation(heap_id, 0x1234abc, bytes);
- heapprofd_report_free(heap_id, 0x1234abc);
+ AHeapProfile_registerHeap(AHeapInfo_create("secondary"));
+ AHeapProfile_reportAllocation(heap_id, 0x1234abc, bytes);
+ AHeapProfile_reportFree(heap_id, 0x1234abc);
}
void AllocateAndFree(size_t bytes) {
@@ -288,9 +287,8 @@
return;
static std::atomic<bool> initialized{false};
- static uint32_t heap_id =
- heapprofd_heap_register(heapprofd_heapinfo_set_callback(
- heapprofd_heapinfo_create("test"), [](bool) { initialized = true; }));
+ static uint32_t heap_id = AHeapProfile_registerHeap(AHeapInfo_setCallback(
+ AHeapInfo_create("test"), [](bool) { initialized = true; }));
ChildFinishHandshake();
@@ -300,11 +298,11 @@
// We call the callback before setting enabled=true on the heap, so we
// wait a bit for the assignment to happen.
usleep(100000);
- heapprofd_report_allocation(heap_id, 0x1, 10u);
- heapprofd_report_free(heap_id, 0x1);
- heapprofd_report_allocation(heap_id, 0x2, 15u);
- heapprofd_report_allocation(heap_id, 0x3, 15u);
- heapprofd_report_free(heap_id, 0x2);
+ AHeapProfile_reportAllocation(heap_id, 0x1, 10u);
+ AHeapProfile_reportFree(heap_id, 0x1);
+ AHeapProfile_reportAllocation(heap_id, 0x2, 15u);
+ AHeapProfile_reportAllocation(heap_id, 0x3, 15u);
+ AHeapProfile_reportFree(heap_id, 0x2);
// Wait around so we can verify it did't crash.
for (;;) {
diff --git a/src/profiling/memory/heapprofd_standalone_client_example.cc b/src/profiling/memory/heapprofd_standalone_client_example.cc
index e03fa18..a6b55bc 100644
--- a/src/profiling/memory/heapprofd_standalone_client_example.cc
+++ b/src/profiling/memory/heapprofd_standalone_client_example.cc
@@ -19,9 +19,9 @@
#include <unistd.h>
int main(int, char**) {
- uint32_t heap_id = heapprofd_heap_register(heapprofd_heapinfo_create("test"));
+ uint32_t heap_id = AHeapProfile_registerHeap(AHeapInfo_create("test"));
for (uint64_t i = 0; i < 100000; ++i) {
- heapprofd_report_allocation(heap_id, i, i);
+ AHeapProfile_reportAllocation(heap_id, i, i);
sleep(1);
}
}
diff --git a/src/profiling/memory/malloc_hooks.cc b/src/profiling/memory/malloc_hooks.cc
index d677fd6..3e67a70 100644
--- a/src/profiling/memory/malloc_hooks.cc
+++ b/src/profiling/memory/malloc_hooks.cc
@@ -105,9 +105,9 @@
}
}
-uint32_t g_heap_id = heapprofd_heap_register(heapprofd_heapinfo_set_callback(
- heapprofd_heapinfo_create("com.android.malloc"),
- ProfileCallback));
+uint32_t g_heap_id = AHeapProfile_registerHeap(
+ AHeapInfo_setCallback(AHeapInfo_create("com.android.malloc"),
+ ProfileCallback));
} // namespace
@@ -126,7 +126,8 @@
const char*) {
// Table of pointers to backing implementation.
g_dispatch.store(malloc_dispatch);
- return heapprofd_init_session(malloc_dispatch->malloc, malloc_dispatch->free);
+ return AHeapProfile_initSession(malloc_dispatch->malloc,
+ malloc_dispatch->free);
}
void HEAPPROFD_ADD_PREFIX(_finalize)() {
@@ -137,32 +138,32 @@
void* HEAPPROFD_ADD_PREFIX(_malloc)(size_t size) {
const MallocDispatch* dispatch = GetDispatch();
void* addr = dispatch->malloc(size);
- heapprofd_report_allocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
- size);
+ AHeapProfile_reportAllocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
+ size);
return addr;
}
void* HEAPPROFD_ADD_PREFIX(_calloc)(size_t nmemb, size_t size) {
const MallocDispatch* dispatch = GetDispatch();
void* addr = dispatch->calloc(nmemb, size);
- heapprofd_report_allocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
- nmemb * size);
+ AHeapProfile_reportAllocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
+ nmemb * size);
return addr;
}
void* HEAPPROFD_ADD_PREFIX(_aligned_alloc)(size_t alignment, size_t size) {
const MallocDispatch* dispatch = GetDispatch();
void* addr = dispatch->aligned_alloc(alignment, size);
- heapprofd_report_allocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
- size);
+ AHeapProfile_reportAllocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
+ size);
return addr;
}
void* HEAPPROFD_ADD_PREFIX(_memalign)(size_t alignment, size_t size) {
const MallocDispatch* dispatch = GetDispatch();
void* addr = dispatch->memalign(alignment, size);
- heapprofd_report_allocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
- size);
+ AHeapProfile_reportAllocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
+ size);
return addr;
}
@@ -174,8 +175,8 @@
if (res != 0)
return res;
- heapprofd_report_allocation(g_heap_id, reinterpret_cast<uint64_t>(*memptr),
- size);
+ AHeapProfile_reportAllocation(g_heap_id, reinterpret_cast<uint64_t>(*memptr),
+ size);
return 0;
}
@@ -195,7 +196,7 @@
return;
const MallocDispatch* dispatch = GetDispatch();
- heapprofd_report_free(g_heap_id, reinterpret_cast<uint64_t>(pointer));
+ AHeapProfile_reportFree(g_heap_id, reinterpret_cast<uint64_t>(pointer));
return dispatch->free(pointer);
}
@@ -210,10 +211,10 @@
void* HEAPPROFD_ADD_PREFIX(_realloc)(void* pointer, size_t size) {
const MallocDispatch* dispatch = GetDispatch();
if (pointer)
- heapprofd_report_free(g_heap_id, reinterpret_cast<uint64_t>(pointer));
+ AHeapProfile_reportFree(g_heap_id, reinterpret_cast<uint64_t>(pointer));
void* addr = dispatch->realloc(pointer, size);
- heapprofd_report_allocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
- size);
+ AHeapProfile_reportAllocation(g_heap_id, reinterpret_cast<uint64_t>(addr),
+ size);
return addr;
}