diff --git a/services/accesstokenmanager/main/cpp/include/dfx/hisysevent_adapter.h b/services/accesstokenmanager/main/cpp/include/dfx/hisysevent_adapter.h index 4e58271b2ef401406d100d6b524150554ee53069..65eb370c08af81ae8d7472430e07a0c3d8b13f4f 100644 --- a/services/accesstokenmanager/main/cpp/include/dfx/hisysevent_adapter.h +++ b/services/accesstokenmanager/main/cpp/include/dfx/hisysevent_adapter.h @@ -74,6 +74,8 @@ void ReportSysEventServiceStart(const AccessTokenDfxInfo& info); void ReportSysEventServiceStartError(SceneCode scene, const std::string& errMsg, int32_t errCode); void ReportSysCommonEventError(int32_t ipcCode, int32_t errCode); void ReportSysEventAddHap(const AccessTokenDfxInfo& info); +uint64_t GetUserDataRemainSize(); +void ReportUserDataSize(); } // namespace AccessToken } // namespace Security diff --git a/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp b/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp index f13756be48d35cc2d04d19dd1e8505f798554d21..fe4b0b737f9af65809123d275612b06d1335d714 100644 --- a/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp +++ b/services/accesstokenmanager/main/cpp/src/dfx/hisysevent_adapter.cpp @@ -13,9 +13,12 @@ * limitations under the License. */ -#include "hisysevent_adapter.h" +#include +#include #include "accesstoken_common_log.h" +#include "directory_ex.h" #include "hisysevent.h" +#include "hisysevent_adapter.h" #include "time_util.h" namespace OHOS { @@ -24,6 +27,11 @@ namespace AccessToken { namespace { static const std::string ACCESSTOKEN_PROCESS_NAME = "accesstoken_service"; static constexpr char ADD_DOMAIN[] = "PERFORMANCE"; +static const std::string ACCESS_TOKEN_NAME = "access_token"; +static const std::string TOKEN_ID_CFG_DIR_PATH = "/data/service/el0/access_token/"; +static const std::string DATABASE_PATH = "/data/service/el1/public/access_token/"; +static const std::string DATA_FOLDER = "/data"; +static constexpr uint64_t INVALID_SIZE = 0; } void ReportSysEventPerformance() @@ -95,6 +103,26 @@ void ReportSysEventAddHap(const AccessTokenDfxInfo& info) LOGE(ATM_DOMAIN, ATM_TAG, "Failed to write hisysevent write, ret %{public}d.", res); } } + +uint64_t GetUserDataRemainSize() +{ + struct statfs stat; + if (statfs(DATA_FOLDER.c_str(), &stat) != 0) { + LOGE(ATM_DOMAIN, ATM_TAG, "Failed to get data remain size."); + return INVALID_SIZE; + } + return static_cast(stat.f_bfree) * stat.f_bsize; +} + +void ReportUserDataSize() +{ + std::vector folderPath{TOKEN_ID_CFG_DIR_PATH, DATABASE_PATH}; + std::vector folderSize{GetFolderSize(TOKEN_ID_CFG_DIR_PATH), GetFolderSize(DATABASE_PATH)}; + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, "USER_DATA_SIZE", + HiviewDFX::HiSysEvent::EventType::STATISTIC, "COMPONENT_NAME", ACCESS_TOKEN_NAME, "PARTITION_NAME", DATA_FOLDER, + "REMAIN_PARTITION_SIZE", GetUserDataRemainSize(), + "FILE_OR_FOLDER_PATH", folderPath, "FILE_OR_FOLDER_SIZE", folderSize); +} } // namespace AccessToken } // namespace Security } // namespace OHOS \ No newline at end of file diff --git a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp index 02262ad1d4f025833cf8b606144daeca74eb48eb..6ee7f90cb828e49e29822b8f5a2565c98fcc9526 100644 --- a/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp +++ b/services/accesstokenmanager/main/cpp/src/service/accesstoken_manager_service.cpp @@ -1407,6 +1407,7 @@ bool AccessTokenManagerService::Initialize() GetConfigValue(dfxInfo.parseConfigFlag); ReportSysEventServiceStart(dfxInfo); + ReportUserDataSize(); LOGI(ATM_DOMAIN, ATM_TAG, "Initialize success"); return true; }