280 lines
11 KiB
Diff
280 lines
11 KiB
Diff
From 5a961d309e0286d23f196e7afeab486a74bd09da Mon Sep 17 00:00:00 2001
|
|
From: fly_1997 <flylove7@outlook.com>
|
|
Date: Wed, 25 Dec 2024 15:19:15 +0800
|
|
Subject: [PATCH 4/7] fix memory leak, plugin type
|
|
|
|
---
|
|
src/common/data_register.cpp | 1 +
|
|
src/common/data_register.h | 2 +-
|
|
src/plugin/collect/docker/docker_adapt.cpp | 15 +++++++--------
|
|
src/plugin/collect/docker/docker_adapt.h | 2 +-
|
|
src/plugin/collect/pmu/pmu_common.cpp | 2 ++
|
|
src/plugin/collect/pmu/pmu_counting_collector.cpp | 3 ++-
|
|
src/plugin/collect/pmu/pmu_sampling_collector.cpp | 3 ++-
|
|
src/plugin/collect/pmu/pmu_uncore.cpp | 2 +-
|
|
src/plugin/collect/pmu/pmu_uncore_collector.cpp | 1 +
|
|
src/plugin/collect/system/thread_collector.cpp | 5 +++++
|
|
src/plugin/tune/docker/cpu_burst.cpp | 12 ++++++------
|
|
src/plugin/tune/docker/cpu_burst_adapt.cpp | 2 +-
|
|
src/plugin/tune/unixbench/ub_tune.cpp | 1 +
|
|
13 files changed, 31 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/src/common/data_register.cpp b/src/common/data_register.cpp
|
|
index df64ba5..f93556a 100644
|
|
--- a/src/common/data_register.cpp
|
|
+++ b/src/common/data_register.cpp
|
|
@@ -152,6 +152,7 @@ void PmuBaseDataFree(void *data)
|
|
PmuDataFree(tmpData->pmuData);
|
|
tmpData->pmuData = nullptr;
|
|
tmpData->len = 0;
|
|
+ delete tmpData;
|
|
}
|
|
|
|
int PmuCountingDataSerialize(const void *data, OutStream &out)
|
|
diff --git a/src/common/data_register.h b/src/common/data_register.h
|
|
index 2804ef5..477811e 100644
|
|
--- a/src/common/data_register.h
|
|
+++ b/src/common/data_register.h
|
|
@@ -21,7 +21,7 @@ using SerializeFunc = int(*)(const void*, OutStream &out);
|
|
using DataFreeFunc = void(*)(void *);
|
|
|
|
struct RegisterEntry {
|
|
- RegisterEntry() { }
|
|
+ RegisterEntry() : se(nullptr), de(nullptr), free(nullptr) { }
|
|
RegisterEntry(const SerializeFunc &se, const DeserializeFunc &de) : se(se), de(de), free(nullptr) { }
|
|
RegisterEntry(const SerializeFunc &se, const DeserializeFunc &de, const DataFreeFunc &free) : se(se),
|
|
de(de), free(free) { }
|
|
diff --git a/src/plugin/collect/docker/docker_adapt.cpp b/src/plugin/collect/docker/docker_adapt.cpp
|
|
index eab3270..1105db2 100644
|
|
--- a/src/plugin/collect/docker/docker_adapt.cpp
|
|
+++ b/src/plugin/collect/docker/docker_adapt.cpp
|
|
@@ -45,6 +45,7 @@ DockerAdapt::DockerAdapt()
|
|
version = "1.0.0";
|
|
period = PERIOD;
|
|
priority = PRIORITY;
|
|
+ type = 0;
|
|
|
|
oeaware::Topic topic;
|
|
topic.instanceName = this->name;
|
|
@@ -97,7 +98,7 @@ void DockerAdapt::Run()
|
|
dataList.data = new void* [containers.size()];
|
|
uint64_t i = 0;
|
|
for (auto &it : containers) {
|
|
- dataList.data[i++] = it.second;
|
|
+ dataList.data[i++] = &it.second;
|
|
}
|
|
dataList.len = i;
|
|
Publish(dataList);
|
|
@@ -108,8 +109,6 @@ void DockerAdapt::DockerUpdate(const std::unordered_set<std::string> &directorie
|
|
// delete non-existent container
|
|
for (auto it = containers.begin(); it != containers.end();) {
|
|
if (directories.find(it->first) == directories.end()) {
|
|
- delete it->second;
|
|
- it->second = nullptr;
|
|
it = containers.erase(it);
|
|
} else {
|
|
++it;
|
|
@@ -123,11 +122,11 @@ void DockerAdapt::DockerUpdate(const std::unordered_set<std::string> &directorie
|
|
read_success &= GetContainersInfo(tmp.cfs_quota_us, dir, "cpu.cfs_quota_us");
|
|
read_success &= GetContainersInfo(tmp.cfs_burst_us, dir, "cpu.cfs_burst_us");
|
|
if (read_success) {
|
|
- Container* container = new Container();
|
|
- container->cfs_period_us = tmp.cfs_period_us;
|
|
- container->cfs_quota_us = tmp.cfs_quota_us;
|
|
- container->cfs_burst_us = tmp.cfs_burst_us;
|
|
- container->id = dir;
|
|
+ Container container;
|
|
+ container.cfs_period_us = tmp.cfs_period_us;
|
|
+ container.cfs_quota_us = tmp.cfs_quota_us;
|
|
+ container.cfs_burst_us = tmp.cfs_burst_us;
|
|
+ container.id = dir;
|
|
containers[dir] = container;
|
|
}
|
|
}
|
|
diff --git a/src/plugin/collect/docker/docker_adapt.h b/src/plugin/collect/docker/docker_adapt.h
|
|
index 570a2a7..9db9c00 100644
|
|
--- a/src/plugin/collect/docker/docker_adapt.h
|
|
+++ b/src/plugin/collect/docker/docker_adapt.h
|
|
@@ -33,6 +33,6 @@ private:
|
|
void DockerUpdate(const std::unordered_set<std::string> &sub_dir);
|
|
void DockerCollect();
|
|
bool openStatus = false;
|
|
- std::unordered_map<std::string, Container*> containers;
|
|
+ std::unordered_map<std::string, Container> containers;
|
|
};
|
|
#endif // OEAWARE_MANAGER_DOCKER_ADAPT_H
|
|
\ No newline at end of file
|
|
diff --git a/src/plugin/collect/pmu/pmu_common.cpp b/src/plugin/collect/pmu/pmu_common.cpp
|
|
index caf453a..28c71f0 100644
|
|
--- a/src/plugin/collect/pmu/pmu_common.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_common.cpp
|
|
@@ -26,8 +26,10 @@ bool IsSupportPmu()
|
|
while (dent = readdir(dir)) {
|
|
std::string armPmuPath = DEVICES_PATH + dent->d_name + "/cpus";
|
|
if (oeaware::FileExist(armPmuPath)) {
|
|
+ closedir(dir);
|
|
return true;
|
|
}
|
|
}
|
|
+ closedir(dir);
|
|
return false;
|
|
}
|
|
diff --git a/src/plugin/collect/pmu/pmu_counting_collector.cpp b/src/plugin/collect/pmu/pmu_counting_collector.cpp
|
|
index 281c61d..2b6c0b5 100644
|
|
--- a/src/plugin/collect/pmu/pmu_counting_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_counting_collector.cpp
|
|
@@ -62,6 +62,7 @@ int PmuCountingCollector::OpenCounting(const oeaware::Topic &topic)
|
|
errno_t ret = strcpy_s(evtList[0], topic.topicName.length() + 1, topic.topicName.c_str());
|
|
if (ret != EOK) {
|
|
std::cout << topic.topicName << " open failed, reason: strcpy_s failed" << std::endl;
|
|
+ delete[] evtList[0];
|
|
return -1;
|
|
}
|
|
attr.evtList = evtList;
|
|
@@ -71,7 +72,7 @@ int PmuCountingCollector::OpenCounting(const oeaware::Topic &topic)
|
|
if (pd == -1) {
|
|
std::cout << topic.topicName << " open failed" << std::endl;
|
|
}
|
|
-
|
|
+ delete[] evtList[0];
|
|
return pd;
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/pmu/pmu_sampling_collector.cpp b/src/plugin/collect/pmu/pmu_sampling_collector.cpp
|
|
index b4cf037..6d4712e 100644
|
|
--- a/src/plugin/collect/pmu/pmu_sampling_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_sampling_collector.cpp
|
|
@@ -60,6 +60,7 @@ int PmuSamplingCollector::OpenSampling(const oeaware::Topic &topic)
|
|
errno_t ret = strcpy_s(evtList[0], topic.topicName.length() + 1, topic.topicName.c_str());
|
|
if (ret != EOK) {
|
|
std::cout << topic.topicName << " open failed, reason: strcpy_s failed" << std::endl;
|
|
+ delete[] evtList[0];
|
|
return -1;
|
|
}
|
|
attr.evtList = evtList;
|
|
@@ -75,7 +76,7 @@ int PmuSamplingCollector::OpenSampling(const oeaware::Topic &topic)
|
|
if (pd == -1) {
|
|
std::cout << topic.topicName << " open failed" << std::endl;
|
|
}
|
|
-
|
|
+ delete[] evtList[0];
|
|
return pd;
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/pmu/pmu_uncore.cpp b/src/plugin/collect/pmu/pmu_uncore.cpp
|
|
index cf46121..66a6bf3 100644
|
|
--- a/src/plugin/collect/pmu/pmu_uncore.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_uncore.cpp
|
|
@@ -128,7 +128,7 @@ int HhaUncoreConfigInit(void)
|
|
static void UncoreConfigFree(UncoreConfig *config)
|
|
{
|
|
if (config != nullptr) {
|
|
- delete config;
|
|
+ delete[] config;
|
|
config = nullptr;
|
|
}
|
|
}
|
|
diff --git a/src/plugin/collect/pmu/pmu_uncore_collector.cpp b/src/plugin/collect/pmu/pmu_uncore_collector.cpp
|
|
index 74c2901..3a2571f 100644
|
|
--- a/src/plugin/collect/pmu/pmu_uncore_collector.cpp
|
|
+++ b/src/plugin/collect/pmu/pmu_uncore_collector.cpp
|
|
@@ -145,6 +145,7 @@ void PmuUncoreCollector::CloseTopic(const oeaware::Topic &topic)
|
|
}
|
|
PmuDisable(pmuId);
|
|
PmuClose(pmuId);
|
|
+ UncoreConfigFini();
|
|
pmuId = -1;
|
|
}
|
|
|
|
diff --git a/src/plugin/collect/system/thread_collector.cpp b/src/plugin/collect/system/thread_collector.cpp
|
|
index 10dfd27..f3439b6 100644
|
|
--- a/src/plugin/collect/system/thread_collector.cpp
|
|
+++ b/src/plugin/collect/system/thread_collector.cpp
|
|
@@ -20,6 +20,7 @@
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <securec.h>
|
|
+#include "data_register.h"
|
|
|
|
ThreadCollector::ThreadCollector()
|
|
{
|
|
@@ -28,6 +29,7 @@ ThreadCollector::ThreadCollector()
|
|
version = "1.0.0";
|
|
period = 500;
|
|
priority = 0;
|
|
+ type = 0;
|
|
oeaware::Topic topic;
|
|
topic.instanceName = this->name;
|
|
topic.topicName = this->name;
|
|
@@ -61,6 +63,9 @@ oeaware::Result ThreadCollector::Enable(const std::string ¶m)
|
|
void ThreadCollector::Disable()
|
|
{
|
|
openStatus = false;
|
|
+ for (auto &item : threads) {
|
|
+ oeaware::Register::GetInstance().GetDataFreeFunc(OE_THREAD_COLLECTOR)(item.second);
|
|
+ }
|
|
}
|
|
|
|
void ThreadCollector::Run()
|
|
diff --git a/src/plugin/tune/docker/cpu_burst.cpp b/src/plugin/tune/docker/cpu_burst.cpp
|
|
index c351684..6c100b7 100644
|
|
--- a/src/plugin/tune/docker/cpu_burst.cpp
|
|
+++ b/src/plugin/tune/docker/cpu_burst.cpp
|
|
@@ -91,10 +91,10 @@ void CpuBurst::UpdatePmu(const DataList &dataList)
|
|
|
|
void CpuBurst::UpdateDocker(const DataList &dataList)
|
|
{
|
|
- std::unordered_map<std::string, Container*> collector;
|
|
+ std::unordered_map<std::string, Container> collector;
|
|
for (uint64_t i = 0; i < dataList.len; i++) {
|
|
auto *tmp = (Container*)dataList.data[i];
|
|
- collector[tmp->id] = tmp;
|
|
+ collector[tmp->id] = *tmp;
|
|
}
|
|
|
|
for (const auto &container : collector) {
|
|
@@ -102,11 +102,11 @@ void CpuBurst::UpdateDocker(const DataList &dataList)
|
|
const auto &container_info = container.second;
|
|
if (containers.find(id) == containers.end()) {
|
|
containers[id].id = id;
|
|
- containers[id].cfs_burst_us_ori = container_info->cfs_burst_us;
|
|
+ containers[id].cfs_burst_us_ori = container_info.cfs_burst_us;
|
|
}
|
|
- containers[id].cfs_period_us = container_info->cfs_period_us;
|
|
- containers[id].cfs_quota_us = container_info->cfs_quota_us;
|
|
- containers[id].cfs_burst_us = container_info->cfs_burst_us;
|
|
+ containers[id].cfs_period_us = container_info.cfs_period_us;
|
|
+ containers[id].cfs_quota_us = container_info.cfs_quota_us;
|
|
+ containers[id].cfs_burst_us = container_info.cfs_burst_us;
|
|
}
|
|
|
|
// remove containers
|
|
diff --git a/src/plugin/tune/docker/cpu_burst_adapt.cpp b/src/plugin/tune/docker/cpu_burst_adapt.cpp
|
|
index 822e0c5..0454b00 100644
|
|
--- a/src/plugin/tune/docker/cpu_burst_adapt.cpp
|
|
+++ b/src/plugin/tune/docker/cpu_burst_adapt.cpp
|
|
@@ -27,7 +27,7 @@ CpuBurstAdapt::CpuBurstAdapt()
|
|
version = "1.0.0";
|
|
period = PERIOD;
|
|
priority = PRIORITY;
|
|
-
|
|
+ type = oeaware::TUNE;
|
|
oeaware::Topic topic;
|
|
topic.instanceName = this->name;
|
|
topic.topicName = this->name;
|
|
diff --git a/src/plugin/tune/unixbench/ub_tune.cpp b/src/plugin/tune/unixbench/ub_tune.cpp
|
|
index a72e8e9..f71f226 100644
|
|
--- a/src/plugin/tune/unixbench/ub_tune.cpp
|
|
+++ b/src/plugin/tune/unixbench/ub_tune.cpp
|
|
@@ -28,6 +28,7 @@ UnixBenchTune::UnixBenchTune() {
|
|
version = "1.0.0";
|
|
period = 500;
|
|
priority = 2;
|
|
+ type = TUNE;
|
|
depTopic.instanceName = "thread_collector";
|
|
depTopic.topicName = "thread_collector";
|
|
}
|
|
--
|
|
2.33.0
|
|
|