• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revision56f7e9719f4b2615426d01baeff0584a7eb88614 (tree)
Zeit2015-12-22 11:59:30
AutorTraianX Schiau <traianx.schiau@inte...>
CommiterChih-Wei Huang

Log Message

logd: Fix pruning

In a scenario in which an on-line (blocking) client is running and
a clean is attempted (logcat -c), the following can be observed:

1) the on-line logger seems to freeze
2) any other clear attempt will have no effect

What is actually happening:

In this case prune function will "instruct" the oldest timeEntry
to skip a huge number (very close to ULONG_MAX) of messages, this
being the cause of 1.

Since the consumer thread will skip all the log entries, mStart
updating will also be skipped. So a new cleaning attempt will have
the same oldest entry, nothing will be done.

Fix description:
a. keep a separated skipAhead count for individual log buffers (log_id_t)

LogTimeEntry::LogTimeEntry
LogTimeEntry::FilterSecondPass
LogTimeEntry::skipAhead
LogTimeEntry::riggerSkip_Locked

b. update LogTimeEntry::mStart even if the current message is skipped

LogTimeEntry::FilterSecondPass

c. while pruning, only take into account the LogTimeEntrys that are monitoring

the log_id in question, and provide a public method of checking this.
LogTimeEntry::isWatching
LogTimeEntry::FilterFirstPass
LogTimeEntry::FilterSecondPass

d. Reset the skip cont befor the client thtread starts to sleep, at this point

we should be up to date.
LogTimeEntry::cleanSkip_Locked
LogTimeEntry::threadStart

Change-Id: I1b369dc5b02476e633e52578266a644e37e188a5
Signed-off-by: TraianX Schiau <traianx.schiau@intel.com>

Ändern Zusammenfassung

Diff

--- a/logd/LogBuffer.cpp
+++ b/logd/LogBuffer.cpp
@@ -241,7 +241,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
241241 LastLogTimes::iterator t = mTimes.begin();
242242 while(t != mTimes.end()) {
243243 LogTimeEntry *entry = (*t);
244- if (entry->owned_Locked()
244+ if (entry->owned_Locked() && entry->isWatching(id)
245245 && (!oldest || (oldest->mStart > entry->mStart))) {
246246 oldest = entry;
247247 }
@@ -353,7 +353,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
353353 // kick a misbehaving log reader client off the island
354354 oldest->release_Locked();
355355 } else {
356- oldest->triggerSkip_Locked(pruneRows);
356+ oldest->triggerSkip_Locked(id, pruneRows);
357357 }
358358 }
359359 break;
@@ -384,7 +384,7 @@ void LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) {
384384 // kick a misbehaving log reader client off the island
385385 oldest->release_Locked();
386386 } else {
387- oldest->triggerSkip_Locked(pruneRows);
387+ oldest->triggerSkip_Locked(id, pruneRows);
388388 }
389389 break;
390390 }
--- a/logd/LogTimes.cpp
+++ b/logd/LogTimes.cpp
@@ -36,7 +36,6 @@ LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
3636 , mReader(reader)
3737 , mLogMask(logMask)
3838 , mPid(pid)
39- , skipAhead(0)
4039 , mCount(0)
4140 , mTail(tail)
4241 , mIndex(0)
@@ -46,6 +45,7 @@ LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
4645 , mEnd(CLOCK_MONOTONIC)
4746 {
4847 pthread_cond_init(&threadTriggeredCondition, NULL);
48+ cleanSkip_Locked();
4949 }
5050
5151 void LogTimeEntry::startReader_Locked(void) {
@@ -148,6 +148,8 @@ void *LogTimeEntry::threadStart(void *obj) {
148148 break;
149149 }
150150
151+ me->cleanSkip_Locked();
152+
151153 pthread_cond_wait(&me->threadTriggeredCondition, &timesLock);
152154 }
153155
@@ -169,7 +171,7 @@ bool LogTimeEntry::FilterFirstPass(const LogBufferElement *element, void *obj) {
169171 }
170172
171173 if ((!me->mPid || (me->mPid == element->getPid()))
172- && (me->mLogMask & (1 << element->getLogId()))) {
174+ && (me->isWatching(element->getLogId()))) {
173175 ++me->mCount;
174176 }
175177
@@ -184,19 +186,19 @@ bool LogTimeEntry::FilterSecondPass(const LogBufferElement *element, void *obj)
184186
185187 LogTimeEntry::lock();
186188
187- if (me->skipAhead) {
188- me->skipAhead--;
189+ me->mStart = element->getMonotonicTime();
190+
191+ if (me->skipAhead[element->getLogId()]) {
192+ me->skipAhead[element->getLogId()]--;
189193 goto skip;
190194 }
191195
192- me->mStart = element->getMonotonicTime();
193-
194196 // Truncate to close race between first and second pass
195197 if (me->mNonBlock && me->mTail && (me->mIndex >= me->mCount)) {
196198 goto skip;
197199 }
198200
199- if ((me->mLogMask & (1 << element->getLogId())) == 0) {
201+ if (!me->isWatching(element->getLogId())) {
200202 goto skip;
201203 }
202204
@@ -223,7 +225,7 @@ bool LogTimeEntry::FilterSecondPass(const LogBufferElement *element, void *obj)
223225 }
224226
225227 ok:
226- if (!me->skipAhead) {
228+ if (!me->skipAhead[element->getLogId()]) {
227229 LogTimeEntry::unlock();
228230 return true;
229231 }
@@ -233,3 +235,9 @@ skip:
233235 LogTimeEntry::unlock();
234236 return false;
235237 }
238+
239+void LogTimeEntry::cleanSkip_Locked(void) {
240+ for (log_id_t i = LOG_ID_MIN; i < LOG_ID_MAX; i = (log_id_t) (i + 1)) {
241+ skipAhead[i] = 0;
242+ }
243+}
--- a/logd/LogTimes.h
+++ b/logd/LogTimes.h
@@ -22,6 +22,7 @@
2222 #include <sys/types.h>
2323 #include <sysutils/SocketClient.h>
2424 #include <utils/List.h>
25+#include <log/log.h>
2526
2627 class LogReader;
2728
@@ -38,7 +39,7 @@ class LogTimeEntry {
3839 static void threadStop(void *me);
3940 const unsigned int mLogMask;
4041 const pid_t mPid;
41- unsigned int skipAhead;
42+ unsigned int skipAhead[LOG_ID_MAX];
4243 unsigned long mCount;
4344 unsigned long mTail;
4445 unsigned long mIndex;
@@ -67,7 +68,8 @@ public:
6768 pthread_cond_signal(&threadTriggeredCondition);
6869 }
6970
70- void triggerSkip_Locked(unsigned int skip) { skipAhead = skip; }
71+ void triggerSkip_Locked(log_id_t id, unsigned int skip) { skipAhead[id] = skip; }
72+ void cleanSkip_Locked(void);
7173
7274 // Called after LogTimeEntry removed from list, lock implicitly held
7375 void release_Locked(void) {
@@ -99,7 +101,7 @@ public:
99101 // No one else is holding a reference to this
100102 delete this;
101103 }
102-
104+ bool isWatching(log_id_t id) { return (mLogMask & (1<<id)) != 0; }
103105 // flushTo filter callbacks
104106 static bool FilterFirstPass(const LogBufferElement *element, void *me);
105107 static bool FilterSecondPass(const LogBufferElement *element, void *me);