当前位置: 首页 > 工具软件 > size-sensor > 使用案例 >

Sensor-sensor日志

冉锋
2023-12-01

一.摘要

    在一些传感器异常的问题中我们常常需要看最近的sensor日志,那么我们可以通过dumpsys sensorservice来看最近sensor上报的数据。

二.日志的初始化已经记录

    我们在SensorService.cpp中有一个std::unordered_map<int, RecentEventLogger*> mRecentEvent;对象,这个对象是专门用来记录sensor日志的,每个sensor注册时会添加到这个mRecentEvent

const Sensor& SensorService::registerSensor(SensorInterface* s, bool isDebug, bool isVirtual) {
    int handle = s->getSensor().getHandle();
    int type = s->getSensor().getType();
    if (mSensors.add(handle, s, isDebug, isVirtual)){
        mRecentEvent.emplace(handle, new RecentEventLogger(type));
        return s->getSensor();
    } else {
        return mSensors.getNonSensor();
    }
}

RecentEventLogger的构造方法:

RecentEventLogger::RecentEventLogger(int sensorType) :
        mSensorType(sensorType), mEventSize(eventSizeBySensorType(mSensorType)),
        mRecentEvents(logSizeBySensorType(sensorType)), mMaskData(false),
        mIsLastEventCurrent(false) {
    // blank
}

这里会初始化mSensorType,mEventSize,mRecentEvents,mMaskData,mIsLastEventCurrent。

我们看到logSizeBySensorType(sensorType):

constexpr size_t LOG_SIZE = 10;
constexpr size_t LOG_SIZE_LARGE = 50;  // larger samples for debugging

size_t RecentEventLogger::logSizeBySensorType(int sensorType) {
    return (sensorType == SENSOR_TYPE_STEP_COUNTER ||
            sensorType == SENSOR_TYPE_SIGNIFICANT_MOTION ||
            sensorType == SENSOR_TYPE_ACCELEROMETER ||
            sensorType == SENSOR_TYPE_LIGHT) ? LOG_SIZE_LARGE : LOG_SIZE;
}

这里会根据不同的sensor来初始化mRecentEvents的大小,对应记录日志的条数。

日志的记录:

void SensorService::recordLastValueLocked(
        const sensors_event_t* buffer, size_t count) {
    for (size_t i = 0; i < count; i++) {
        if (buffer[i].type == SENSOR_TYPE_META_DATA ||
            buffer[i].type == SENSOR_TYPE_DYNAMIC_SENSOR_META ||
            buffer[i].type == SENSOR_TYPE_ADDITIONAL_INFO) {
            continue;
        }

        auto logger = mRecentEvent.find(buffer[i].sensor);
        if (logger != mRecentEvent.end()) {
            logger->second->addEvent(buffer[i]);
        }
    }
}

三.打印sensor日志:dumpsys sensorservice

