From 56047f38f4334577ab0147c468cf6644d18e1a73 Mon Sep 17 00:00:00 2001 From: zhoukaiqi Date: Wed, 15 May 2024 09:27:46 +0800 Subject: [PATCH] fix compile warnings (cherry picked from commit 5d1f8b217b6751b7570bff2a80437946fc186176) --- 0001-fix-compile-warnings.patch | 229 ++++++++++++++++++++++++++++++++ oeAware-collector.spec | 6 +- 2 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 0001-fix-compile-warnings.patch diff --git a/0001-fix-compile-warnings.patch b/0001-fix-compile-warnings.patch new file mode 100644 index 0000000..a299e54 --- /dev/null +++ b/0001-fix-compile-warnings.patch @@ -0,0 +1,229 @@ +From 3c72333dbaf64eed536cfd4c1aae0546bf6a1c00 Mon Sep 17 00:00:00 2001 +From: zhoukaiqi +Date: Tue, 14 May 2024 19:35:35 +0800 +Subject: [PATCH] fix compile warnings + +--- + pmu/CMakeLists.txt | 2 +- + pmu/plugin/plugin_counting.c | 8 ++++++++ + pmu/plugin/plugin_sampling.c | 8 ++++++++ + pmu/plugin/plugin_spe.c | 8 ++++++++ + pmu/plugin/plugin_uncore.c | 8 ++++++++ + pmu/plugin/pmu_uncore.c | 3 ++- + thread_collector/CMakeLists.txt | 3 ++- + thread_collector/thread_collector.cpp | 5 +++-- + 8 files changed, 40 insertions(+), 5 deletions(-) + +diff --git a/pmu/CMakeLists.txt b/pmu/CMakeLists.txt +index b84a77e..9da7622 100644 +--- a/pmu/CMakeLists.txt ++++ b/pmu/CMakeLists.txt +@@ -9,7 +9,7 @@ if (WITH_DEBUG) + message("-- Note:pmu debug mode") + add_compile_options(-g) + endif() +-add_compile_options(-O2 -fPIC) ++add_compile_options(-O2 -fPIC -Wall -Wextra) + + # libkperf + message("-- libkperf library path: ${LIB_KPERF_LIBPATH}") +diff --git a/pmu/plugin/plugin_counting.c b/pmu/plugin/plugin_counting.c +index b18b8be..5cb99c7 100644 +--- a/pmu/plugin/plugin_counting.c ++++ b/pmu/plugin/plugin_counting.c +@@ -31,7 +31,12 @@ static void counting_init() + + static void counting_fini() + { ++ if (!counting_buf) { ++ return; ++ } ++ + free_buf(counting_buf); ++ counting_buf = NULL; + } + + static int counting_open() +@@ -81,6 +86,8 @@ void counting_enable() + void counting_disable() + { + PmuDisable(counting_pd); ++ counting_close(); ++ counting_fini(); + } + + void *counting_get_ring_buf() +@@ -133,5 +140,6 @@ char *counting_get_type() + + char **counting_get_dep(int *len) + { ++ *len = 0; + return NULL; + } +diff --git a/pmu/plugin/plugin_sampling.c b/pmu/plugin/plugin_sampling.c +index 132de07..22263ea 100644 +--- a/pmu/plugin/plugin_sampling.c ++++ b/pmu/plugin/plugin_sampling.c +@@ -31,7 +31,12 @@ static void sampling_init() + + static void sampling_fini() + { ++ if (!sampling_buf) { ++ return; ++ } ++ + free_buf(sampling_buf); ++ sampling_buf = NULL; + } + + static int sampling_open() +@@ -83,6 +88,8 @@ void sampling_enable() + void sampling_disable() + { + PmuDisable(sampling_pd); ++ sampling_close(); ++ sampling_fini(); + } + + void *sampling_get_ring_buf() +@@ -135,5 +142,6 @@ char *sampling_get_type() + + char **sampling_get_dep(int *len) + { ++ *len = 0; + return NULL; + } +diff --git a/pmu/plugin/plugin_spe.c b/pmu/plugin/plugin_spe.c +index a94cfed..4f7fb56 100644 +--- a/pmu/plugin/plugin_spe.c ++++ b/pmu/plugin/plugin_spe.c +@@ -31,7 +31,12 @@ static void spe_init() + + static void spe_fini() + { ++ if (!spe_buf) { ++ return; ++ } ++ + free_buf(spe_buf); ++ spe_buf = NULL; + } + + static int spe_open() +@@ -82,6 +87,8 @@ void spe_enable() + void spe_disable() + { + PmuDisable(spe_pd); ++ spe_close(); ++ spe_fini(); + } + + void *spe_get_ring_buf() +@@ -133,5 +140,6 @@ char *spe_get_type() + + char **spe_get_dep(int *len) + { ++ *len = 0; + return NULL; + } +diff --git a/pmu/plugin/plugin_uncore.c b/pmu/plugin/plugin_uncore.c +index 070f1a7..63b9c8e 100644 +--- a/pmu/plugin/plugin_uncore.c ++++ b/pmu/plugin/plugin_uncore.c +@@ -32,7 +32,12 @@ static void uncore_init() + + static void uncore_fini() + { ++ if (!uncore_buf) { ++ return; ++ } ++ + free_buf(uncore_buf); ++ uncore_buf = NULL; + } + + static int uncore_open() +@@ -106,6 +111,8 @@ void uncore_enable() + void uncore_disable() + { + PmuDisable(uncore_pd); ++ uncore_close(); ++ uncore_fini(); + } + + void *uncore_get_ring_buf() +@@ -158,5 +165,6 @@ char *uncore_get_type() + + char **uncore_get_dep(int *len) + { ++ *len = 0; + return NULL; + } +diff --git a/pmu/plugin/pmu_uncore.c b/pmu/plugin/pmu_uncore.c +index 56b9190..71dcda1 100644 +--- a/pmu/plugin/pmu_uncore.c ++++ b/pmu/plugin/pmu_uncore.c +@@ -13,6 +13,7 @@ + #include + #include + #include ++#include + #include "pmu_uncore.h" + + static int hha_num = 0; +@@ -45,7 +46,7 @@ static int read_single_uncore_event(const char *hha_name, struct uncore_config * + char hha_path[MAX_PATH_LEN] = {0}; + + // Read cfg +- snprintf(hha_path, MAX_PATH_LEN, "%s/%s/", hha_name, event_name); ++ snprintf_truncated_s(hha_path, MAX_PATH_LEN, "%s/%s/", hha_name, event_name); + + strcpy(uncore_event->uncore_name, hha_path); + +diff --git a/thread_collector/CMakeLists.txt b/thread_collector/CMakeLists.txt +index 937dafa..90d9dfa 100644 +--- a/thread_collector/CMakeLists.txt ++++ b/thread_collector/CMakeLists.txt +@@ -1,6 +1,7 @@ + cmake_minimum_required(VERSION 3.11) + project(thread_collector) + include_directories(../include) ++add_compile_options(-O2 -fPIC -Wall -Wextra) + add_library(thread_collector SHARED + thread_collector.cpp +-) +\ No newline at end of file ++) +diff --git a/thread_collector/thread_collector.cpp b/thread_collector/thread_collector.cpp +index 1343c16..83b627f 100644 +--- a/thread_collector/thread_collector.cpp ++++ b/thread_collector/thread_collector.cpp +@@ -20,7 +20,7 @@ + #include + + const std::string PATH = "/proc"; +-char *THREAD_NAME = "thread_collector"; ++char thread_name[] = "thread_collector"; + const int CYCLE_SIZE = 100; + const std::string STATUS_NAME = "Name:\t"; + const int STATUS_NAME_LENGTH = 6; +@@ -74,7 +74,7 @@ static int get_all_threads() { + } + + char* get_name() { +- return THREAD_NAME; ++ return thread_name; + } + + char* get_version() { +@@ -122,6 +122,7 @@ struct CollectorInterface thread_collect = { + .get_description = get_description, + .get_type = get_type, + .get_cycle = get_cycle, ++ .get_dep = nullptr, + .enable = enable, + .disable = disable, + .get_ring_buf = get_ring_buf, +-- +2.27.0 + diff --git a/oeAware-collector.spec b/oeAware-collector.spec index 998013f..7c44e3d 100644 --- a/oeAware-collector.spec +++ b/oeAware-collector.spec @@ -1,10 +1,11 @@ Name: oeAware-collector Version: v1.0.1 -Release: 1 +Release: 2 Summary: %{name} provides low-overhead metrics collection capabilities, including microarchitecture, system, and kernel information. License: MulanPSL2 URL: https://gitee.com/openeuler/%{name} Source0: %{name}-%{version}.tar.gz +Patch1: 0001-fix-compile-warnings.patch %global libkperf_name libkperf %global libkperf_tagver v1.0.2 @@ -79,6 +80,9 @@ install -b -m740 ./thread_collector/build/libthread_collector.so ${RPM_BUIL %attr(0440, root, root) %{_libdir}/oeAware-plugin/collector/*.so %changelog +* Wed May 15 2024 zhoukaiqi - v1.0.1-2 +- fix compile warnings + * Sat May 11 2024 fly_1997 -v1.0.1-1 - update version to v1.0.1 -- Gitee