!35 [sync] PR-32: refactor interface and fix some bugs

From: @openeuler-sync-bot 
Reviewed-by: @ksana123 
Signed-off-by: @ksana123
This commit is contained in:
openeuler-ci-bot 2024-06-05 02:58:19 +00:00 committed by Gitee
commit 0d43a976b0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 10 additions and 236 deletions

View File

@ -1,229 +0,0 @@
From 3c72333dbaf64eed536cfd4c1aae0546bf6a1c00 Mon Sep 17 00:00:00 2001
From: zhoukaiqi <zhoukaiqi@huawei.com>
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 <stdlib.h>
#include <string.h>
#include <dirent.h>
+#include <securec.h>
#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 <dirent.h>
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

Binary file not shown.

Binary file not shown.

View File

@ -1,11 +1,10 @@
Name: oeAware-collector
Version: v1.0.1
Release: 2
Version: v1.0.2
Release: 1
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
@ -64,22 +63,26 @@ make
%install
mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/oeAware-plugin/collector/
mkdir -p ${RPM_BUILD_ROOT}%{_libdir}/oeAware-plugin/
%ifarch aarch64
install -b -m740 ./pmu/3rdlib/bin/*.so ${RPM_BUILD_ROOT}%{_libdir}
install -b -m740 ./pmu/build/libpmu.so ${RPM_BUILD_ROOT}%{_libdir}/oeAware-plugin/collector/
install -b -m740 ./pmu/build/libpmu.so ${RPM_BUILD_ROOT}%{_libdir}/oeAware-plugin/
%endif
install -b -m740 ./thread_collector/build/libthread_collector.so ${RPM_BUILD_ROOT}%{_libdir}/oeAware-plugin/collector/
install -b -m740 ./thread_collector/build/libthread_collector.so ${RPM_BUILD_ROOT}%{_libdir}/oeAware-plugin/
%files
%defattr (-, root, root)
%ifarch aarch64
%attr(0440, root, root) %{_libdir}/libkperf.so
%attr(0440, root, root) %{_libdir}/libsym.so
%attr(0440, root, root) %{_libdir}/oeAware-plugin/libpmu.so
%endif
%attr(0440, root, root) %{_libdir}/oeAware-plugin/collector/*.so
%attr(0440, root, root) %{_libdir}/oeAware-plugin/libthread_collector.so
%changelog
* Fri May 31 2024 zhoukaiqi <zhoukaiqi@huawei.com> - v1.0.2-1
- refactor interface and fix some bugs
* Wed May 15 2024 zhoukaiqi <zhoukaiqi@huawei.com> - v1.0.1-2
- fix compile warnings