improve sensorservice dumpsys

Change-Id: I8b53d5cab884c3aca16d95df5fbf288368d52e8b
This commit is contained in:
Mathias Agopian 2011-09-14 16:43:34 -07:00
parent b9e152637a
commit 667102f6b0
3 changed files with 51 additions and 29 deletions

View File

@ -167,6 +167,9 @@ Fusion::Fusion() {
Bm.y = 1; Bm.y = 1;
Bm.z = 0; Bm.z = 0;
x0 = 0;
x1 = 0;
init(); init();
} }

View File

@ -138,9 +138,18 @@ void SensorDevice::dump(String8& result, char* buffer, size_t SIZE)
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
for (size_t i=0 ; i<size_t(count) ; i++) { 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, 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); 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); Mutex::Autolock _l(mLock);
nsecs_t ns = info.rates.valueAt(0); nsecs_t ns = info.selectDelay();
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;
}
}
}
mSensorDevice->setDelay(mSensorDevice, handle, ns); 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) status_t SensorDevice::setDelay(void* ident, int handle, int64_t ns)
{ {
if (!mSensorDevice) return NO_INIT; if (!mSensorDevice) return NO_INIT;
Mutex::Autolock _l(mLock);
Info& info( mActivationCount.editValueFor(handle) ); Info& info( mActivationCount.editValueFor(handle) );
{ // scope for lock status_t err = info.setDelayForIdent(ident, ns);
Mutex::Autolock _l(mLock); if (err < 0) return err;
ssize_t index = info.rates.indexOfKey(ident); ns = info.selectDelay();
if (index < 0) return BAD_INDEX; return mSensorDevice->setDelay(mSensorDevice, handle, ns);
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) { status_t SensorDevice::Info::setDelayForIdent(void* ident, int64_t ns)
ns = cur; {
} 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;
} }
} }
delay = ns;
//LOGD("setDelay: ident=%p, handle=%d, ns=%lld", ident, handle, ns); return ns;
return mSensorDevice->setDelay(mSensorDevice, handle, ns);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -37,11 +37,14 @@ class SensorDevice : public Singleton<SensorDevice> {
friend class Singleton<SensorDevice>; friend class Singleton<SensorDevice>;
struct sensors_poll_device_t* mSensorDevice; struct sensors_poll_device_t* mSensorDevice;
struct sensors_module_t* mSensorModule; struct sensors_module_t* mSensorModule;
Mutex mLock; // protect mActivationCount[].rates mutable Mutex mLock; // protect mActivationCount[].rates
// fixed-size array after construction // fixed-size array after construction
struct Info { struct Info {
Info() { } Info() : delay(0) { }
KeyedVector<void*, nsecs_t> rates; KeyedVector<void*, nsecs_t> rates;
nsecs_t delay;
status_t setDelayForIdent(void* ident, int64_t ns);
nsecs_t selectDelay();
}; };
DefaultKeyedVector<int, Info> mActivationCount; DefaultKeyedVector<int, Info> mActivationCount;