From 472e6a95980a6a16407a6eb5d85556cdf4c69d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=9B=BD=E4=BA=AE?= Date: Fri, 5 Sep 2025 15:08:49 +0800 Subject: [PATCH] =?UTF-8?q?GC=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 牛国亮 --- .../collector/include/GpuCounter.h | 6 +++--- .../collector/src/GpuCounter.cpp | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/smartperf_device/device_command/collector/include/GpuCounter.h b/smartperf_device/device_command/collector/include/GpuCounter.h index c510a0ef1..2756f919f 100644 --- a/smartperf_device/device_command/collector/include/GpuCounter.h +++ b/smartperf_device/device_command/collector/include/GpuCounter.h @@ -59,12 +59,12 @@ namespace OHOS { void SetIsPause(bool isPause); std::map GetGpuRealtimeData(); private: - GpuCounter() {}; + GpuCounter(); GpuCounter(const GpuCounter &); GpuCounter &operator = (const GpuCounter &); GcStatus gcStatus = GC_INIT; - std::vector gpuCounterData; - std::vector gpuCounterSaveReportData; + std::unique_ptr> gpuCounterData; + std::unique_ptr> gpuCounterSaveReportData; std::mutex realtimeDataLock; std::mutex gpuCounterLock; std::string gpuCounterRealtimeData; diff --git a/smartperf_device/device_command/collector/src/GpuCounter.cpp b/smartperf_device/device_command/collector/src/GpuCounter.cpp index 86ed8c043..56dc91a3d 100644 --- a/smartperf_device/device_command/collector/src/GpuCounter.cpp +++ b/smartperf_device/device_command/collector/src/GpuCounter.cpp @@ -27,6 +27,10 @@ namespace OHOS { namespace SmartPerf { + GpuCounter::GpuCounter() + : gpuCounterData(std::make_unique>()), + gpuCounterSaveReportData(std::make_unique>()) {} + std::map GpuCounter::ItemData() { std::map gpuCounterDataMap; @@ -45,7 +49,7 @@ namespace OHOS { SaveData(savePathDirectory_); StopCollect(); if (!isPause_) { - gpuCounterData.clear(); + gpuCounterData->clear(); } } @@ -81,7 +85,7 @@ namespace OHOS { if (type == GC_START && gcStatus == GC_INIT) { if (!isPause_) { - gpuCounterData.clear(); + gpuCounterData->clear(); gpuCounterRealtimeData.clear(); } int ret = servicePlugin()->StartGetGpuPerfInfo(duration, frequency, std::move(gpuCounterCallback)); @@ -104,7 +108,7 @@ namespace OHOS { { // device与editor采集都会走tcp stop时的SaveData,但是deivce同时会走FinishtExecutionOnce导致SaveData执行两次 // 目前device在第一次保存数据后会清空,第二次SaveData实际不生效 - if (gcStatus != GC_RUNNING || gpuCounterData.size() <= 0 || path.empty()) { + if (gcStatus != GC_RUNNING || gpuCounterData->size() <= 0 || path.empty()) { return; } savePathDirectory_ = path; @@ -137,27 +141,27 @@ namespace OHOS { "memoryBandwidthPercentage\r"; outFile << title << std::endl; std::unique_lock lock(realtimeDataLock); - for (unsigned int i = 0; i < gpuCounterSaveReportData.size() - 1; i++) { - outFile << gpuCounterSaveReportData[i] << std::endl; + for (const auto& data : *gpuCounterSaveReportData) { + outFile << data << std::endl; } outFile.close(); } std::vector &GpuCounter::GetGpuCounterData() { - return gpuCounterData; + return *gpuCounterData; } std::vector &GpuCounter::GetGpuCounterSaveReportData() { - return gpuCounterSaveReportData; + return *gpuCounterSaveReportData; } std::map GpuCounter::GetGpuRealtimeData() { std::unique_lock lock(realtimeDataLock); std::map gpuCounterDataMap = {}; - if (gpuCounterRealtimeData.size() > 0) { + if (!gpuCounterRealtimeData.empty()) { gpuCounterDataMap.insert({"gpuCounterData", gpuCounterRealtimeData}); gpuCounterRealtimeData.clear(); } -- Gitee