diff --git a/smartperf_device/device_command/colltector/include/AI_schedule.h b/smartperf_device/device_command/colltector/include/AI_schedule.h new file mode 100644 index 0000000000000000000000000000000000000000..a797ea803936fb0571aa1b23a2199ff45d0187c1 --- /dev/null +++ b/smartperf_device/device_command/colltector/include/AI_schedule.h @@ -0,0 +1,45 @@ +/* + * 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 AI_SCHEDULE_H +#define AI_SCHEDULE_H +#include "sp_profiler.h" +#include + +namespace OHOS { +namespace SmartPerf { +class AISchedule : public SpProfiler { + public: + std::map ItemData() override; + static AISchedule &GetInstance() + { + static AISchedule instance; + return instance; + } + void SetProcessId(const std::string &pid); + + private: + AISchedule() {}; + AISchedule(const AISchedule &) = delete; + AISchedule &operator=(const AISchedule &) = delete; + std::map aiScheduleParams; + const std::string aiScheduleParamPid = "pid"; + const std::string aiScheduleParamType = "functionType"; + const std::string createPlugin = "onCreatePlugin"; + std::string processId = ""; +}; +} // namespace SmartPerf +} // namespace OHOS +#endif // AI_SCHEDULE_H \ No newline at end of file diff --git a/smartperf_device/device_command/colltector/include/ByTrace.h b/smartperf_device/device_command/colltector/include/ByTrace.h new file mode 100644 index 0000000000000000000000000000000000000000..f58a6b29345b8ecd97c068fbbd851a00ec91c8fd --- /dev/null +++ b/smartperf_device/device_command/colltector/include/ByTrace.h @@ -0,0 +1,61 @@ +/* + * 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 BY_TRACE_H +#define BY_TRACE_H +#include "common.h" +namespace OHOS { +namespace SmartPerf { +class ByTrace { +public: + static ByTrace &GetInstance() + { + static ByTrace instance; + return instance; + } + // trace配置 + void SetTraceConfig(int mSum, int mInterval, long long mThreshold, int mLowfps, int mCurNum) const; + // 开始抓trace线程 + void ThreadGetTrace() const; + // 校验fps-jitters + TraceStatus CheckFpsJitters(std::vector& jitters, int cfps) const; + // 触发trace + void TriggerCatch(long long curTime) const; + bool CheckHitraceId() const; + +private: + ByTrace() {}; + ByTrace(const ByTrace &); + ByTrace &operator = (const ByTrace &); + + // 抓trace总次数 默认2次 + mutable int sum = 2; + // 当前触发的次数 + mutable int curNum = 1; + // 抓trace间隔(两次抓取的间隔时间 默认60*1000 ms) + mutable int interval = 60000; + // 抓trace触发条件:默认 某一帧的某个jitter>100 ms触发 + mutable long long threshold = 100; + // 上一次触发时间 + mutable long long lastTriggerTime = -1; + // 当前是否触发 + mutable long long currentTrigger = -1; + // 低帧触发 + mutable int lowfps = -1; + // 前2秒采的不准 + mutable int times = 0; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/colltector/include/CPU.h b/smartperf_device/device_command/colltector/include/CPU.h new file mode 100644 index 0000000000000000000000000000000000000000..9ff8cb9bfe33315592fdce24476306d3e868ed03 --- /dev/null +++ b/smartperf_device/device_command/colltector/include/CPU.h @@ -0,0 +1,66 @@ +/* + * 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 CPU_H +#define CPU_H +#include +#include +#include "sp_profiler.h" +namespace OHOS { +namespace SmartPerf { +struct CpuFreqs { + uint32_t cpuId = 0; + uint32_t curFreq = 0; +}; +struct CpuUsageInfos { + std::string cpuId; + double userUsage = 0; + double niceUsage = 0; + double systemUsage = 0; + double idleUsage = 0; + double ioWaitUsage = 0; + double irqUsage = 0; + double softIrqUsage = 0; +}; + +class CPU : public SpProfiler { +public: + static CPU &GetInstance() + { + static CPU instance; + return instance; + } + std::map ItemData() override; + std::vector GetCpuFreq(); + std::vector GetCpuUsage(); + std::map GetSysProcessCpuLoad() const; + void GetSysProcessCpuLoadContinue(std::map &processCpuInfo) const; + void GetSysChildProcessCpuLoad(size_t processIdSize, std::map &processCpuInfo) const; + void SetPackageName(const std::string &pName); + void SetProcessId(const std::string &pid); + +private: + CPU() {}; + CPU(const CPU &); + CPU &operator = (const CPU &); + std::string packageName = ""; + std::vector processId; + const std::string cpustr = "cpu"; + const std::string totalcpu = "Totalcpu"; + int twenty = 20; + int thousand = 1000; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/colltector/include/Capture.h b/smartperf_device/device_command/colltector/include/Capture.h new file mode 100644 index 0000000000000000000000000000000000000000..675f0557cf11cf9d3fadf7e51de71a86cd017ba6 --- /dev/null +++ b/smartperf_device/device_command/colltector/include/Capture.h @@ -0,0 +1,48 @@ +/* + * 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 CAPTURE_H +#define CAPTURE_H +#include "sp_profiler.h" +namespace OHOS { +namespace SmartPerf { +class Capture : public SpProfiler { +public: + std::map ItemData() override; + static Capture &GetInstance() + { + static Capture instance; + return instance; + } + // 截图线程 + void ThreadGetCatch(); + void ThreadGetCatchSocket(); + // 触发线程 + void TriggerGetCatch(); + void TriggerGetCatchSocket(); + bool TakeScreenCap(const std::string &savePath) const; + void SetCollectionNum(); + long long GetCurTimes(); + void SocketMessage(); +private: + Capture() {}; + Capture(const Capture &); + Capture &operator = (const Capture &); + bool isSocketMessage = false; + int callNum = 0; + long long curTime = 0.0; +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/colltector/include/DDR.h b/smartperf_device/device_command/colltector/include/DDR.h new file mode 100644 index 0000000000000000000000000000000000000000..71fb27289131ef6709b318006c7f1a89e05e3bfb --- /dev/null +++ b/smartperf_device/device_command/colltector/include/DDR.h @@ -0,0 +1,41 @@ +/* + * 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 DDR_H +#define DDR_H +#include "sp_profiler.h" +namespace OHOS { +namespace SmartPerf { +class DDR : public SpProfiler { +public: + long long GetDdrFreq(); + static DDR &GetInstance() + { + static DDR instance; + return instance; + } + std::map ItemData() override; + void SetRkFlag(); + +private: + DDR() {}; + DDR(const DDR &); + DDR &operator = (const DDR &); + std::string ddrCurFreqPath = "/sys/class/devfreq/ddrfreq/cur_freq"; + std::string ddrCurFreqRkPath = "/sys/class/devfreq/fde60000.gpu/available_frequencies"; + bool rkFlag = false; +}; +}; +} +#endif diff --git a/smartperf_device/device_command/colltector/include/Dubai.h b/smartperf_device/device_command/colltector/include/Dubai.h new file mode 100644 index 0000000000000000000000000000000000000000..2fe3e6484f178ec725930bfcfb481ea0a132d0d3 --- /dev/null +++ b/smartperf_device/device_command/colltector/include/Dubai.h @@ -0,0 +1,47 @@ +/* + * 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 DUBAI_H +#define DUBAI_H +#include +namespace OHOS { +namespace SmartPerf { +class Dubai { +public: + static Dubai &GetInstance() + { + static Dubai instance; + return instance; + } + // dubai db转移smartperf 沙箱 + static void MoveDubaiDb(); + // testsa自拉起SP db文件转移到local + static void MoveDubaiDb(const std::string &path); + // dubai -b + static void DumpDubaiBegin(); + // dubai -f + static void DumpDubaiFinish(); + static void CallBeginAndFinish(); + static std::string CallMoveDubaiDbFinished(); + static bool IsFileAccessible(const std::string &filename); + static inline std::string dubaiPkgName = " "; + static inline bool isDumpDubaiFinish = false; +private: + Dubai() {}; + Dubai(const Dubai &); + Dubai &operator = (const Dubai &); +}; +} +} +#endif \ No newline at end of file diff --git a/smartperf_device/device_command/colltector/include/FPS.h b/smartperf_device/device_command/colltector/include/FPS.h new file mode 100644 index 0000000000000000000000000000000000000000..6dfc0c980b46ae2d0dcec6036763a2fac468ea9f --- /dev/null +++ b/smartperf_device/device_command/colltector/include/FPS.h @@ -0,0 +1,167 @@ +/* + * 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 FPS_H +#define FPS_H +#include +#include +#include "sp_profiler.h" +namespace OHOS { +namespace SmartPerf { +struct FpsInfo { + int fps; + std::vector jitters; + std::vector currTimeStamps; + std::vector currDumpTimeStamps; + int curTime; + long long currTimeDiff; + long long currTimeDump; + void Clear() + { + fps = 0; + curTime = 0; + currTimeDiff = 0; + jitters.clear(); + } + bool operator == (const FpsInfo &other) const + { + if (fps != other.fps) { + return false; + } + if (jitters.size() != other.jitters.size()) { + return false; + } + for (size_t i = 0; i < jitters.size(); i++) { + if (jitters[i] != other.jitters[i]) { + return false; + } + } + return true; + } + FpsInfo() + { + fps = 0; + curTime = 0; + currTimeDiff = 0; + currTimeDump = 0; + } +}; +struct FpsCurrentFpsTime { + int fps = 0; + long long currentFpsTime = 0; +}; + +class FPS : public SpProfiler { +public: + void SetPackageName(const std::string& pName); + void SetLayerName(const std::string& sName); + FpsInfo GetFpsInfo(); + FpsInfo GetDiffLayersFpsInfo(const std::string &sName); + FpsInfo GetChangedLayerFps(); + bool CalcFpsAndJitters(bool isBreak); + long long CalculateJitter() const; + FpsInfo fpsInfo; + FpsInfo fpsInfoData; + FpsInfo prevResultFpsInfo; + static FPS &GetInstance() + { + static FPS instance; + return instance; + } + std::map ItemData() override; + void StartExecutionOnce(bool isPause) override; + void SetFpsCurrentFpsTime(FpsInfo fpsInfoResult); + FpsCurrentFpsTime GetFpsCurrentFpsTime(); + void ReadDataFromPipe(int fd); + void SetProcessId(const std::string &pid); + void SetRkFlag(); + std::string FindFpsRefreshrate(); + std::string GetHardenRefreshrate(std::string &screenInfo) const; + void CalcJitters(); + static inline bool isGameApp = false; + static inline bool isNeedDump = false; + static inline bool isPreset = false; + static inline bool isLowCurFps = false; + static inline bool isHistoryHap = false; + bool SetOtherDeviceFlag(); + bool hapLowFpsFlag = false; + bool hapNeedCatonInfo = false; + int catonNum = 0; + void CalcFatalCaton(std::vector& jitters); + void GetGameScenStatus(); + FpsInfo GetFpsInfoByDump(const std::string& name); + FpsInfo GetFpsInfoByRs(const std::string& name); + std::map GetFpsAndJitters(FpsInfo &fpsInfoResult, + std::map &result); + void SetTraceCatch(); + std::string GetGameLayer(); + std::string GetLayerName(std::string &gameLayer, uint64_t &nodeId, const std::string& line, size_t &endPos); + std::string GetSurfaceId(std::string &gameLayer, uint64_t &nodeId, const std::string &surfaceId, + const std::string& line, size_t &endPos); + FpsInfo GetAppFps(std::string &uniteLayer); + + // sections + void GetOhFps(std::vector& v); + void GetTimeDiff(); + void GetResultFPS(int sectionsNum); + void GetSectionsFps(FpsInfo &fpsInfoResult, int nums) const; + void PrintSections(int msCount, long long currTimeLast, long long currTimeStart, long long currLastTime) const; + void GetSectionsPrint(int printCount, long long msStartTime, int numb, long long harTime) const; + void GetFPS(std::vector& v); +private: + FPS() {}; + FPS(const FPS &); + FPS &operator = (const FPS &); + + std::string pkgName; + std::string surfaceViewName; + bool refresh = false; + long long mod = 1e9; + long long curScreenTimestamp = 0; + long long prevScreenTimestamp = -1; + long long prevlastScreenTimestamp = 0; + int fpsNum = 0; + FpsInfo GetSurfaceFrame(const std::string& name); + int fifty = 50; + int hundred = 100; + FpsCurrentFpsTime ffTime; + bool processFlag = false; + bool rkFlag = false; + const std::string screenPath = "/sys/class/graphics/fb0/lcd_fps_scence"; + std::string processId = ""; + std::string gameLayerName; + bool isOtherDevice = false; + int inGameSceneNum = 0; + int eleven = 11; + + int num = 1; + int number = 2; + bool ohFlag = false; + int four = 4; + int ten = 10; + long long lastCurrTime = 0; + long long msClear = 1000000000; + long oneSec = 1000000; + long long oneThousand = 1000; + long long currRealTime = 0; + unsigned long sleepTime = 950000; + unsigned long sleepNowTime = 10000; + + bool isSections = false; + int isCatchTrace = 0; + std::string nodeIdStr = ""; +}; +} +} +#endif diff --git a/smartperf_device/device_command/colltector/include/FileDescriptor.h b/smartperf_device/device_command/colltector/include/FileDescriptor.h new file mode 100644 index 0000000000000000000000000000000000000000..b43306c29de71e82810b4c25bb120f43d5eeff2c --- /dev/null +++ b/smartperf_device/device_command/colltector/include/FileDescriptor.h @@ -0,0 +1,45 @@ +/* + * 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 FILEDRECRIOTOR +#define FILEDRECRIOTOR +#include +#include "sp_profiler.h" +namespace OHOS { +namespace SmartPerf { +class FileDescriptor : public SpProfiler { +public: + std::map ItemData() override; + static FileDescriptor &GetInstance() + { + static FileDescriptor instance; + return instance; + } + + void GetFds(const std::string &pid, std::string &fds, std::string &fdTotal); + void SetPackageName(const std::string &pName); + void SetProcessId(const std::string &pid); + void SetProcessIdForFuzzTest(const std::vector &pid); +private: + FileDescriptor() {}; + FileDescriptor(const FileDescriptor &); + FileDescriptor &operator = (const FileDescriptor &); + bool rkFlag = false; + std::string packageName = ""; + std::vector processId; + size_t idNum = 0; +}; +} +} +#endif diff --git a/smartperf_device/device_command/colltector/include/cpu_info.h b/smartperf_device/device_command/colltector/include/cpu_info.h new file mode 100644 index 0000000000000000000000000000000000000000..044823218a565c322b9628ab8e6a896f907f0513 --- /dev/null +++ b/smartperf_device/device_command/colltector/include/cpu_info.h @@ -0,0 +1,52 @@ +/* + * 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 CPU_INFO_H +#define CPU_INFO_H + +#include "sp_profiler.h" +#include +#include +#include +#include +#include +#include + +namespace OHOS::SmartPerf { +class CPUInfo : public SpProfiler { +public: + static CPUInfo &GetInstance() + { + static CPUInfo instance; + return instance; + } + std::map ItemData() override; + void StartExecutionOnce(bool isPause) override; + void FinishtExecutionOnce(bool isPause) override; + void SetPids(const std::string& pids); + void Start(); + void Stop(); +private: + std::vector pids_; + std::thread th_; + std::string hiperfCmd_; + std::atomic_bool running_ {false}; + std::condition_variable cond_; + std::mutex mtx_; + std::string buffer_; +}; +} + +#endif // CPU_INFO_H \ No newline at end of file diff --git a/smartperf_device/device_command/colltector/include/effective.h b/smartperf_device/device_command/colltector/include/effective.h new file mode 100644 index 0000000000000000000000000000000000000000..8cd781f4a4bfae212e1848b466dc457566d5eed4 --- /dev/null +++ b/smartperf_device/device_command/colltector/include/effective.h @@ -0,0 +1,112 @@ +/* + * 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 EFFECTIVE_H +#define EFFECTIVE_H + +#include "sp_profiler.h" +#include +#include +#include + +namespace OHOS::SmartPerf { +class Effective : public SpProfiler { +public: + static Effective &GetInstance() + { + static Effective instance; + return instance; + } + std::map ItemData() override; + int fps_ {0}; + long long frameTime_ {LLONG_MAX}; + +private: + bool CheckCounterId(); + std::thread ThreadGetHiperf(long long timeStamp); + void GetHiperf(const std::string &traceName); + std::string SetHiperf(const std::string &traceName); + + int64_t startCaptuerTime_ {0}; + int requestId_ {1}; + std::string strOne_ = R"(hiprofiler_cmd \ + -c - \ + -o /data/local/tmp/)"; + std::string strTwo_ = R"(.htrace \ + -t 5 \ + -s \ + -k \ + <