summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2015-03-03 15:39:37 -0600
committerMark Salyzyn2015-03-18 14:43:23 -0500
commitf7c0f75275d0fde2d8b7614f1501f0ad0cd3a01c (patch)
treec0470bc2f9663bb790dbce92c10d027954959a8f /logd/LogTimes.cpp
parent5aa097c8a7b9326e1add7a23bf4d31febd25127b (diff)
downloadplatform-system-core-f7c0f75275d0fde2d8b7614f1501f0ad0cd3a01c.tar.gz
platform-system-core-f7c0f75275d0fde2d8b7614f1501f0ad0cd3a01c.tar.xz
platform-system-core-f7c0f75275d0fde2d8b7614f1501f0ad0cd3a01c.zip
logd: replace internal CLOCK_MONOTONIC use with sequence numbers
- switch to simpler and faster internal sequence number, drops a syscall overhead on 32-bit platforms. - add ability to break-out of flushTo loop with filter return -1 allowing in reduction in reader overhead. Change-Id: Ic5cb2b9afa4d9470153971fc9197b07279e2b79d
Diffstat (limited to 'logd/LogTimes.cpp')
-rw-r--r--logd/LogTimes.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/logd/LogTimes.cpp b/logd/LogTimes.cpp
index 5f9db8da5..1b60b7ead 100644
--- a/logd/LogTimes.cpp
+++ b/logd/LogTimes.cpp
@@ -23,12 +23,10 @@
23 23
24pthread_mutex_t LogTimeEntry::timesLock = PTHREAD_MUTEX_INITIALIZER; 24pthread_mutex_t LogTimeEntry::timesLock = PTHREAD_MUTEX_INITIALIZER;
25 25
26const struct timespec LogTimeEntry::EPOCH = { 0, 1 };
27
28LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client, 26LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
29 bool nonBlock, unsigned long tail, 27 bool nonBlock, unsigned long tail,
30 unsigned int logMask, pid_t pid, 28 unsigned int logMask, pid_t pid,
31 log_time start) 29 uint64_t start)
32 : mRefCount(1) 30 : mRefCount(1)
33 , mRelease(false) 31 , mRelease(false)
34 , mError(false) 32 , mError(false)
@@ -42,7 +40,7 @@ LogTimeEntry::LogTimeEntry(LogReader &reader, SocketClient *client,
42 , mClient(client) 40 , mClient(client)
43 , mStart(start) 41 , mStart(start)
44 , mNonBlock(nonBlock) 42 , mNonBlock(nonBlock)
45 , mEnd(CLOCK_MONOTONIC) 43 , mEnd(LogBufferElement::getCurrentSequence())
46{ 44{
47 pthread_cond_init(&threadTriggeredCondition, NULL); 45 pthread_cond_init(&threadTriggeredCondition, NULL);
48 cleanSkip_Locked(); 46 cleanSkip_Locked();
@@ -129,7 +127,7 @@ void *LogTimeEntry::threadStart(void *obj) {
129 lock(); 127 lock();
130 128
131 while (me->threadRunning && !me->isError_Locked()) { 129 while (me->threadRunning && !me->isError_Locked()) {
132 log_time start = me->mStart; 130 uint64_t start = me->mStart;
133 131
134 unlock(); 132 unlock();
135 133
@@ -161,13 +159,13 @@ void *LogTimeEntry::threadStart(void *obj) {
161} 159}
162 160
163// A first pass to count the number of elements 161// A first pass to count the number of elements
164bool LogTimeEntry::FilterFirstPass(const LogBufferElement *element, void *obj) { 162int LogTimeEntry::FilterFirstPass(const LogBufferElement *element, void *obj) {
165 LogTimeEntry *me = reinterpret_cast<LogTimeEntry *>(obj); 163 LogTimeEntry *me = reinterpret_cast<LogTimeEntry *>(obj);
166 164
167 LogTimeEntry::lock(); 165 LogTimeEntry::lock();
168 166
169 if (me->mCount == 0) { 167 if (me->mCount == 0) {
170 me->mStart = element->getMonotonicTime(); 168 me->mStart = element->getSequence();
171 } 169 }
172 170
173 if ((!me->mPid || (me->mPid == element->getPid())) 171 if ((!me->mPid || (me->mPid == element->getPid()))
@@ -181,12 +179,12 @@ bool LogTimeEntry::FilterFirstPass(const LogBufferElement *element, void *obj) {
181} 179}
182 180
183// A second pass to send the selected elements 181// A second pass to send the selected elements
184bool LogTimeEntry::FilterSecondPass(const LogBufferElement *element, void *obj) { 182int LogTimeEntry::FilterSecondPass(const LogBufferElement *element, void *obj) {
185 LogTimeEntry *me = reinterpret_cast<LogTimeEntry *>(obj); 183 LogTimeEntry *me = reinterpret_cast<LogTimeEntry *>(obj);
186 184
187 LogTimeEntry::lock(); 185 LogTimeEntry::lock();
188 186
189 me->mStart = element->getMonotonicTime(); 187 me->mStart = element->getSequence();
190 188
191 if (me->skipAhead[element->getLogId()]) { 189 if (me->skipAhead[element->getLogId()]) {
192 me->skipAhead[element->getLogId()]--; 190 me->skipAhead[element->getLogId()]--;
@@ -195,7 +193,7 @@ bool LogTimeEntry::FilterSecondPass(const LogBufferElement *element, void *obj)
195 193
196 // Truncate to close race between first and second pass 194 // Truncate to close race between first and second pass
197 if (me->mNonBlock && me->mTail && (me->mIndex >= me->mCount)) { 195 if (me->mNonBlock && me->mTail && (me->mIndex >= me->mCount)) {
198 goto skip; 196 goto stop;
199 } 197 }
200 198
201 if (!me->isWatching(element->getLogId())) { 199 if (!me->isWatching(element->getLogId())) {
@@ -207,7 +205,7 @@ bool LogTimeEntry::FilterSecondPass(const LogBufferElement *element, void *obj)
207 } 205 }
208 206
209 if (me->isError_Locked()) { 207 if (me->isError_Locked()) {
210 goto skip; 208 goto stop;
211 } 209 }
212 210
213 if (!me->mTail) { 211 if (!me->mTail) {
@@ -234,6 +232,10 @@ ok:
234skip: 232skip:
235 LogTimeEntry::unlock(); 233 LogTimeEntry::unlock();
236 return false; 234 return false;
235
236stop:
237 LogTimeEntry::unlock();
238 return -1;
237} 239}
238 240
239void LogTimeEntry::cleanSkip_Locked(void) { 241void LogTimeEntry::cleanSkip_Locked(void) {