diff options
| author | Mark Salyzyn <salyzyn@google.com> | 2014-02-26 21:29:34 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-02-26 21:29:34 +0000 |
| commit | 78617a0875ccf5662dc69a6fbcc72a7a39ab42a3 (patch) | |
| tree | 15d8ca635798a5bc4314b4882f99e018a39813ee | |
| parent | e9c8fb900a460699201208870ce9997a734261cc (diff) | |
| parent | 882f856668331488d9bbaec429de7aac5d7978c9 (diff) | |
| download | system_core-78617a0875ccf5662dc69a6fbcc72a7a39ab42a3.zip system_core-78617a0875ccf5662dc69a6fbcc72a7a39ab42a3.tar.gz system_core-78617a0875ccf5662dc69a6fbcc72a7a39ab42a3.tar.bz2 | |
Merge changes Id25cdef0,I80685cdc,I929dddc7
* changes:
logd: Add SCHED_BATCH to reduce priority
logd: Adjust to match defacto coding style
logd: prune more aggressively when over the top
| -rw-r--r-- | logd/FlushCommand.cpp | 4 | ||||
| -rw-r--r-- | logd/LogBuffer.cpp | 19 | ||||
| -rw-r--r-- | logd/LogCommand.cpp | 4 | ||||
| -rw-r--r-- | logd/LogTimes.cpp | 2 | ||||
| -rw-r--r-- | logd/LogTimes.h | 9 | ||||
| -rw-r--r-- | logd/main.cpp | 8 |
6 files changed, 30 insertions, 16 deletions
diff --git a/logd/FlushCommand.cpp b/logd/FlushCommand.cpp index b848fd0..f6f8cb8 100644 --- a/logd/FlushCommand.cpp +++ b/logd/FlushCommand.cpp @@ -63,7 +63,7 @@ void FlushCommand::runSocketCommand(SocketClient *client) { } if (it == times.end()) { - /* Create LogTimeEntry in notifyNewLog() ? */ + // Create LogTimeEntry in notifyNewLog() ? if (mTail == (unsigned long) -1) { LogTimeEntry::unlock(); return; @@ -74,7 +74,7 @@ void FlushCommand::runSocketCommand(SocketClient *client) { client->incRef(); - /* release client and entry reference counts once done */ + // release client and entry reference counts once done entry->startReader_Locked(); LogTimeEntry::unlock(); } diff --git a/logd/LogBuffer.cpp b/logd/LogBuffer.cpp index 8b273e2..7340a36 100644 --- a/logd/LogBuffer.cpp +++ b/logd/LogBuffer.cpp @@ -52,11 +52,12 @@ void LogBuffer::log(log_id_t log_id, struct timespec realtime, LogBufferElementCollection::iterator it = mLogElements.end(); LogBufferElementCollection::iterator last = it; while (--it != mLogElements.begin()) { - if ((*it)->getRealTime() <= elem->getRealTime()) { + if ((*it)->getRealTime() <= realtime) { break; } last = it; } + if (last == mLogElements.end()) { mLogElements.push_back(elem); } else { @@ -83,7 +84,7 @@ void LogBuffer::log(log_id_t log_id, struct timespec realtime, } if (end_always - || (end_set && (end >= (*last)->getMonotonicTime()))) { + || (end_set && (end >= (*last)->getMonotonicTime()))) { mLogElements.push_back(elem); } else { mLogElements.insert(last,elem); @@ -99,12 +100,20 @@ void LogBuffer::log(log_id_t log_id, struct timespec realtime, } // If we're using more than 256K of memory for log entries, prune -// 10% of the log entries. +// at least 10% of the log entries. // // mLogElementsLock must be held when this function is called. void LogBuffer::maybePrune(log_id_t id) { - if (mSizes[id] > LOG_BUFFER_SIZE) { - prune(id, mElements[id] / 10); + unsigned long sizes = mSizes[id]; + if (sizes > LOG_BUFFER_SIZE) { + unsigned long sizeOver90Percent = sizes - ((LOG_BUFFER_SIZE * 9) / 10); + unsigned long elements = mElements[id]; + unsigned long pruneRows = elements * sizeOver90Percent / sizes; + elements /= 10; + if (pruneRows <= elements) { + pruneRows = elements; + } + prune(id, pruneRows); } } diff --git a/logd/LogCommand.cpp b/logd/LogCommand.cpp index ec8365a..6ccc93e 100644 --- a/logd/LogCommand.cpp +++ b/logd/LogCommand.cpp @@ -16,6 +16,6 @@ #include "LogCommand.h" -LogCommand::LogCommand(const char *cmd) : - FrameworkCommand(cmd) { +LogCommand::LogCommand(const char *cmd) + : FrameworkCommand(cmd) { } diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp index d6d4e93..67cc65e 100644 --- a/logd/LogTimes.cpp +++ b/logd/LogTimes.cpp @@ -160,7 +160,7 @@ bool LogTimeEntry::FilterFirstPass(const LogBufferElement *element, void *obj) { } if ((!me->mPid || (me->mPid == element->getPid())) - && (me->mLogMask & (1 << element->getLogId()))) { + && (me->mLogMask & (1 << element->getLogId()))) { ++me->mCount; } diff --git a/logd/LogTimes.h b/logd/LogTimes.h index ac52db2..cb6f566 100644 --- a/logd/LogTimes.h +++ b/logd/LogTimes.h @@ -59,16 +59,14 @@ public: void startReader_Locked(void); - bool runningReader_Locked(void) const - { + bool runningReader_Locked(void) const { return threadRunning || mRelease || mError || mNonBlock; } void triggerReader_Locked(void) { threadTriggered = true; } void triggerSkip_Locked(unsigned int skip) { skipAhead = skip; } // Called after LogTimeEntry removed from list, lock implicitly held - void release_Locked(void) - { + void release_Locked(void) { mRelease = true; if (mRefCount || threadRunning) { return; @@ -89,8 +87,7 @@ public: bool owned_Locked(void) const { return mRefCount != 0; } - void decRef_Locked(void) - { + void decRef_Locked(void) { if ((mRefCount && --mRefCount) || !mRelease || threadRunning) { return; } diff --git a/logd/main.cpp b/logd/main.cpp index 667e5bb..1891206 100644 --- a/logd/main.cpp +++ b/logd/main.cpp @@ -17,6 +17,7 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <sched.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -32,6 +33,13 @@ #include "LogListener.h" static int drop_privs() { + struct sched_param param; + memset(¶m, 0, sizeof(param)); + + if (sched_setscheduler((pid_t) 0, SCHED_BATCH, ¶m) < 0) { + return -1; + } + if (prctl(PR_SET_KEEPCAPS, 1) < 0) { return -1; } |
