summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-11-30 13:35:56 -0600
committerMark Salyzyn2015-12-07 16:24:02 -0600
commitb75cce0389748bea111ca62af623645117e12d9d (patch)
treeab909a5121db593408c82efe857c8c19e535ae64 /logd/LogTimes.cpp
parent3ea02e8eca9fc0f2122d73a1d117292514256fcf (diff)
downloadplatform-system-core-b75cce0389748bea111ca62af623645117e12d9d.tar.gz
platform-system-core-b75cce0389748bea111ca62af623645117e12d9d.tar.xz
platform-system-core-b75cce0389748bea111ca62af623645117e12d9d.zip
logd: wakeup on wrap or timeout
If a timeout is specified for the reader, then go to sleep with the socket open. If the start time is about to get pruned in the specified log buffers, then wakeup and dump the logs; or wakeup on timeout, whichever comes first. Bug: 25929746 Change-Id: I7d2421c2c5083b33747b84f74d9a560d3ba645df
Diffstat (limited to 'logd/LogTimes.cpp')
-rw-r--r--logd/LogTimes.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp
index 229be3cd5..b4c97a985 100644
--- a/logd/LogTimes.cpp
+++ b/logd/LogTimes.cpp
@@ -14,6 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <errno.h>
17#include <sys/prctl.h> 18#include <sys/prctl.h>
18 19
19#include "FlushCommand.h" 20#include "FlushCommand.h"
@@ -26,7 +27,7 @@ pthread_mutex_t LogTimeEntry::timesLock = PTHREAD_MUTEX_INITIALIZER;
26LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client, 27LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
27 bool nonBlock, unsigned long tail, 28 bool nonBlock, unsigned long tail,
28 unsigned int logMask, pid_t pid, 29 unsigned int logMask, pid_t pid,
29 uint64_t start) : 30 uint64_t start, uint64_t timeout) :
30 mRefCount(1), 31 mRefCount(1),
31 mRelease(false), 32 mRelease(false),
32 mError(false), 33 mError(false),
@@ -42,6 +43,8 @@ LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
42 mStart(start), 43 mStart(start),
43 mNonBlock(nonBlock), 44 mNonBlock(nonBlock),
44 mEnd(LogBufferElement::getCurrentSequence()) { 45 mEnd(LogBufferElement::getCurrentSequence()) {
46 mTimeout.tv_sec = timeout / NS_PER_SEC;
47 mTimeout.tv_nsec = timeout % NS_PER_SEC;
45 pthread_cond_init(&threadTriggeredCondition, NULL); 48 pthread_cond_init(&threadTriggeredCondition, NULL);
46 cleanSkip_Locked(); 49 cleanSkip_Locked();
47} 50}
@@ -131,6 +134,19 @@ void *LogTimeEntry::threadStart(void *obj) {
131 uint64_t start = me->mStart; 134 uint64_t start = me->mStart;
132 135
133 while (me->threadRunning && !me->isError_Locked()) { 136 while (me->threadRunning && !me->isError_Locked()) {
137
138 if (me->mTimeout.tv_sec || me->mTimeout.tv_nsec) {
139 if (pthread_cond_timedwait(&me->threadTriggeredCondition,
140 &timesLock,
141 &me->mTimeout) == ETIMEDOUT) {
142 me->mTimeout.tv_sec = 0;
143 me->mTimeout.tv_nsec = 0;
144 }
145 if (!me->threadRunning || me->isError_Locked()) {
146 break;
147 }
148 }
149
134 unlock(); 150 unlock();
135 151
136 if (me->mTail) { 152 if (me->mTail) {
@@ -154,7 +170,9 @@ void *LogTimeEntry::threadStart(void *obj) {
154 170
155 me->cleanSkip_Locked(); 171 me->cleanSkip_Locked();
156 172
157 pthread_cond_wait(&me->threadTriggeredCondition, &timesLock); 173 if (!me->mTimeout.tv_sec && !me->mTimeout.tv_nsec) {
174 pthread_cond_wait(&me->threadTriggeredCondition, &timesLock);
175 }
158 } 176 }
159 177
160 unlock(); 178 unlock();