Recent Sensor events:
icm4x6xx Accelerometer Non-wakeup: last 50 events
	 1 (ts=2854.096160598, wall=14:19:36.716) 0.03, 0.00, 9.86, 
	 2 (ts=2854.296986275, wall=14:19:36.877) 0.03, 0.00, 9.86, 
	 3 (ts=2854.497808515, wall=14:19:37.198) 0.03, 0.00, 9.86, 
	 4 (ts=2854.698632004, wall=14:19:37.359) 0.03, -0.00, 9.86, 
	 5 (ts=2854.899459504, wall=14:19:37.519) 0.03, 0.00, 9.88, 
	 6 (ts=2855.100292421, wall=14:19:37.680) 0.03, 0.00, 9.86, 
	 7 (ts=2855.301129869, wall=14:19:38.001) 0.03, 0.00, 9.86, 
	 8 (ts=2855.501969608, wall=14:19:38.161) 0.03, 0.00, 9.86, 
	 9 (ts=2855.702804348, wall=14:19:38.322) 0.03, 0.00, 9.87, 
	10 (ts=2855.903625546, wall=14:19:38.483) 0.03, 0.00, 9.87, 
	11 (ts=2856.104443046, wall=14:19:38.805) 0.03, 0.00, 9.87, 
	12 (ts=2856.305255754, wall=14:19:38.965) 0.03, 0.00, 9.86, 
	13 (ts=2856.506068827, wall=14:19:39.126) 0.03, 0.00, 9.87, 
	14 (ts=2856.706884296, wall=14:19:39.287) 0.03, 0.00, 9.87, 
	15 (ts=2856.907703254, wall=14:19:39.608) 0.03, 0.00, 9.86, 
	16 (ts=2857.108524921, wall=14:19:39.768) 0.03, -0.00, 9.86, 
	17 (ts=2857.309348202, wall=14:19:39.929) 0.03, -0.00, 9.86, 
	18 (ts=2857.510160338, wall=14:19:40.090) 0.03, -0.00, 9.87, 
	19 (ts=2857.710966379, wall=14:19:40.411) 0.03, 0.00, 9.87, 
	20 (ts=2857.911774088, wall=14:19:40.569) 0.03, -0.00, 9.86, 
	21 (ts=2858.112584140, wall=14:19:40.732) 0.03, 0.00, 9.87, 
	22 (ts=2858.313397525, wall=14:19:40.894) 0.03, 0.00, 9.87, 
	23 (ts=2858.514212942, wall=14:19:41.215) 0.03, 0.00, 9.87, 
	24 (ts=2858.715028671, wall=14:19:41.375) 0.03, 0.00, 9.87, 
	25 (ts=2858.915845129, wall=14:19:41.536) 0.03, 0.00, 9.87, 
	26 (ts=2859.116662733, wall=14:19:41.697) 0.04, 0.01, 9.87, 
	27 (ts=2859.317483983, wall=14:19:42.018) 0.03, 0.00, 9.87, 
	28 (ts=2859.518307525, wall=14:19:42.177) 0.03, 0.00, 9.86, 
	29 (ts=2859.719132317, wall=14:19:42.339) -0.16, 0.05, 9.86, 
	30 (ts=2859.919957317, wall=14:19:42.502) 0.24, -0.13, 9.88, 
	31 (ts=2860.106134504, wall=14:19:42.701) 0.07, -0.04, 9.78, 
	32 (ts=2860.307350390, wall=14:19:42.902) 0.15, 0.22, 9.87, 
	33 (ts=2860.508566483, wall=14:19:43.100) 0.03, 0.00, 9.86, 
	34 (ts=2860.709783150, wall=14:19:43.304) 0.24, -0.09, 9.86, 
	35 (ts=2860.911000546, wall=14:19:43.506) -0.41, -0.07, 9.83, 
	36 (ts=2861.112217838, wall=14:19:43.707) 0.30, -0.58, 9.88, 
	37 (ts=2861.313434504, wall=14:19:43.909) -0.17, 0.74, 9.87, 
	38 (ts=2861.514651171, wall=14:19:44.109) 0.17, -0.02, 9.86, 
	39 (ts=2861.715867838, wall=14:19:44.311) 0.03, -0.01, 9.87, 
	40 (ts=2861.917084504, wall=14:19:44.512) 0.03, -0.00, 9.86, 
	41 (ts=2862.118301171, wall=14:19:44.713) 0.03, -0.00, 9.86, 
	42 (ts=2862.319517838, wall=14:19:44.914) 0.03, -0.00, 9.87, 
	43 (ts=2862.535053046, wall=14:19:45.156) 0.03, -0.00, 9.86, 
	44 (ts=2862.735366796, wall=14:19:45.317) 0.03, -0.00, 9.86, 
	45 (ts=2862.936161483, wall=14:19:45.559) 0.03, -0.00, 9.87, 
	46 (ts=2863.137457421, wall=14:19:45.719) 0.03, -0.00, 9.86, 
	47 (ts=2863.339220233, wall=14:19:45.961) 0.03, -0.00, 9.87, 
	48 (ts=2863.541249817, wall=14:19:46.122) 0.03, -0.00, 9.87, 
	49 (ts=2863.743036431, wall=14:19:46.360) 0.03, -0.00, 9.87, 
	50 (ts=2863.944253254, wall=14:19:46.520) 0.03, -0.00, 9.87, 
