sdm660: folio_daemon: improve logging for debugging

Bug: 37402669
Test: loaded on walleye
Change-Id: I9cfd071158386d3eb15a5b81656b09452c7fed15
This commit is contained in:
Andrew Lehmer 2017-04-17 10:49:30 -07:00 committed by Max Weffers
parent f08faed4c3
commit 1c3353b71b
No known key found for this signature in database
GPG key ID: 795F73D22FB93FAE

View file

@ -15,6 +15,7 @@
*/ */
#include <fcntl.h> #include <fcntl.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/uinput.h> #include <linux/uinput.h>
@ -25,6 +26,9 @@
// Hall-effect sensor type // Hall-effect sensor type
#define SENSOR_TYPE 33171016 #define SENSOR_TYPE 33171016
// Warn if the polling loop yields zero events at most once every five seconds.
#define WARN_PERIOD (time_t)5
/* /*
* This simple daemon listens for events from the Hall-effect sensor and writes * This simple daemon listens for events from the Hall-effect sensor and writes
* the appropriate SW_LID event to a uinput node. This allows the screen to be * the appropriate SW_LID event to a uinput node. This allows the screen to be
@ -38,6 +42,7 @@ int main(void) {
ASensorRef hallSensor; ASensorRef hallSensor;
ALooper *looper; ALooper *looper;
ASensorEventQueue *eventQueue = nullptr; ASensorEventQueue *eventQueue = nullptr;
time_t lastWarn = 0;
ALOGI("Started"); ALOGI("Started");
@ -103,6 +108,7 @@ int main(void) {
// Polling loop // Polling loop
while (ALooper_pollAll(-1, NULL, NULL, NULL) == 0) { while (ALooper_pollAll(-1, NULL, NULL, NULL) == 0) {
int eventCount = 0;
ASensorEvent sensorEvent; ASensorEvent sensorEvent;
while (ASensorEventQueue_getEvents(eventQueue, &sensorEvent, 1) > 0) { while (ASensorEventQueue_getEvents(eventQueue, &sensorEvent, 1) > 0) {
// 1 means closed; 0 means open // 1 means closed; 0 means open
@ -129,6 +135,18 @@ int main(void) {
} }
ALOGI("Sent lid %s event", isClosed ? "closed" : "open"); ALOGI("Sent lid %s event", isClosed ? "closed" : "open");
eventCount++;
}
/*
* Bug 37402669: If ALooper_pollAll() returns when there are no sensor
* events, make a note of this in the log for debugging. Since this can
* cause the loop to be infinitely busy, throttle the warnings to once
* every five seconds to prevent log spam.
*/
if (eventCount == 0 && time(NULL) >= lastWarn + WARN_PERIOD) {
ALOGW("Poll returned with zero events: %s", strerror(errno));
lastWarn = time(NULL);
} }
} }