From 9975951a9a2e005c22ba3662703a0d161108e8d7 Mon Sep 17 00:00:00 2001 From: wangjuntao Date: Thu, 24 Jul 2025 15:55:55 +0800 Subject: [PATCH] add sp device interface Signed-off-by: wangjuntao --- .../device_command/include/common.h | 373 ++++++++++++++++++ .../device_command/include/heartbeat.h | 53 +++ .../device_command/include/sp_csv_util.h | 162 ++++++++ .../device_command/include/sp_data.h | 27 ++ .../device_command/include/sp_profiler.h | 31 ++ .../interface/GameEventCallback.h | 30 ++ .../interface/GameServicePlugin.h | 40 ++ .../interface/GpuCounterCallback.h | 75 ++++ 8 files changed, 791 insertions(+) create mode 100644 smartperf_device/device_command/include/common.h create mode 100644 smartperf_device/device_command/include/heartbeat.h create mode 100644 smartperf_device/device_command/include/sp_csv_util.h create mode 100644 smartperf_device/device_command/include/sp_data.h create mode 100644 smartperf_device/device_command/include/sp_profiler.h create mode 100644 smartperf_device/device_command/interface/GameEventCallback.h create mode 100644 smartperf_device/device_command/interface/GameServicePlugin.h create mode 100644 smartperf_device/device_command/interface/GpuCounterCallback.h diff --git a/smartperf_device/device_command/include/common.h b/smartperf_device/device_command/include/common.h new file mode 100644 index 00000000..bc3c5010 --- /dev/null +++ b/smartperf_device/device_command/include/common.h @@ -0,0 +1,373 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef COMMON_H +#define COMMON_H +#include +#include +namespace OHOS { +namespace SmartPerf { +enum class MessageType { + APP_START_COLLECT, + APP_STOP_COLLECT, + APP_PAUSE_COLLECT, + APP_RESUME_COLLECT, + GET_CPU_NUM, + GET_CPU_FREQ_LOAD, + SET_PKG_NAME, + SET_PROCESS_ID, + GET_FPS_AND_JITTERS, + GET_GPU_FREQ, + GET_GPU_LOAD, + GET_DDR_FREQ, + GET_RAM_INFO, + GET_MEMORY_INFO, + GET_TEMPERATURE, + GET_POWER, + GET_CAPTURE, + CATCH_TRACE_CONFIG, + CATCH_TRACE_CMD, + SET_DUBAI_DB, + START_DUBAI_DB, + CATCH_NETWORK_TRAFFIC, + GET_NETWORK_TRAFFIC, // 获取网络流量信息 + BACK_TO_DESKTOP, + GET_CUR_FPS, + SET_GAME_VIEW, + GET_APP_TYPE, + CHECK_UDP_STATUS, + GET_LOG, + GET_DAEMON_VERSION, + GET_PROCESS_THREADS, + GET_PROCESS_FDS, + START_GPU_COUNTER, + SAVE_GPU_COUNTER, + CATCH_TRACE_FINISH, + APP_RECEIVE_DATA_ON, + APP_RECEIVE_DATA_OFF, + GET_INDEX_INFO +}; + +const std::unordered_map MESSAGE_MAP = { + { MessageType::GET_CPU_NUM, std::string("get_cpu_num") }, + { MessageType::GET_CPU_FREQ_LOAD, std::string("get_cpu_freq_load") }, + { MessageType::SET_PKG_NAME, std::string("set_pkgName") }, + { MessageType::SET_PROCESS_ID, std::string("set_pid") }, + { MessageType::GET_FPS_AND_JITTERS, std::string("get_fps_and_jitters") }, + { MessageType::GET_GPU_FREQ, std::string("get_gpu_freq") }, + { MessageType::GET_GPU_LOAD, std::string("get_gpu_load") }, + { MessageType::GET_DDR_FREQ, std::string("get_ddr_freq") }, + { MessageType::GET_RAM_INFO, std::string("get_ram_info") }, + { MessageType::GET_TEMPERATURE, std::string("get_temperature") }, + { MessageType::GET_POWER, std::string("get_power") }, + { MessageType::GET_CAPTURE, std::string("get_capture") }, + { MessageType::GET_MEMORY_INFO, std::string("get_memory") }, + { MessageType::CATCH_TRACE_CONFIG, std::string("catch_trace_config") }, + { MessageType::CATCH_TRACE_CMD, std::string("catch_trace_cmd") }, + { MessageType::SET_DUBAI_DB, std::string("set_dubai_db") }, + { MessageType::START_DUBAI_DB, std::string("start_dubai_db") }, + { MessageType::CATCH_NETWORK_TRAFFIC, std::string("catch_network_traffic") }, + { MessageType::GET_NETWORK_TRAFFIC, std::string("get_network_traffic") }, + { MessageType::BACK_TO_DESKTOP, std::string("back_to_desk") }, + { MessageType::GET_CUR_FPS, std::string("get_cur_fps") }, + { MessageType::SET_GAME_VIEW, std::string("set_game_view") }, + { MessageType::GET_APP_TYPE, std::string("get_app_type") }, + { MessageType::CHECK_UDP_STATUS, std::string("check_udp_status") }, + { MessageType::GET_LOG, std::string("get_log") }, + { MessageType::GET_DAEMON_VERSION, std::string("get_daemon_version") }, + { MessageType::GET_PROCESS_THREADS, std::string("get_process_threads") }, + { MessageType::GET_PROCESS_FDS, std::string("get_process_fds") }, + { MessageType::START_GPU_COUNTER, std::string("start_gpu_counter") }, + { MessageType::SAVE_GPU_COUNTER, std::string("save_gpu_counter") }, + { MessageType::CATCH_TRACE_FINISH, std::string("catch_trace_finish") }, + { MessageType::APP_START_COLLECT, std::string("app_start_collect") }, + { MessageType::APP_STOP_COLLECT, std::string("app_stop_collect") }, + { MessageType::APP_RECEIVE_DATA_ON, std::string("app_receive_data_on") }, + { MessageType::APP_RECEIVE_DATA_OFF, std::string("app_receive_data_off") }, + { MessageType::APP_PAUSE_COLLECT, std::string("app_pause_collect") }, + { MessageType::APP_RESUME_COLLECT, std::string("app_resume_collect") }, + { MessageType::GET_INDEX_INFO, std::string("get_index_info") }, +}; + +enum class CommandType { + CT_N, + CT_PKG, + CT_PID, + CT_OUT, + CT_C, + CT_G, + CT_D, + CT_F, + CT_FDS, + CT_T, + CT_P, + CT_PRINT, + CT_R, + CT_TTRACE, + CT_THREADS, + CT_SNAPSHOT, + CT_HW, + CT_SESSIONID, + CT_INTERVAL, + CT_NET, + CT_VIEW, + CT_FL, //帧率限制值 + CT_FTL, //帧间隔限制值,单位ms + CT_GC, + CT_NAV, + CT_O, + CT_LF, + CT_AS, + CT_GE, + CT_CI, + CT_FC, + CT_HCI, +}; +enum class CommandHelp { + HELP, + VERSION, + SCREEN, + CLEAR, + CLEARALL, + SERVER, + EDITORSERVER, + DEVICESERVER, +}; + +const std::unordered_map COMMAND_MAP = { + { std::string("-N"), CommandType::CT_N }, + { std::string("-PKG"), CommandType::CT_PKG }, + { std::string("-PID"), CommandType::CT_PID }, + { std::string("-OUT"), CommandType::CT_OUT }, + { std::string("-c"), CommandType::CT_C }, + { std::string("-CPU"), CommandType::CT_C }, + { std::string("-g"), CommandType::CT_G }, + { std::string("-GPU"), CommandType::CT_G }, + { std::string("-f"), CommandType::CT_F }, + { std::string("-FPS"), CommandType::CT_F }, + { std::string("-LOW_POWER"), CommandType::CT_F }, + { std::string("-fds"), CommandType::CT_FDS }, + { std::string("-FDS"), CommandType::CT_FDS }, + { std::string("-t"), CommandType::CT_T }, + { std::string("-TEMP"), CommandType::CT_T }, + { std::string("-p"), CommandType::CT_P }, + { std::string("-POWER"), CommandType::CT_P }, + { std::string("-print"), CommandType::CT_PRINT }, + { std::string("-r"), CommandType::CT_R }, + { std::string("-RAM"), CommandType::CT_R }, + { std::string("-trace"), CommandType::CT_TTRACE }, + { std::string("-threads"), CommandType::CT_THREADS }, + { std::string("-snapshot"), CommandType::CT_SNAPSHOT }, + { std::string("-SCREEN"), CommandType::CT_SNAPSHOT }, + { std::string("-hw"), CommandType::CT_HW }, + { std::string("-d"), CommandType::CT_D }, + { std::string("-DDR"), CommandType::CT_D }, + { std::string("-INTERVAL"), CommandType::CT_INTERVAL }, + { std::string("-SESSIONID"), CommandType::CT_SESSIONID }, + { std::string("-net"), CommandType::CT_NET }, + { std::string("-NET"), CommandType::CT_NET }, + { std::string("-VIEW"), CommandType::CT_VIEW }, + { std::string("-fl"), CommandType::CT_FL }, + { std::string("-ftl"), CommandType::CT_FTL }, + { std::string("-gc"), CommandType::CT_GC }, + { std::string("-GPU_COUNTER"), CommandType::CT_GC }, + { std::string("-nav"), CommandType::CT_NAV }, + { std::string("-o"), CommandType::CT_O }, + { std::string("-lockfreq"), CommandType::CT_LF }, + { std::string("-aischedule"), CommandType::CT_AS }, + { std::string("-ge"), CommandType::CT_GE }, + { std::string("-ci"), CommandType::CT_CI }, + { std::string("-fc"), CommandType::CT_FC }, + { std::string("-HCI"), CommandType::CT_HCI }, +}; + +const std::unordered_map COMMAND_MAP_REVERSE = { + { CommandType::CT_N, std::string("-N") }, + { CommandType::CT_PKG, std::string("-PKG") }, + { CommandType::CT_PID, std::string("-PID") }, + { CommandType::CT_OUT, std::string("-OUT") }, + { CommandType::CT_C, std::string("-c") }, + { CommandType::CT_G, std::string("-g") }, + { CommandType::CT_F, std::string("-f") }, + { CommandType::CT_FDS, std::string("-fds") }, + { CommandType::CT_T, std::string("-t") }, + { CommandType::CT_P, std::string("-p") }, + { CommandType::CT_PRINT, std::string("-print") }, + { CommandType::CT_R, std::string("-r") }, + { CommandType::CT_TTRACE, std::string("-trace") }, + { CommandType::CT_THREADS, std::string("-threads") }, + { CommandType::CT_SNAPSHOT, std::string("-snapshot") }, + { CommandType::CT_HW, std::string("-hw") }, + { CommandType::CT_D, std::string("-d") }, + { CommandType::CT_INTERVAL, std::string("-INTERVAL") }, + { CommandType::CT_SESSIONID, std::string("-SESSIONID") }, + { CommandType::CT_NET, std::string("-net") }, + { CommandType::CT_VIEW, std::string("-VIEW") }, + { CommandType::CT_FL, std::string("-fl") }, + { CommandType::CT_FTL, std::string("-ftl") }, + { CommandType::CT_GC, std::string("-GPU_COUNTER") }, + { CommandType::CT_NAV, std::string("-nav") }, + { CommandType::CT_O, std::string("-o") }, + { CommandType::CT_LF, std::string("-lockfreq") }, + { CommandType::CT_AS, std::string("-aischedule") }, + { CommandType::CT_GE, std::string("-ge") }, + { CommandType::CT_CI, std::string("-ci") }, + { CommandType::CT_FC, std::string("-fc") }, + { CommandType::CT_HCI, std::string("-HCI") }, +}; + + +const std::unordered_map COMMAND_HELP_MAP = { + { CommandHelp::HELP, std::string("--help") }, + { CommandHelp::VERSION, std::string("--version") }, + { CommandHelp::SCREEN, std::string("-screen") }, + { CommandHelp::CLEAR, std::string("-clear") }, + { CommandHelp::CLEARALL, std::string("-clearAll") }, + { CommandHelp::SERVER, std::string("-server") }, + { CommandHelp::EDITORSERVER, std::string("-editorServer") }, + { CommandHelp::DEVICESERVER, std::string("-deviceServer") }, +}; + +enum class TraceStatus { + TRACE_START, + TRACE_FINISH, + TRACE_NO +}; + +enum class CmdCommand { + HITRACE_1024, + HITRACE_2048, + HITRACE_CMD, + CREAT_DIR, + SNAPSHOT, + SERVER, + OHTESTFPS, + RM_FILE, + TASKSET, + PROC_STAT, + HIPROFILER, + PERF, + HIPROFILER_CMD, + HIPROFILER_PID, + KILL_CMD, + PIDOF_SP, + SERVER_GREP, + EDITOR_SERVER_GREP, + UINPUT_BACK, + TIMESTAMPS, + USER_PERMISSIONS, + REMOVE, + CP, + TAR, + GET_HILOG, +}; + +const std::unordered_map CMD_COMMAND_MAP = { + { CmdCommand::HITRACE_1024, std::string( + "hitrace --trace_clock mono -t 10 -b 102400 --overwrite idle ace app ohos ability graphic " + "nweb sched freq sync workq multimodalinput > ") }, + { CmdCommand::HITRACE_2048, std::string( + "hitrace --trace_clock mono -t 10 -b 204800 --overwrite idle ace app ohos ability graphic " + "nweb sched freq sync workq multimodalinput > ") }, + { CmdCommand::HITRACE_CMD, std::string("ps -ef |grep hitrace |grep -v grep") }, + { CmdCommand::CREAT_DIR, std::string("mkdir -p -m 777 ") }, + { CmdCommand::SNAPSHOT, std::string("snapshot_display -f ") }, + { CmdCommand::SERVER, std::string("SP_daemon -server") }, + { CmdCommand::OHTESTFPS, std::string("SP_daemon -ohtestfps 10") }, + { CmdCommand::RM_FILE, std::string("rm -rfv /data/local/tmp/") }, + { CmdCommand::TASKSET, std::string("taskset -p f ") }, + { CmdCommand::PROC_STAT, std::string("chmod o+r /proc/stat") }, + { CmdCommand::HIPROFILER, std::string("rm -f /data/local/tmp/hiprofiler_[0-9]*.htrace") }, + { CmdCommand::PERF, std::string("rm -f /data/local/tmp/perf_[0-9]*.data") }, + { CmdCommand::HIPROFILER_CMD, std::string("ps -ef |grep hiprofiler_cmd |grep -v grep") }, + { CmdCommand::HIPROFILER_PID, std::string("pidof hiprofiler_cmd") }, + { CmdCommand::KILL_CMD, std::string("kill ") }, + { CmdCommand::PIDOF_SP, std::string("pidof SP_daemon") }, + { CmdCommand::SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -server'") }, + { CmdCommand::EDITOR_SERVER_GREP, std::string("ps -ef | grep -v grep | grep 'SP_daemon -editorServer'") }, + { CmdCommand::UINPUT_BACK, std::string("uinput -K -d 2076 -d 2020 -u 2076 -u 2020") }, + { CmdCommand::TIMESTAMPS, std::string("timestamps") }, + { CmdCommand::USER_PERMISSIONS, std::string("whoami") }, + { CmdCommand::REMOVE, std::string("rm -rf ") }, + { CmdCommand::CP, std::string("cp ") }, + { CmdCommand::TAR, std::string("tar -czf ") }, + { CmdCommand::GET_HILOG, std::string("timeout 1s hilog > ") }, +}; + +enum class DeviceCmd { + SN, + DEVICET_NAME, + BRAND, + VERSION, + ABILIST, + NAME, + MODEL, + FULL_NAME, +}; +const std::unordered_map DEVICE_CMD_MAP = { + { DeviceCmd::SN, std::string("ohos.boot.sn") }, + { DeviceCmd::DEVICET_NAME, std::string("ohos.boot.hardware") }, + { DeviceCmd::BRAND, std::string("const.product.brand") }, + { DeviceCmd::VERSION, std::string("const.product.software.version") }, + { DeviceCmd::ABILIST, std::string("const.product.cpu.abilist") }, + { DeviceCmd::NAME, std::string("const.product.name") }, + { DeviceCmd::MODEL, std::string("const.product.model") }, + { DeviceCmd::FULL_NAME, std::string("const.ohos.fullname") }, +}; + +enum class HidumperCmd { + DUMPER_DUBAI_B, + DUMPER_DUBAI_F, + DUMPER_SURFACE, + DUMPER_HEAD, + DUMPER_SCREEN, + DUMPER_A_A, + DUMPER_NAV, + DUMPER_MEM, + DUMPER_RS_TREE, +}; +const std::unordered_map HIDUMPER_CMD_MAP = { + { HidumperCmd::DUMPER_DUBAI_B, std::string("hidumper -s 1213 -a '-b'") }, + { HidumperCmd::DUMPER_DUBAI_F, std::string("hidumper -s 1213 -a '-f'") }, + { HidumperCmd::DUMPER_SURFACE, std::string("hidumper -s 10 -a surface | grep surface") }, + { HidumperCmd::DUMPER_HEAD, std::string( + "hidumper -s AbilityManagerService -a '-a' | grep 'bundle name' | head -n 1") }, + { HidumperCmd::DUMPER_SCREEN, std::string("hidumper -s 10 -a screen") }, + { HidumperCmd::DUMPER_A_A, std::string("hidumper -s WindowManagerService -a '-a'") }, + { HidumperCmd::DUMPER_NAV, std::string("hidumper -s WindowManagerService -a '-w ") }, + { HidumperCmd::DUMPER_MEM, std::string("hidumper --mem ") }, + { HidumperCmd::DUMPER_RS_TREE, std::string("hidumper -s 10 -a RSTree | grep SURFACE_NODE") }, +}; + +enum class HisyseventCmd { + HISYS_APP_START, + HISYS_JANK, + HISYS_RESPONSE, + HISYS_COMPLETED, + HISYSEVENT, + HISYS_PID, + HISYS_SCROLL_ANIMATION, +}; +const std::unordered_map HISYSEVENT_CMD_MAP = { + { HisyseventCmd::HISYS_APP_START, std::string("hisysevent -r -o PERFORMANCE -n APP_START") }, + { HisyseventCmd::HISYS_JANK, std::string("hisysevent -r -o PERFORMANCE -n INTERACTION_JANK") }, + { HisyseventCmd::HISYS_SCROLL_ANIMATION, std::string("hisysevent -r -o PERFORMANCE -n SCROLL_ANIMATION") }, + { HisyseventCmd::HISYS_RESPONSE, std::string("hisysevent -r -n INTERACTION_RESPONSE_LATENCY") }, + { HisyseventCmd::HISYS_COMPLETED, std::string("hisysevent -r -n INTERACTION_COMPLETED_LATENCY") }, + { HisyseventCmd::HISYSEVENT, std::string("ps -ef |grep hisysevent") }, + { HisyseventCmd::HISYS_PID, std::string("pidof hisysevent") }, +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/include/heartbeat.h b/smartperf_device/device_command/include/heartbeat.h new file mode 100644 index 00000000..3501b217 --- /dev/null +++ b/smartperf_device/device_command/include/heartbeat.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HEARTBEAT_H +#define HEARTBEAT_H +#include +#include +#include +#include +#include +#include +#include +#include +namespace OHOS { +namespace SmartPerf { +class Heartbeat { +public: + void HeartbeatRule(); + void UpdatestartTime(); + void KillSpId(); + static Heartbeat &GetInstance() + { + static Heartbeat instance; + return instance; + } + +private: + Heartbeat() {}; + Heartbeat(const Heartbeat &); + Heartbeat &operator = (const Heartbeat &); +private: + std::atomic isrunning = true; + const int timeout = 1800; + const int checkMessageTime = 300; + std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); + std::chrono::steady_clock::time_point updateStart; + std::mutex mtx; +}; +} +} +#endif diff --git a/smartperf_device/device_command/include/sp_csv_util.h b/smartperf_device/device_command/include/sp_csv_util.h new file mode 100644 index 00000000..2778aff9 --- /dev/null +++ b/smartperf_device/device_command/include/sp_csv_util.h @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SP_CSV_UTIL_H +#define SP_CSV_UTIL_H +#include +#include +#include +#include +#include +#include +#include +#include "common.h" +#include "sp_data.h" +#include "sp_utils.h" +#include "sp_task.h" +#include +#include +#include "sp_log.h" +#include "hisysevent.h" +#include +#include +namespace OHOS { +namespace SmartPerf { +class SpCsvUtil { +public: + static void WriteCsv(const std::string &path, std::vector& vmap) + { + std::ofstream outFile; + std::string cmdResult; + SPUtils::LoadCmd(CMD_COMMAND_MAP.at(CmdCommand::USER_PERMISSIONS), cmdResult); + outFile.open(path.c_str(), std::ios::out | std::ios::trunc); + if (SPUtils::GetPathPermissions(path) && outFile.is_open() && path == "/data/local/tmp/data.csv" && + (cmdResult == "root" || cmdResult == "shell")) { + std::string cmd = "chmod 777 " + path; + SPUtils::LoadCmd(cmd, cmdResult); + } + int i = 0; + for (SPData& spdata : vmap) { + std::string lineContent = ""; + for (auto iter = spdata.values.cbegin(); iter != spdata.values.cend(); ++iter) { + lineContent += iter->second + ","; + } + if (i == 0) { + std::string csvTitle = ""; + csvTitle = SetDataCsvTitle(spdata); + csvTitle.pop_back(); + outFile << csvTitle << std::endl; + } + lineContent.pop_back(); + outFile << lineContent << std::endl; + ++i; + } + ReportFileWriteEvent(path); + outFile.close(); + } + static void WriteCsvH(std::map& vmap) + { + const std::string outGeneralPath = "/data/local/tmp/smartperf/1/t_general_info.csv"; + std::ofstream outFile(outGeneralPath, std::ios::out | std::ios::trunc); + if (!outFile.is_open()) { + std::cout << "Error opening file!" << std::endl; + return; + } + for (const auto& [key, value] : vmap) { + outFile << key << "," << value << std::endl; + } + ReportFileWriteEvent(outGeneralPath); + outFile.close(); + } + static std::string SetDataCsvTitle(SPData& spdata) + { + std::string csvTitle = SPTask::GetInstance().GetCsvTitle(); + if (csvTitle.empty()) { + for (auto iter = spdata.values.cbegin(); iter != spdata.values.cend(); ++iter) { + csvTitle += iter->first + ","; + } + } + return csvTitle; + } + + static bool IsUiTestCreatedFile(const std::string &fileName) + { + if (fileName == "t_general_info.csv" || fileName == "t_index_info.csv" || fileName == "data.csv") { + return true; + } + return false; + } + + static uint64_t GetFileSize(const std::string &filePath) + { + struct stat fileStat; + uint64_t fileSize = stat(filePath.c_str(), &fileStat) ? 0 : static_cast(fileStat.st_size); + return fileSize; + } + + static uint64_t GetUiTestCreatedFileSize(const std::string &newFilePath, std::string &dirName) + { + uint64_t createdFileSize = 0; + DIR* dir = opendir(dirName.c_str()); + if (!dir) { + LOGE("Open dir %{public}s failed.", dirName.c_str()); + return createdFileSize; + } + if (newFilePath != "") { + createdFileSize += GetFileSize(newFilePath); + } + struct dirent* file; + while ((file = readdir(dir)) != nullptr) { + if (file->d_type == DT_REG && IsUiTestCreatedFile(file->d_name)) { + std::string filePath = dirName + "/" + file->d_name; + if (filePath != newFilePath) { + createdFileSize += GetFileSize(filePath); + } + } + } + closedir(dir); + return createdFileSize; + } + + static void ReportFileWriteEvent(const std::string &newFilePath) + { + std::string partitionName = "/data"; + std::string dirName = "/data/local/tmp"; + struct statfs partitionStat; + if (statfs(partitionName.c_str(), &partitionStat) != 0) { + LOGE("Get remain partition size failed, partitionName = %{public}s", partitionName.c_str()); + return; + } + constexpr double units = 1024.0; + double remainPartitionSize = (static_cast(partitionStat.f_bfree) / units) * + (static_cast(partitionStat.f_bsize) / units); + uint64_t createdFileSize = GetUiTestCreatedFileSize(newFilePath, dirName); + std::vector filePaths = { dirName }; + std::vector fileSizes = { createdFileSize }; + HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT, "USER_DATA_SIZE", + HiviewDFX::HiSysEvent::EventType::STATISTIC, + "COMPONENT_NAME", "SP_daemon", + "PARTITION_NAME", partitionName, + "REMAIN_PARTITION_SIZE", remainPartitionSize, + "FILE_OR_FOLDER_PATH", filePaths, + "FILE_OR_FOLDER_SIZE", fileSizes); + + LOGD("partitionName = %s", partitionName.c_str()); + LOGD("remainPartitionSize = %lld", remainPartitionSize); + } +}; +} +} + +#endif // SP_CSV_UTILS_H diff --git a/smartperf_device/device_command/include/sp_data.h b/smartperf_device/device_command/include/sp_data.h new file mode 100644 index 00000000..9ab8f77c --- /dev/null +++ b/smartperf_device/device_command/include/sp_data.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SP_DATA_H +#define SP_DATA_H +#include +#include +namespace OHOS { +namespace SmartPerf { +class SPData { +public: + std::map values; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/include/sp_profiler.h b/smartperf_device/device_command/include/sp_profiler.h new file mode 100644 index 00000000..2b39d346 --- /dev/null +++ b/smartperf_device/device_command/include/sp_profiler.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SP_PROFILER_H +#define SP_PROFILER_H +#include +namespace OHOS { +namespace SmartPerf { +class SpProfiler { +public: + SpProfiler() {}; + virtual ~SpProfiler() {}; + virtual std::map ItemData() = 0; + virtual void StartExecutionOnce(bool isPause) {}; + virtual void FinishtExecutionOnce(bool isPause) {}; + std::function ipcCallback_ {nullptr}; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/interface/GameEventCallback.h b/smartperf_device/device_command/interface/GameEventCallback.h new file mode 100644 index 00000000..d2c35610 --- /dev/null +++ b/smartperf_device/device_command/interface/GameEventCallback.h @@ -0,0 +1,30 @@ +/* +* Copyright (C) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GAME_EVENT_CALLBACK_H +#define GAME_EVENT_CALLBACK_H + +#include +namespace OHOS { + namespace SmartPerf { + class GameEventCallback { + public: + GameEventCallback() = default; + virtual ~GameEventCallback() = default; + virtual void OnGameEvent(int32_t type, std::map ¶ms) = 0; + }; + } +} + +#endif //GAMEEVENTCALLBACK_H diff --git a/smartperf_device/device_command/interface/GameServicePlugin.h b/smartperf_device/device_command/interface/GameServicePlugin.h new file mode 100644 index 00000000..1ecd8e5a --- /dev/null +++ b/smartperf_device/device_command/interface/GameServicePlugin.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef GAME_SERVICE_PLUGIN_H +#define GAME_SERVICE_PLUGIN_H + +#include +#include +#include "GameEventCallback.h" +#include "GpuCounterCallback.h" + +namespace OHOS { + namespace SmartPerf { + class GameServicePlugin { + public: + uint32_t version; + const char *pluginName; + + virtual int32_t StartGetGpuPerfInfo(int64_t duration, int64_t collectDur, + std::unique_ptr callback) = 0; + virtual int32_t StopGetGpuPerfInfo() = 0; + virtual std::map GetSystemFunctionStatus( + std::map &queryParams) = 0; + virtual int32_t RegisterGameEventListener(std::unique_ptr callback) = 0; + virtual int32_t UnregisterGameEventListener() = 0; + }; + } +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/interface/GpuCounterCallback.h b/smartperf_device/device_command/interface/GpuCounterCallback.h new file mode 100644 index 00000000..eb03020a --- /dev/null +++ b/smartperf_device/device_command/interface/GpuCounterCallback.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2024 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GPU_COUNTER_CALLBACK_H +#define GPU_COUNTER_CALLBACK_H +#include "vector" + +namespace OHOS { + namespace SmartPerf { + struct GpuPerfInfo { + int64_t remainTime = 0; + int64_t startTime = 0; + int32_t duration = 0; + uint32_t gpuActive = 0; + uint32_t drawCalls = 0; + uint64_t primitives = 0; + uint64_t vertexCounts = 0; + uint64_t totalInstruments = 0; + uint32_t gpuLoadPercentage = 0; + uint32_t vertexLoadPercentage = 0; + uint32_t fragmentLoadPercentage = 0; + uint32_t computeLoadPercentage = 0; + uint32_t textureLoadPercentage = 0; + uint32_t memoryReadBandwidth = 0; + uint32_t memoryWriteBandwidth = 0; + uint32_t memoryBandwidthPercentage = 0; + }; + + class GpuCounterCallback { + public: + GpuCounterCallback() = default; + virtual ~GpuCounterCallback() = default; + virtual int OnGpuData(std::vector &gpuPerfInfos) = 0; + }; + + class GpuCounterCallbackImpl : public GpuCounterCallback { + public: + GpuCounterCallbackImpl(); + int OnGpuData(std::vector &gpuPerfInfos) override; + + private: + void GetRealTime(GpuPerfInfo *newData); + void JoinSocketDataValue(GpuPerfInfo *newData); + unsigned long long JoinSocketDataPercentFunction(uint32_t itemFirst, int32_t durationFirst, + uint32_t itemSecond, int32_t durationSecond) const; + void JoinSocketDataPercent(GpuPerfInfo *newData); + void JoinSocketData(GpuPerfInfo *newData); + unsigned long long SplitSocketDataValueFunction(uint32_t value, int32_t interval, int32_t duration) const; + void SplitSocketDataValue(int32_t interval); + void SplitSocketDataPercent(); + void SplitSocketData(); + std::string GetGpuPerfInfoItem(const GpuPerfInfo *itemData) const; + std::vector gpuCounter; + const long long collectInterval = 50; + const int64_t maxTime = 10800000; + const int64_t restartTime = 300000; + const int32_t maxDuration = 1000; + GpuPerfInfo realtimeGpuPerfInfoData; + }; + } +} + +#endif -- Gitee