tcs3701  Non-wakeup: last 10 events
	 1 (ts=2946.619745243, wall=14:21:09.235) 444.16, 580.53, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 2 (ts=2946.739745243, wall=14:21:09.314) 444.34, 582.80, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 3 (ts=2946.819745243, wall=14:21:09.432) 444.09, 577.72, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 4 (ts=2946.939745243, wall=14:21:09.512) 444.23, 580.40, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 5 (ts=2947.019745243, wall=14:21:09.634) 444.42, 580.72, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 6 (ts=2947.139745243, wall=14:21:09.714) 444.61, 580.83, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 7 (ts=2947.219745243, wall=14:21:09.834) 444.63, 580.15, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 8 (ts=2947.339745243, wall=14:21:09.914) 444.52, 580.33, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	 9 (ts=2947.419745243, wall=14:21:10.034) 444.34, 580.19, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
	10 (ts=2947.539745243, wall=14:21:10.114) 444.52, 580.99, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 
tcs3701 Ambient Light Sensor Non-wakeup: last 50 events
	 1 (ts=2226.121162390, wall=14:09:08.637) 243.82, 384.66, 0.00, 
	 2 (ts=2229.121135411, wall=14:09:11.626) 220.43, 201.99, 0.00, 
	 3 (ts=2234.921162911, wall=14:09:17.436) 260.77, 441.69, 0.00, 
	 4 (ts=2243.421169366, wall=14:09:25.937) 292.10, 440.46, 0.00, 
	 5 (ts=2246.421168637, wall=14:09:28.937) 264.20, 252.35, 0.00, 
	 6 (ts=2254.921168846, wall=14:09:37.437) 237.25, 274.17, 0.00, 
	 7 (ts=2259.421161085, wall=14:09:41.936) 204.11, 65.55, 0.00, 
	 8 (ts=2263.421168637, wall=14:09:45.937) 234.64, 413.99, 0.00, 
	 9 (ts=2269.421168794, wall=14:09:51.935) 266.84, 437.25, 0.00, 
	10 (ts=2272.871168950, wall=14:09:55.384) 234.09, 187.97, 0.00, 
	11 (ts=2276.171168012, wall=14:09:58.686) 260.72, 477.61, 0.00, 
	12 (ts=2277.171167804, wall=14:09:59.687) 291.17, 558.56, 0.00, 
	13 (ts=2278.921170669, wall=14:10:01.436) 334.27, 439.70, 0.00, 
	14 (ts=2279.921167335, wall=14:10:02.437) 373.79, 430.49, 0.00, 
	15 (ts=2299.371165721, wall=14:10:21.884) 415.99, 560.64, 0.00, 
	16 (ts=2316.621180814, wall=14:10:39.136) 375.97, 332.78, 0.00, 
	17 (ts=2336.921172324, wall=14:10:59.436) 336.79, 457.61, 0.00, 
	18 (ts=2344.371158835, wall=14:11:06.876) 378.39, 498.37, 0.00, 
	19 (ts=2351.021174147, wall=14:11:13.536) 343.31, 325.59, 0.00, 
	20 (ts=2382.621179252, wall=14:11:45.137) 381.96, 565.16, 0.00, 
	21 (ts=2387.071179773, wall=14:11:49.587) 339.37, 384.41, 0.00, 
	22 (ts=2388.071178575, wall=14:11:50.587) 307.95, 281.18, 0.00, 
	23 (ts=2389.071179773, wall=14:11:51.586) 275.06, 267.06, 0.00, 
	24 (ts=2390.571180710, wall=14:11:53.086) 242.22, 266.33, 0.00, 
	25 (ts=2394.071187273, wall=14:11:56.586) 271.57, 463.68, 0.00, 
	26 (ts=2400.071180919, wall=14:12:02.587) 243.75, 341.59, 0.00, 
	27 (ts=2405.571182794, wall=14:12:08.087) 276.05, 422.47, 0.00, 
	28 (ts=2412.571180190, wall=14:12:15.085) 247.28, 257.95, 0.00, 
	29 (ts=2414.071179721, wall=14:12:16.587) 221.20, 307.36, 0.00, 
	30 (ts=2417.921178783, wall=14:12:20.437) 251.55, 478.45, 0.00, 
	31 (ts=2418.921178471, wall=14:12:21.437) 285.69, 554.16, 0.00, 
	32 (ts=2421.121180971, wall=14:12:23.636) 323.92, 546.42, 0.00, 
	33 (ts=2425.121184873, wall=14:12:27.637) 364.95, 553.90, 0.00, 
	34 (ts=2478.471185550, wall=14:13:20.987) 331.14, 228.03, 0.00, 
	35 (ts=2480.971184404, wall=14:13:23.487) 378.91, 560.23, 0.00, 
	36 (ts=2646.171204230, wall=14:16:08.686) 340.17, 332.61, 0.00, 
	37 (ts=2653.871205793, wall=14:16:16.387) 384.60, 471.37, 0.00, 
	38 (ts=2669.871212124, wall=14:16:32.387) 347.74, 410.62, 0.00, 
	39 (ts=2682.321210353, wall=14:16:44.836) 311.27, 417.46, 0.00, 
	40 (ts=2687.571212384, wall=14:16:50.086) 347.46, 468.98, 0.00, 
	41 (ts=2694.021203061, wall=14:16:56.536) 315.81, 283.56, 0.00, 
	42 (ts=2699.971213269, wall=14:17:02.487) 354.49, 484.49, 0.00, 
	43 (ts=2727.821216391, wall=14:17:30.334) 394.79, 483.69, 0.00, 
	44 (ts=2784.021222231, wall=14:18:26.536) 356.83, 375.04, 0.00, 
	45 (ts=2806.071221138, wall=14:18:48.585) 399.96, 498.34, 0.00, 
	46 (ts=2809.671221606, wall=14:18:52.185) 358.59, 497.79, 0.00, 
	47 (ts=2864.358933931, wall=14:19:46.860) 403.40, 527.02, 0.00, 
	48 (ts=2952.182837326, wall=14:21:14.699) 454.20, 593.31, 0.00, 
	49 (ts=2954.057266805, wall=14:21:16.573) 456.20, 595.96, 0.00, 
	50 (ts=2956.207329357, wall=14:21:18.723) 409.40, 534.90, 0.00, 
tcs3701 Proximity Sensor Wakeup: last 10 events
	 1 (ts=2851.045018463, wall=14:19:33.556) 5.00, 0.00, 0.00, 
	 2 (ts=2857.257696379, wall=14:19:39.770) 0.00, 0.00, 0.00, 
	 3 (ts=2857.990780338, wall=14:19:40.504) 5.00, 0.00, 0.00, 
	 4 (ts=2858.402411952, wall=14:19:40.917) 0.00, 0.00, 0.00, 
	 5 (ts=2858.608242317, wall=14:19:41.122) 5.00, 0.00, 0.00, 
	 6 (ts=2858.916938775, wall=14:19:41.431) 0.00, 0.00, 0.00, 
	 7 (ts=2859.437928150, wall=14:19:41.954) 5.00, 0.00, 0.00, 
	 8 (ts=2861.322240858, wall=14:19:43.837) 0.00, 0.00, 0.00, 
	 9 (ts=2861.425162213, wall=14:19:43.937) 5.00, 0.00, 0.00, 
	10 (ts=2864.838007213, wall=14:19:47.344) 5.00, 0.00, 0.00, 

 

 类似资料: