improve sensorservice dumpsys
Change-Id: I8b53d5cab884c3aca16d95df5fbf288368d52e8b
This commit is contained in:
parent
b9e152637a
commit
667102f6b0
@ -167,6 +167,9 @@ Fusion::Fusion() {
|
||||
Bm.y = 1;
|
||||
Bm.z = 0;
|
||||
|
||||
x0 = 0;
|
||||
x1 = 0;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -138,9 +138,18 @@ void SensorDevice::dump(String8& result, char* buffer, size_t SIZE)
|
||||
|
||||
Mutex::Autolock _l(mLock);
|
||||
for (size_t i=0 ; i<size_t(count) ; i++) {
|
||||
snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d\n",
|
||||
const Info& info = mActivationCount.valueFor(list[i].handle);
|
||||
snprintf(buffer, SIZE, "handle=0x%08x, active-count=%d, rates(ms)={ ",
|
||||
list[i].handle,
|
||||
mActivationCount.valueFor(list[i].handle).rates.size());
|
||||
info.rates.size());
|
||||
result.append(buffer);
|
||||
for (size_t j=0 ; j<info.rates.size() ; j++) {
|
||||
snprintf(buffer, SIZE, "%4.1f%s",
|
||||
info.rates.valueAt(j) / 1e6f,
|
||||
j<info.rates.size()-1 ? ", " : "");
|
||||
result.append(buffer);
|
||||
}
|
||||
snprintf(buffer, SIZE, " }, selected=%4.1f ms\n", info.delay / 1e6f);
|
||||
result.append(buffer);
|
||||
}
|
||||
}
|
||||
@ -217,17 +226,9 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled)
|
||||
}
|
||||
}
|
||||
|
||||
if (!actuateHardware || enabled) {
|
||||
{ // scope for the lock
|
||||
Mutex::Autolock _l(mLock);
|
||||
nsecs_t ns = info.rates.valueAt(0);
|
||||
for (size_t i=1 ; i<info.rates.size() ; i++) {
|
||||
if (info.rates.valueAt(i) < ns) {
|
||||
nsecs_t cur = info.rates.valueAt(i);
|
||||
if (cur < ns) {
|
||||
ns = cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
nsecs_t ns = info.selectDelay();
|
||||
mSensorDevice->setDelay(mSensorDevice, handle, ns);
|
||||
}
|
||||
|
||||
@ -237,24 +238,39 @@ status_t SensorDevice::activate(void* ident, int handle, int enabled)
|
||||
status_t SensorDevice::setDelay(void* ident, int handle, int64_t ns)
|
||||
{
|
||||
if (!mSensorDevice) return NO_INIT;
|
||||
Mutex::Autolock _l(mLock);
|
||||
Info& info( mActivationCount.editValueFor(handle) );
|
||||
{ // scope for lock
|
||||
Mutex::Autolock _l(mLock);
|
||||
ssize_t index = info.rates.indexOfKey(ident);
|
||||
if (index < 0) return BAD_INDEX;
|
||||
info.rates.editValueAt(index) = ns;
|
||||
ns = info.rates.valueAt(0);
|
||||
for (size_t i=1 ; i<info.rates.size() ; i++) {
|
||||
nsecs_t cur = info.rates.valueAt(i);
|
||||
if (cur < ns) {
|
||||
ns = cur;
|
||||
}
|
||||
status_t err = info.setDelayForIdent(ident, ns);
|
||||
if (err < 0) return err;
|
||||
ns = info.selectDelay();
|
||||
return mSensorDevice->setDelay(mSensorDevice, handle, ns);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
status_t SensorDevice::Info::setDelayForIdent(void* ident, int64_t ns)
|
||||
{
|
||||
ssize_t index = rates.indexOfKey(ident);
|
||||
if (index < 0) {
|
||||
LOGE("Info::setDelayForIdent(ident=%p, ns=%lld) failed (%s)",
|
||||
ident, ns, strerror(-index));
|
||||
return BAD_INDEX;
|
||||
}
|
||||
rates.editValueAt(index) = ns;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
nsecs_t SensorDevice::Info::selectDelay()
|
||||
{
|
||||
nsecs_t ns = rates.valueAt(0);
|
||||
for (size_t i=1 ; i<rates.size() ; i++) {
|
||||
nsecs_t cur = rates.valueAt(i);
|
||||
if (cur < ns) {
|
||||
ns = cur;
|
||||
}
|
||||
}
|
||||
|
||||
//LOGD("setDelay: ident=%p, handle=%d, ns=%lld", ident, handle, ns);
|
||||
|
||||
return mSensorDevice->setDelay(mSensorDevice, handle, ns);
|
||||
delay = ns;
|
||||
return ns;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -37,11 +37,14 @@ class SensorDevice : public Singleton<SensorDevice> {
|
||||
friend class Singleton<SensorDevice>;
|
||||
struct sensors_poll_device_t* mSensorDevice;
|
||||
struct sensors_module_t* mSensorModule;
|
||||
Mutex mLock; // protect mActivationCount[].rates
|
||||
mutable Mutex mLock; // protect mActivationCount[].rates
|
||||
// fixed-size array after construction
|
||||
struct Info {
|
||||
Info() { }
|
||||
Info() : delay(0) { }
|
||||
KeyedVector<void*, nsecs_t> rates;
|
||||
nsecs_t delay;
|
||||
status_t setDelayForIdent(void* ident, int64_t ns);
|
||||
nsecs_t selectDelay();
|
||||
};
|
||||
DefaultKeyedVector<int, Info> mActivationCount;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user