diff --git a/smartperf_device/device_command/collector/include/GpuCounter.h b/smartperf_device/device_command/collector/include/GpuCounter.h index c510a0ef17b6a978e7543b7a6343fce1f02ee811..2756f919fde6cc619219ee7f2347c1b75ee36d1a 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 86ed8c0439ed8c1eef169107342c43f7db391378..56dc91a3d26f77c913ba6492751b89e955d009d5 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(); }