diff options
Diffstat (limited to 'logd/LogBuffer.cpp')
-rw-r--r-- | logd/LogBuffer.cpp | 69 |
1 files changed, 61 insertions, 8 deletions
diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index dc9d47e..ae167aa 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -18,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/user.h> #include <time.h> #include <unistd.h> @@ -32,6 +33,34 @@ // Default #define LOG_BUFFER_SIZE (256 * 1024) // Tuned on a per-platform basis here? #define log_buffer_size(id) mMaxSize[id] +#define LOG_BUFFER_MIN_SIZE (64 * 1024UL) +#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL) + +static bool valid_size(unsigned long value) { + if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) { + return false; + } + + long pages = sysconf(_SC_PHYS_PAGES); + if (pages < 1) { + return true; + } + + long pagesize = sysconf(_SC_PAGESIZE); + if (pagesize <= 1) { + pagesize = PAGE_SIZE; + } + + // maximum memory impact a somewhat arbitrary ~3% + pages = (pages + 31) / 32; + unsigned long maximum = pages * pagesize; + + if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) { + return true; + } + + return value <= maximum; +} static unsigned long property_get_size(const char *key) { char property[PROPERTY_VALUE_MAX]; @@ -56,6 +85,10 @@ static unsigned long property_get_size(const char *key) { value = 0; } + if (!valid_size(value)) { + value = 0; + } + return value; } @@ -64,18 +97,38 @@ LogBuffer::LogBuffer(LastLogTimes *times) pthread_mutex_init(&mLogElementsLock, NULL); dgram_qlen_statistics = false; - static const char global_default[] = "persist.logd.size"; - unsigned long default_size = property_get_size(global_default); + static const char global_tuneable[] = "persist.logd.size"; // Settings App + static const char global_default[] = "ro.logd.size"; // BoardConfig.mk - log_id_for_each(i) { - setSize(i, LOG_BUFFER_SIZE); - setSize(i, default_size); + unsigned long default_size = property_get_size(global_tuneable); + if (!default_size) { + default_size = property_get_size(global_default); + } + log_id_for_each(i) { char key[PROP_NAME_MAX]; + snprintf(key, sizeof(key), "%s.%s", - global_default, android_log_id_to_name(i)); + global_tuneable, android_log_id_to_name(i)); + unsigned long property_size = property_get_size(key); + + if (!property_size) { + snprintf(key, sizeof(key), "%s.%s", + global_default, android_log_id_to_name(i)); + property_size = property_get_size(key); + } + + if (!property_size) { + property_size = default_size; + } - setSize(i, property_get_size(key)); + if (!property_size) { + property_size = LOG_BUFFER_SIZE; + } + + if (setSize(i, property_size)) { + setSize(i, LOG_BUFFER_MIN_SIZE); + } } } @@ -339,7 +392,7 @@ unsigned long LogBuffer::getSizeUsed(log_id_t id) { // set the total space allocated to "id" int LogBuffer::setSize(log_id_t id, unsigned long size) { // Reasonable limits ... - if ((size < (64 * 1024)) || ((256 * 1024 * 1024) < size)) { + if (!valid_size(size)) { return -1; } pthread_mutex_lock(&mLogElementsLock); |