Skip to content

Commit 9e1fe6d

Browse files
committed
InputReader: use ALOGD_IF instead of if (…) ALOGD
This makes things a bit more compact and gives us branch prediction hints for those conditionals. Bug: 311625331 Test: $ m checkinput Test: $ atest --host inputflinger_tests Flag: EXEMPT log only update Change-Id: I01a6cd4de6df049af0ac04645f264265a7a520f4
1 parent 3b2e421 commit 9e1fe6d

5 files changed

Lines changed: 47 additions & 87 deletions

File tree

services/inputflinger/reader/InputReader.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ void InputReader::loopOnce() {
174174
if (mNextTimeout != LLONG_MAX) {
175175
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
176176
if (now >= mNextTimeout) {
177-
if (debugRawEvents()) {
178-
ALOGD("Timeout expired, latency=%0.3fms", (now - mNextTimeout) * 0.000001f);
179-
}
177+
ALOGD_IF(debugRawEvents(), "Timeout expired, latency=%0.3fms",
178+
(now - mNextTimeout) * 0.000001f);
180179
mNextTimeout = LLONG_MAX;
181180
mPendingArgs += timeoutExpiredLocked(now);
182181
}
@@ -241,9 +240,7 @@ std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents
241240
}
242241
batchSize += 1;
243242
}
244-
if (debugRawEvents()) {
245-
ALOGD("BatchSize: %zu Count: %zu", batchSize, count);
246-
}
243+
ALOGD_IF(debugRawEvents(), "BatchSize: %zu Count: %zu", batchSize, count);
247244
out += processEventsForDeviceLocked(deviceId, rawEvent, batchSize);
248245
} else {
249246
switch (rawEvent->type) {

services/inputflinger/reader/controller/PeripheralController.cpp

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ std::optional<std::int32_t> PeripheralController::Light::getRawLightBrightness(i
7878
if (rawMaxBrightness != MAX_BRIGHTNESS) {
7979
brightness = brightness * ratio;
8080
}
81-
if (DEBUG_LIGHT_DETAILS) {
82-
ALOGD("getRawLightBrightness rawLightId %d brightness 0x%x ratio %.2f", rawLightId,
83-
brightness, ratio);
84-
}
81+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "getRawLightBrightness rawLightId %d brightness 0x%x ratio %.2f",
82+
rawLightId, brightness, ratio);
8583
return brightness;
8684
}
8785

@@ -97,10 +95,8 @@ void PeripheralController::Light::setRawLightBrightness(int32_t rawLightId, int3
9795
if (rawMaxBrightness != MAX_BRIGHTNESS) {
9896
brightness = ceil(brightness / ratio);
9997
}
100-
if (DEBUG_LIGHT_DETAILS) {
101-
ALOGD("setRawLightBrightness rawLightId %d brightness 0x%x ratio %.2f", rawLightId,
102-
brightness, ratio);
103-
}
98+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "setRawLightBrightness rawLightId %d brightness 0x%x ratio %.2f",
99+
rawLightId, brightness, ratio);
104100
context.setLightBrightness(rawLightId, brightness);
105101
}
106102

@@ -453,10 +449,9 @@ void PeripheralController::configureLights() {
453449
if (rawInfo->flags.test(InputLightClass::GLOBAL)) {
454450
rawGlobalId = rawId;
455451
}
456-
if (DEBUG_LIGHT_DETAILS) {
457-
ALOGD("Light rawId %d name %s max %d flags %s \n", rawInfo->id, rawInfo->name.c_str(),
458-
rawInfo->maxBrightness.value_or(MAX_BRIGHTNESS), rawInfo->flags.string().c_str());
459-
}
452+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "Light rawId %d name %s max %d flags %s\n", rawInfo->id,
453+
rawInfo->name.c_str(), rawInfo->maxBrightness.value_or(MAX_BRIGHTNESS),
454+
rawInfo->flags.string().c_str());
460455
}
461456

