summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2023-04-06 18:20:39 -0700
committerChristopher Ferris <cferris@google.com>2023-04-06 18:20:39 -0700
commit442cd3e8878759bc39edde2e14d18365d32a53f3 (patch)
treee9a21efdb5fec65b90417bd1e6b42e4e978b1a24
parent3b180696a55ff4c50a07340ba1b2cd5a94c6b087 (diff)
downloadextras-442cd3e8878759bc39edde2e14d18365d32a53f3.tar.gz
Remove async_safe references.
The only reason async_safe was being used was to avoid allocations. However, on bionic, using dprintf also avoids allocations, so use that function instead. Test: Ran memory_replay before and after on a trace and verified all Test: output is the same. Test: Added malloc_disable/malloc_enable around all dprintf calls to Test: verify they do not allocate. Change-Id: I4f1f304bcbabfde529bba281f0a735345dfd312a
-rw-r--r--memory_replay/Android.bp1
-rw-r--r--memory_replay/NativeInfo.cpp17
-rw-r--r--memory_replay/NativeInfo.h3
-rw-r--r--memory_replay/main.cpp18
4 files changed, 12 insertions, 27 deletions
diff --git a/memory_replay/Android.bp b/memory_replay/Android.bp
index bdcde1b2..c7de1feb 100644
--- a/memory_replay/Android.bp
+++ b/memory_replay/Android.bp
@@ -75,7 +75,6 @@ cc_defaults {
static_libs: [
"liballoc_parser",
- "libasync_safe",
],
}
diff --git a/memory_replay/NativeInfo.cpp b/memory_replay/NativeInfo.cpp
index 3439a29d..8493b682 100644
--- a/memory_replay/NativeInfo.cpp
+++ b/memory_replay/NativeInfo.cpp
@@ -27,23 +27,12 @@
#include <unistd.h>
#include <android-base/unique_fd.h>
-#include <async_safe/log.h>
#include "NativeInfo.h"
-void NativePrintf(const char* fmt, ...) {
- va_list args;
- va_start(args, fmt);
- char buffer[512];
- int buffer_len = async_safe_format_buffer_va_list(buffer, sizeof(buffer), fmt, args);
- va_end(args);
-
- (void)write(STDOUT_FILENO, buffer, buffer_len);
-}
-
void NativeFormatFloat(char* buffer, size_t buffer_len, uint64_t value, uint64_t divisor) {
uint64_t hundreds = ((((value % divisor) * 1000) / divisor) + 5) / 10;
- async_safe_format_buffer(buffer, buffer_len, "%" PRIu64 ".%02" PRIu64, value / divisor, hundreds);
+ snprintf(buffer, buffer_len, "%" PRIu64 ".%02" PRIu64, value / divisor, hundreds);
}
// This function is not re-entrant since it uses a static buffer for
@@ -114,7 +103,7 @@ void NativePrintInfo(const char* preamble) {
// Avoid any allocations, so use special non-allocating printfs.
char buffer[256];
NativeFormatFloat(buffer, sizeof(buffer), rss_bytes, 1024 * 1024);
- NativePrintf("%sNative RSS: %zu bytes %sMB\n", preamble, rss_bytes, buffer);
+ dprintf(STDOUT_FILENO, "%sNative RSS: %zu bytes %sMB\n", preamble, rss_bytes, buffer);
NativeFormatFloat(buffer, sizeof(buffer), va_bytes, 1024 * 1024);
- NativePrintf("%sNative VA Space: %zu bytes %sMB\n", preamble, va_bytes, buffer);
+ dprintf(STDOUT_FILENO, "%sNative VA Space: %zu bytes %sMB\n", preamble, va_bytes, buffer);
}
diff --git a/memory_replay/NativeInfo.h b/memory_replay/NativeInfo.h
index c91eec29..a33db027 100644
--- a/memory_replay/NativeInfo.h
+++ b/memory_replay/NativeInfo.h
@@ -20,8 +20,5 @@ void NativeGetInfo(int smaps_fd, size_t* rss_bytes, size_t* va_bytes);
void NativePrintInfo(const char* preamble);
-// Does not support any floating point specifiers.
-void NativePrintf(const char* fmt, ...) __printflike(1, 2);
-
// Fill buffer as if %0.2f was chosen for value / divisor.
void NativeFormatFloat(char* buffer, size_t buffer_len, uint64_t value, uint64_t divisor);
diff --git a/memory_replay/main.cpp b/memory_replay/main.cpp
index e610305e..2dd66bb3 100644
--- a/memory_replay/main.cpp
+++ b/memory_replay/main.cpp
@@ -78,15 +78,15 @@ static void ProcessDump(const AllocEntry* entries, size_t num_entries, size_t ma
Pointers pointers(max_allocs);
Threads threads(&pointers, max_threads);
- NativePrintf("Maximum threads available: %zu\n", threads.max_threads());
- NativePrintf("Maximum allocations in dump: %zu\n", max_allocs);
- NativePrintf("Total pointers available: %zu\n\n", pointers.max_pointers());
+ dprintf(STDOUT_FILENO, "Maximum threads available: %zu\n", threads.max_threads());
+ dprintf(STDOUT_FILENO, "Maximum allocations in dump: %zu\n", max_allocs);
+ dprintf(STDOUT_FILENO, "Total pointers available: %zu\n\n", pointers.max_pointers());
NativePrintInfo("Initial ");
for (size_t i = 0; i < num_entries; i++) {
if (((i + 1) % 100000) == 0) {
- NativePrintf(" At line %zu:\n", i + 1);
+ dprintf(STDOUT_FILENO, " At line %zu:\n", i + 1);
NativePrintInfo(" ");
}
const AllocEntry& entry = entries[i];
@@ -139,7 +139,7 @@ static void ProcessDump(const AllocEntry* entries, size_t num_entries, size_t ma
char buffer[256];
uint64_t total_nsecs = threads.total_time_nsecs();
NativeFormatFloat(buffer, sizeof(buffer), total_nsecs, 1000000000);
- NativePrintf("Total Allocation/Free Time: %" PRIu64 "ns %ss\n", total_nsecs, buffer);
+ dprintf(STDOUT_FILENO, "Total Allocation/Free Time: %" PRIu64 "ns %ss\n", total_nsecs, buffer);
}
int main(int argc, char** argv) {
@@ -161,13 +161,13 @@ int main(int argc, char** argv) {
}
#if defined(__LP64__)
- NativePrintf("64 bit environment.\n");
+ dprintf(STDOUT_FILENO, "64 bit environment.\n");
#else
- NativePrintf("32 bit environment.\n");
+ dprintf(STDOUT_FILENO, "32 bit environment.\n");
#endif
#if defined(__BIONIC__)
- NativePrintf("Setting decay time to 1\n");
+ dprintf(STDOUT_FILENO, "Setting decay time to 1\n");
mallopt(M_DECAY_TIME, 1);
#endif
@@ -180,7 +180,7 @@ int main(int argc, char** argv) {
size_t num_entries;
GetUnwindInfo(argv[1], &entries, &num_entries);
- NativePrintf("Processing: %s\n", argv[1]);
+ dprintf(STDOUT_FILENO, "Processing: %s\n", argv[1]);
ProcessDump(entries, num_entries, max_threads);