From 8961ff84500d9d57ab09fbb5d0439ef46d7a2e46 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Fri, 24 Jan 2025 20:45:11 +0800 Subject: [PATCH] sensor Adds switch dot Signed-off-by: bailu1992 --- hisysevent.yaml | 10 ++++- utils/common/include/print_sensor_data.h | 2 + utils/common/src/print_sensor_data.cpp | 48 ++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index dacb428a..7cd09bad 100755 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -48,4 +48,10 @@ HDF_SERVICE_EXCEPTION: SERVICE_EXCEPTION: __BASE: {type: FAULT, level: MINOR, desc: sensor service exception} PKG_NAME: {type: STRING, desc: package name} - ERROR_CODE: {type: INT32, desc: error code} \ No newline at end of file + ERROR_CODE: {type: INT32, desc: error code} + +EVENT_REPORT: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: Non consecutive and critical event reporting, preserve: true} + SENSOR_ID: {type: INT32, desc: Sensor Type} + TIMESTAMP: {type: STRING, desc: Timestamp} + DATA: {type: STRING, desc: Data Information} \ No newline at end of file diff --git a/utils/common/include/print_sensor_data.h b/utils/common/include/print_sensor_data.h index 0db26f61..5d24b551 100644 --- a/utils/common/include/print_sensor_data.h +++ b/utils/common/include/print_sensor_data.h @@ -43,6 +43,8 @@ private: void PrintClientData(const SensorEvent &event); void PrintHdiData(const SensorData &sensorData); int32_t GetDataDimension(int32_t sensorId); + void ProcessHdiDFX(const SensorData &sensorData); + void ProcessClientDFX(const SensorEvent &event); struct LogPrintInfo { int32_t count { 0 }; int64_t lastTime { 0 }; diff --git a/utils/common/src/print_sensor_data.cpp b/utils/common/src/print_sensor_data.cpp index 3ff1073d..1d1e5140 100644 --- a/utils/common/src/print_sensor_data.cpp +++ b/utils/common/src/print_sensor_data.cpp @@ -18,6 +18,10 @@ #include #include +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE +#include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE + #include "sensor_errors.h" #undef LOG_TAG @@ -25,6 +29,7 @@ namespace OHOS { namespace Sensors { +using namespace OHOS::HiviewDFX; namespace { enum { ONE_DIMENSION = 1, @@ -43,6 +48,7 @@ const std::vector g_triggerSensorType = { SENSOR_TYPE_ID_PROXIMITY, SENSOR_TYPE_ID_HALL, SENSOR_TYPE_ID_WEAR_DETECTION, + SENSOR_TYPE_ID_PROXIMITY1, }; const std::vector g_continuousSensorType = { SENSOR_TYPE_ID_ACCELEROMETER, @@ -61,6 +67,7 @@ void PrintSensorData::ControlSensorHdiPrint(const SensorData &sensorData) auto triggerIt = std::find(g_triggerSensorType.begin(), g_triggerSensorType.end(), sensorData.sensorTypeId); if (triggerIt != g_triggerSensorType.end()) { PrintHdiData(sensorData); + ProcessHdiDFX(sensorData); } std::lock_guard hdiLoginfoLock(hdiLoginfoMutex_); auto it = hdiLoginfo_.find(sensorData.sensorTypeId); @@ -100,6 +107,26 @@ void PrintSensorData::PrintHdiData(const SensorData &sensorData) SEN_HILOGI("SensorData: %{public}s", str.c_str()); } +void PrintSensorData::ProcessHdiDFX(const SensorData &sensorData) +{ + std::string strData; + auto data = reinterpret_cast(sensorData.data); + int32_t dataDim = GetDataDimension(sensorData.sensorTypeId); + for (int32_t i = 0; i < dataDim; i++) { + CHKPV(data); + strData.append(std::to_string(*data)); + if (i != dataDim - 1) { + strData.append(", "); + } + ++data; + } +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "EVENT_REPORT", + HiSysEvent::EventType::BEHAVIOR, "SENSOR_ID", sensorData.sensorTypeId, "TIMESTAMP", + std::to_string(sensorData.timestamp), "DATA", strData); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE +} + int32_t PrintSensorData::GetDataDimension(int32_t sensorId) { switch (sensorId) { @@ -131,6 +158,7 @@ void PrintSensorData::ControlSensorClientPrint(const RecordSensorCallback callba auto triggerIt = std::find(g_triggerSensorType.begin(), g_triggerSensorType.end(), event.sensorTypeId); if (triggerIt != g_triggerSensorType.end()) { PrintClientData(event); + ProcessClientDFX(event); } auto continuosIt = std::find(g_continuousSensorType.begin(), g_continuousSensorType.end(), event.sensorTypeId); @@ -175,6 +203,26 @@ void PrintSensorData::PrintClientData(const SensorEvent &event) SEN_HILOGI("SensorData: %{public}s", str.c_str()); } +void PrintSensorData::ProcessClientDFX(const SensorEvent &event) +{ + std::string strData; + auto data = reinterpret_cast(event.data); + int32_t dataDim = GetDataDimension(event.sensorTypeId); + for (int32_t i = 0; i < dataDim; i++) { + CHKPV(data); + strData.append(std::to_string(*data)); + if (i != dataDim - 1) { + strData.append(", "); + } + ++data; + } +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "EVENT_REPORT", + HiSysEvent::EventType::BEHAVIOR, "SENSOR_ID", event.sensorTypeId, "TIMESTAMP", + std::to_string(event.timestamp), "DATA", strData); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE +} + bool PrintSensorData::IsContinuousType(int32_t sensorId) { return std::find(g_continuousSensorType.begin(), g_continuousSensorType.end(), -- Gitee