462457
// Construct a player ID light
@@ -473,10 +468,8 @@ void PeripheralController::configureLights() {
473468
}
474469
// Construct a RGB light for composed RGB light
475470
if (hasRedLed && hasGreenLed && hasBlueLed) {
476-
if (DEBUG_LIGHT_DETAILS) {
477-
ALOGD("Rgb light ids [%d, %d, %d] \n", rawRgbIds.at(LightColor::RED),
478-
rawRgbIds.at(LightColor::GREEN), rawRgbIds.at(LightColor::BLUE));
479-
}
471+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "Rgb light ids [%d, %d, %d]\n", rawRgbIds.at(LightColor::RED),
472+
rawRgbIds.at(LightColor::GREEN), rawRgbIds.at(LightColor::BLUE));
480473
bool isKeyboardBacklight = keyboardBacklightIds.find(rawRgbIds.at(LightColor::RED)) !=
481474
keyboardBacklightIds.end() &&
482475
keyboardBacklightIds.find(rawRgbIds.at(LightColor::GREEN)) !=
@@ -518,19 +511,17 @@ void PeripheralController::configureLights() {
518511
// If the node is multi-color led, construct a MULTI_COLOR light
519512
if (rawInfo.flags.test(InputLightClass::MULTI_INDEX) &&
520513
rawInfo.flags.test(InputLightClass::MULTI_INTENSITY)) {
521-
if (DEBUG_LIGHT_DETAILS) {
522-
ALOGD("Multicolor light Id %d name %s \n", rawInfo.id, rawInfo.name.c_str());
523-
}
514+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "Multicolor light Id %d name %s\n", rawInfo.id,
515+
rawInfo.name.c_str());
524516
std::unique_ptr<Light> light =
525517
std::make_unique<MultiColorLight>(getDeviceContext(), rawInfo.name, ++mNextId,
526518
type, rawInfo.id);
527519
mLights.insert_or_assign(light->id, std::move(light));
528520
continue;
529521
}
530522
// Construct a Mono LED light
531-
if (DEBUG_LIGHT_DETAILS) {
532-
ALOGD("Mono light Id %d name %s \n", rawInfo.id, rawInfo.name.c_str());
533-
}
523+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "Mono light Id %d name %s\n", rawInfo.id,
524+
rawInfo.name.c_str());
534525
std::unique_ptr<Light> light = std::make_unique<MonoLight>(getDeviceContext(), rawInfo.name,
535526
++mNextId, type, rawInfo.id);
536527

@@ -552,10 +543,8 @@ bool PeripheralController::setLightColor(int32_t lightId, int32_t color) {
552543
return false;
553544
}
554545
auto& light = it->second;
555-
if (DEBUG_LIGHT_DETAILS) {
556-
ALOGD("setLightColor lightId %d type %s color 0x%x", lightId,
557-
ftl::enum_string(light->type).c_str(), color);
558-
}
546+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "setLightColor lightId %d type %s color 0x%x", lightId,
547+
ftl::enum_string(light->type).c_str(), color);
559548
return light->setLightColor(color);
560549
}
561550

@@ -566,10 +555,8 @@ std::optional<int32_t> PeripheralController::getLightColor(int32_t lightId) {
566555
}
567556
auto& light = it->second;
568557
std::optional<int32_t> color = light->getLightColor();
569-
if (DEBUG_LIGHT_DETAILS) {
570-
ALOGD("getLightColor lightId %d type %s color 0x%x", lightId,
571-
ftl::enum_string(light->type).c_str(), color.value_or(0));
572-
}
558+
ALOGD_IF(DEBUG_LIGHT_DETAILS, "getLightColor lightId %d type %s color 0x%x", lightId,
559+
ftl::enum_string(light->type).c_str(), color.value_or(0));
573560
return color;
574561
}
575562

services/inputflinger/reader/mapper/MultiTouchInputMapper.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,17 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) {
7979
if (id) {
8080
outState->rawPointerData.canceledIdBits.markBit(id.value());
8181
}
82-
if (DEBUG_POINTERS) {
83-
ALOGI("Stop processing slot %zu for it received a palm event from device %s",
84-
inIndex, getDeviceName().c_str());
85-
}
82+
ALOGI_IF(DEBUG_POINTERS,
83+
"Stop processing slot %zu for it received a palm event from device %s",
84+
inIndex, getDeviceName().c_str());
8685
continue;
8786
}
8887

8988
if (outCount >= MAX_POINTERS) {
90-
if (DEBUG_POINTERS) {
91-
ALOGD("MultiTouch device %s emitted more than maximum of %zu pointers; "
92-
"ignoring the rest.",
93-
getDeviceName().c_str(), MAX_POINTERS);
94-
}
89+
ALOGD_IF(DEBUG_POINTERS,
90+
"MultiTouch device %s emitted more than maximum of %zu pointers; ignoring the "
91+
"rest.",
92+
getDeviceName().c_str(), MAX_POINTERS);
9593
break; // too many fingers!
9694
}
9795

