diff options
author | Mark Salyzyn <salyzyn@google.com> | 2014-05-16 00:27:07 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-05-16 00:27:08 +0000 |
commit | 8b2d46a5fcbe81edde4b7c405916282a142a09d2 (patch) | |
tree | 25f2e0e161614b61688a2b978a95ed50c1d99fec | |
parent | b4ad6911a4e88ae5c8f8f0249cae8071a783e01c (diff) | |
parent | 57a0af93133ad0d190a79372b702653f96b99fe8 (diff) | |
download | system_core-8b2d46a5fcbe81edde4b7c405916282a142a09d2.zip system_core-8b2d46a5fcbe81edde4b7c405916282a142a09d2.tar.gz system_core-8b2d46a5fcbe81edde4b7c405916282a142a09d2.tar.bz2 |
Merge "init: logd: Allow Developer settings to adjust logd size"
-rw-r--r-- | init/property_service.c | 1 | ||||
-rw-r--r-- | logd/LogBuffer.cpp | 69 | ||||
-rw-r--r-- | logd/LogCommand.cpp | 2 |
3 files changed, 63 insertions, 9 deletions
diff --git a/init/property_service.c b/init/property_service.c index 7e8d79a..4bcf883 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -90,6 +90,7 @@ struct { { "log.", AID_SHELL, 0 }, { "service.adb.root", AID_SHELL, 0 }, { "service.adb.tcp.port", AID_SHELL, 0 }, + { "persist.logd.size",AID_SYSTEM, 0 }, { "persist.sys.", AID_SYSTEM, 0 }, { "persist.service.", AID_SYSTEM, 0 }, { "persist.security.", AID_SYSTEM, 0 }, 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); diff --git a/logd/LogCommand.cpp b/logd/LogCommand.cpp index 0873e63..e4c138e 100644 --- a/logd/LogCommand.cpp +++ b/logd/LogCommand.cpp @@ -64,7 +64,7 @@ bool clientHasLogCredentials(SocketClient * cli) { } gid_t gid = cli->getGid(); - if ((gid == AID_ROOT) || (gid == AID_LOG)) { + if ((gid == AID_ROOT) || (gid == AID_SYSTEM) || (gid == AID_LOG)) { return true; } |