services/inputflinger/reader/mapper/SensorInputMapper.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ void SensorInputMapper::processHardWareTimestamp(nsecs_t evTime, int32_t mscTime
235235
// else calculate difference between previous and current MSC_TIMESTAMP
236236
if (mPrevMscTime == 0) {
237237
mHardwareTimestamp = evTime;
238-
if (DEBUG_SENSOR_EVENT_DETAILS) {
239-
ALOGD("Initialize hardware timestamp = %" PRId64, mHardwareTimestamp);
240-
}
238+
ALOGD_IF(DEBUG_SENSOR_EVENT_DETAILS, "Initialize hardware timestamp = %" PRId64,
239+
mHardwareTimestamp);
241240
} else {
242241
// Calculate the difference between current msc_timestamp and
243242
// previous msc_timestamp, including when msc_timestamp wraps around.
@@ -330,11 +329,10 @@ void SensorInputMapper::flushSensor(InputDeviceSensorType sensorType) {
330329
bool SensorInputMapper::enableSensor(InputDeviceSensorType sensorType,
331330
std::chrono::microseconds samplingPeriod,
332331
std::chrono::microseconds maxBatchReportLatency) {
333-
if (DEBUG_SENSOR_EVENT_DETAILS) {
334-
ALOGD("Enable Sensor %s samplingPeriod %lld maxBatchReportLatency %lld",
335-
ftl::enum_string(sensorType).c_str(), samplingPeriod.count(),
336-
maxBatchReportLatency.count());
337-
}
332+
ALOGD_IF(DEBUG_SENSOR_EVENT_DETAILS,
333+
"Enable Sensor %s samplingPeriod %lld maxBatchReportLatency %lld",
334+
ftl::enum_string(sensorType).c_str(), samplingPeriod.count(),
335+
maxBatchReportLatency.count());
338336

339337
if (!setSensorEnabled(sensorType, /*enabled=*/true)) {
340338
return false;
@@ -355,9 +353,7 @@ bool SensorInputMapper::enableSensor(InputDeviceSensorType sensorType,
355353
}
356354

357355
void SensorInputMapper::disableSensor(InputDeviceSensorType sensorType) {
358-
if (DEBUG_SENSOR_EVENT_DETAILS) {
359-
ALOGD("Disable Sensor %s", ftl::enum_string(sensorType).c_str());
360-
}
356+
ALOGD_IF(DEBUG_SENSOR_EVENT_DETAILS, "Disable Sensor %s", ftl::enum_string(sensorType).c_str());
361357

362358
if (!setSensorEnabled(sensorType, /*enabled=*/false)) {
363359
return;
@@ -389,15 +385,12 @@ std::list<NotifyArgs> SensorInputMapper::sync(nsecs_t when, bool force) {
389385
}
390386

391387
nsecs_t timestamp = mHasHardwareTimestamp ? mHardwareTimestamp : when;
392-
if (DEBUG_SENSOR_EVENT_DETAILS) {
393-
ALOGD("Sensor %s timestamp %" PRIu64 " values [%f %f %f]",
394-
ftl::enum_string(sensorType).c_str(), timestamp, values[0], values[1], values[2]);
395-
}
388+
ALOGD_IF(DEBUG_SENSOR_EVENT_DETAILS, "Sensor %s timestamp %" PRIu64 " values [%f %f %f]",
389+
ftl::enum_string(sensorType).c_str(), timestamp, values[0], values[1], values[2]);
396390
if (sensor.lastSampleTimeNs.has_value() &&
397391
timestamp - sensor.lastSampleTimeNs.value() < sensor.samplingPeriod.count()) {
398-
if (DEBUG_SENSOR_EVENT_DETAILS) {
399-
ALOGD("Sensor %s Skip a sample.", ftl::enum_string(sensorType).c_str());
400-
}
392+
ALOGD_IF(DEBUG_SENSOR_EVENT_DETAILS, "Sensor %s Skip a sample.",
393+
ftl::enum_string(sensorType).c_str());
401394
} else {
402395
// Convert to Android unit
403396
convertFromLinuxToAndroid(values, sensorType);

services/inputflinger/reader/mapper/VibratorInputMapper.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ std::list<NotifyArgs> VibratorInputMapper::process(const RawEvent& rawEvent) {
4343

4444
std::list<NotifyArgs> VibratorInputMapper::vibrate(const VibrationSequence& sequence,
4545
ssize_t repeat, int32_t token) {
46-
if (DEBUG_VIBRATOR) {
47-
ALOGD("vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d", getDeviceId(),
48-
sequence.toString().c_str(), repeat, token);
49-
}
46+
ALOGD_IF(DEBUG_VIBRATOR, "vibrate: deviceId=%d, pattern=[%s], repeat=%zd, token=%d",
47+
getDeviceId(), sequence.toString().c_str(), repeat, token);
5048
std::list<NotifyArgs> out;
5149

5250
mVibrating = true;
@@ -63,9 +61,7 @@ std::list<NotifyArgs> VibratorInputMapper::vibrate(const VibrationSequence& sequ
6361
}
6462

6563
std::list<NotifyArgs> VibratorInputMapper::cancelVibrate(int32_t token) {
66-
if (DEBUG_VIBRATOR) {
67-
ALOGD("cancelVibrate: deviceId=%d, token=%d", getDeviceId(), token);
68-
}
64+
ALOGD_IF(DEBUG_VIBRATOR, "cancelVibrate: deviceId=%d, token=%d", getDeviceId(), token);
6965
std::list<NotifyArgs> out;
7066

7167
if (mVibrating && mToken == token) {
@@ -95,9 +91,7 @@ std::list<NotifyArgs> VibratorInputMapper::timeoutExpired(nsecs_t when) {
9591
}
9692

9793
std::list<NotifyArgs> VibratorInputMapper::nextStep() {
98-
if (DEBUG_VIBRATOR) {
99-
ALOGD("nextStep: index=%d, vibrate deviceId=%d", (int)mIndex, getDeviceId());
100-
}
94+
ALOGD_IF(DEBUG_VIBRATOR, "nextStep: index=%d, vibrate deviceId=%d", (int)mIndex, getDeviceId());
10195
std::list<NotifyArgs> out;
10296
mIndex += 1;
10397
if (size_t(mIndex) >= mSequence.pattern.size()) {
@@ -111,34 +105,25 @@ std::list<NotifyArgs> VibratorInputMapper::nextStep() {
111105

112106
const VibrationElement& element = mSequence.pattern[mIndex];
113107
if (element.isOn()) {
114-
if (DEBUG_VIBRATOR) {
115-
std::string description = element.toString();
116-
ALOGD("nextStep: sending vibrate deviceId=%d, element=%s", getDeviceId(),
117-
description.c_str());
118-
}
108+
ALOGD_IF(DEBUG_VIBRATOR, "nextStep: sending vibrate deviceId=%d, element=%s", getDeviceId(),
109+
element.toString().c_str());
119110
getDeviceContext().vibrate(element);
120111
} else {
121-
if (DEBUG_VIBRATOR) {
122-
ALOGD("nextStep: sending cancel vibrate deviceId=%d", getDeviceId());
123-
}
112+
ALOGD_IF(DEBUG_VIBRATOR, "nextStep: sending cancel vibrate deviceId=%d", getDeviceId());
124113
getDeviceContext().cancelVibrate();
125114
}
126115
nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
127116
std::chrono::nanoseconds duration =
128117
std::chrono::duration_cast<std::chrono::nanoseconds>(element.duration);
129118
mNextStepTime = now + duration.count();
130119
getContext()->requestTimeoutAtTime(mNextStepTime);
131-
if (DEBUG_VIBRATOR) {
132-
ALOGD("nextStep: scheduled timeout in %lldms", element.duration.count());
133-
}
120+
ALOGD_IF(DEBUG_VIBRATOR, "nextStep: scheduled timeout in %lldms", element.duration.count());
134121
return out;
135122
}
136123

137124
NotifyVibratorStateArgs VibratorInputMapper::stopVibrating() {
138125
mVibrating = false;
139-
if (DEBUG_VIBRATOR) {
140-
ALOGD("stopVibrating: sending cancel vibrate deviceId=%d", getDeviceId());
141-
}
126+
ALOGD_IF(DEBUG_VIBRATOR, "stopVibrating: sending cancel vibrate deviceId=%d", getDeviceId());
142127
getDeviceContext().cancelVibrate();
143128

144129
// Request InputReader to notify InputManagerService for vibration complete.

0 commit comments

Comments
 (0)