323 lines
13 KiB
Diff
323 lines
13 KiB
Diff
From 906d417f7a370b6b9f60069bae41ee6d00d7537e Mon Sep 17 00:00:00 2001
|
|
From: fly_1997 <flylove7@outlook.com>
|
|
Date: Tue, 7 May 2024 18:02:15 +0800
|
|
Subject: [PATCH] modify logs, sock file permission and fix service file,
|
|
repetition of dependencies
|
|
|
|
---
|
|
config.yaml | 11 ++++-----
|
|
oeaware.service | 2 +-
|
|
src/client/cmd_handler.cpp | 22 +++++++++++++-----
|
|
src/client/cmd_handler.h | 2 ++
|
|
src/plugin_mgr/dep_handler.cpp | 36 +++++++++++++++++++++---------
|
|
src/plugin_mgr/dep_handler.h | 8 +++----
|
|
src/plugin_mgr/error_code.cpp | 2 +-
|
|
src/plugin_mgr/message_manager.cpp | 3 +++
|
|
src/plugin_mgr/plugin.h | 6 +++--
|
|
src/plugin_mgr/plugin_manager.cpp | 15 ++++++++-----
|
|
10 files changed, 73 insertions(+), 34 deletions(-)
|
|
|
|
diff --git a/config.yaml b/config.yaml
|
|
index ef0b44b..99d01d7 100644
|
|
--- a/config.yaml
|
|
+++ b/config.yaml
|
|
@@ -1,8 +1,9 @@
|
|
log_path: /var/log/oeAware
|
|
-log_level: 1
|
|
+log_level: 2
|
|
enable_list:
|
|
- - name: aaa.so
|
|
+
|
|
plugin_list:
|
|
- - name: test
|
|
- description: hello world
|
|
- url: https://gitee.com/openeuler/oeAware-manager
|
|
\ No newline at end of file
|
|
+ - name: numafast
|
|
+ description: numafast is a userspace tool designed for Kunpeng Chips that aims to improve
|
|
+ system performance by reducing cross-NUMA memory access.
|
|
+ url: https://repo.oepkgs.net/openeuler/rpm/openEuler-22.03-LTS-SP1/extras/aarch64/Packages/n/numafast-v1.0.0-2.aarch64.rpm
|
|
\ No newline at end of file
|
|
diff --git a/oeaware.service b/oeaware.service
|
|
index b321530..be13c4b 100644
|
|
--- a/oeaware.service
|
|
+++ b/oeaware.service
|
|
@@ -5,7 +5,7 @@ After=network.target
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/usr/bin/oeaware /etc/oeAware/config.yaml
|
|
-ExecStop=kill $MAINPID && sleep 5 && kill -9 $MAINPID
|
|
+ExecStop=kill $MAINPID
|
|
Restart=on-failure
|
|
RestartSec=1
|
|
RemainAfterExit=yes
|
|
diff --git a/src/client/cmd_handler.cpp b/src/client/cmd_handler.cpp
|
|
index 1f2b8a5..4fec95b 100644
|
|
--- a/src/client/cmd_handler.cpp
|
|
+++ b/src/client/cmd_handler.cpp
|
|
@@ -15,12 +15,22 @@
|
|
|
|
std::unordered_set<std::string> LoadHandler::types = {"collector", "scenario", "tune"};
|
|
|
|
+void LoadHandler::check(const std::string &arg, const std::string &type) {
|
|
+ if (arg.empty()) {
|
|
+ ArgParse::arg_error("plugin name empty.");
|
|
+ }
|
|
+ if (type.empty()) {
|
|
+ ArgParse::arg_error("type empty.");
|
|
+ }
|
|
+ if (!types.count(type)) {
|
|
+ ArgParse::arg_error("this type is not supported.");
|
|
+ }
|
|
+}
|
|
+
|
|
void LoadHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
|
std::string arg = arg_parse.get_arg();
|
|
std::string type = arg_parse.get_type();
|
|
- if (arg.empty() || type.empty() || !types.count(type)) {
|
|
- ArgParse::arg_error("args error.");
|
|
- }
|
|
+ check(arg, type);
|
|
msg.add_payload(arg);
|
|
msg.add_payload(type);
|
|
msg.set_opt(Opt::LOAD);
|
|
@@ -84,7 +94,7 @@ void RemoveHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
|
|
|
void RemoveHandler::res_handler(Msg &msg) {
|
|
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
|
- std::cout << "plugin remove successful.\n";
|
|
+ std::cout << "plugin remove successfully.\n";
|
|
} else {
|
|
std::cout << "plugin remove failed, because " << msg.payload(0) << ".\n";
|
|
}
|
|
@@ -131,7 +141,7 @@ void EnabledHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
|
|
|
void EnabledHandler::res_handler(Msg &msg) {
|
|
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
|
- std::cout << "instance enabled.\n";
|
|
+ std::cout << "instance enabled successfully.\n";
|
|
} else {
|
|
std::cout << "instance enabled failed, because "<< msg.payload(0) << ".\n";
|
|
}
|
|
@@ -145,7 +155,7 @@ void DisabledHandler::handler(const ArgParse &arg_parse, Msg &msg) {
|
|
|
|
void DisabledHandler::res_handler(Msg &msg) {
|
|
if (msg.get_opt() == Opt::RESPONSE_OK) {
|
|
- std::cout << "instance disabled.\n";
|
|
+ std::cout << "instance disabled successfully.\n";
|
|
} else {
|
|
std::cout << "instance disabled failed, because "<< msg.payload(0) << ".\n";
|
|
}
|
|
diff --git a/src/client/cmd_handler.h b/src/client/cmd_handler.h
|
|
index ab21944..1b6f1c1 100644
|
|
--- a/src/client/cmd_handler.h
|
|
+++ b/src/client/cmd_handler.h
|
|
@@ -29,6 +29,7 @@ public:
|
|
void handler(const ArgParse &arg_parse, Msg &msg) override;
|
|
void res_handler(Msg &msg) override;
|
|
private:
|
|
+ void check(const std::string &arg, const std::string &type);
|
|
static std::unordered_set<std::string> types;
|
|
};
|
|
|
|
@@ -36,6 +37,7 @@ class QueryHandler : public CmdHandler {
|
|
public:
|
|
void handler(const ArgParse &arg_parse, Msg &msg) override;
|
|
void res_handler(Msg &msg) override;
|
|
+private:
|
|
void print_format();
|
|
};
|
|
|
|
diff --git a/src/plugin_mgr/dep_handler.cpp b/src/plugin_mgr/dep_handler.cpp
|
|
index eff333c..652fdce 100644
|
|
--- a/src/plugin_mgr/dep_handler.cpp
|
|
+++ b/src/plugin_mgr/dep_handler.cpp
|
|
@@ -11,6 +11,7 @@
|
|
******************************************************************************/
|
|
#include "dep_handler.h"
|
|
#include <queue>
|
|
+#include <unordered_set>
|
|
#include <stdio.h>
|
|
|
|
void DepHandler::add_arc_node(std::shared_ptr<Node> node, const std::vector<std::string> &dep_nodes) {
|
|
@@ -38,14 +39,14 @@ void DepHandler::add_arc_node(std::shared_ptr<Node> node, const std::vector<std:
|
|
}
|
|
|
|
|
|
-void DepHandler::add_node(std::string name, std::vector<std::string> dep_nodes) {
|
|
+void DepHandler::add_node(const std::string &name, std::vector<std::string> dep_nodes) {
|
|
std::shared_ptr<Node> cur_node = add_new_node(name);
|
|
this->nodes[name] = cur_node;
|
|
add_arc_node(cur_node, dep_nodes);
|
|
change_arc_nodes(name, true);
|
|
}
|
|
|
|
-void DepHandler::del_node(std::string name) {
|
|
+void DepHandler::del_node(const std::string &name) {
|
|
del_node_and_arc_nodes(get_node(name));
|
|
this->nodes.erase(name);
|
|
}
|
|
@@ -119,26 +120,41 @@ void DepHandler::query_node_top(std::string name, std::vector<std::vector<std::s
|
|
}
|
|
}
|
|
|
|
-void DepHandler::query_node(std::string name, std::vector<std::vector<std::string>> &query) {
|
|
+void DepHandler::query_node(const std::string &name, std::vector<std::vector<std::string>> &query) {
|
|
if (!nodes.count(name)) return;
|
|
- std::shared_ptr<Node> p = nodes[name];
|
|
- query.emplace_back(std::vector<std::string>{name});
|
|
- for (auto cur = p->head->next; cur != nullptr; cur = cur->next) {
|
|
- query.emplace_back(std::vector<std::string>{name, cur->arc_name});
|
|
- query_node(cur->arc_name, query);
|
|
+ std::queue<std::string> q;
|
|
+ std::unordered_set<std::string> vis;
|
|
+ vis.insert(name);
|
|
+ q.push(name);
|
|
+ while (!q.empty()) {
|
|
+ auto node = nodes[q.front()];
|
|
+ q.pop();
|
|
+ query.emplace_back(std::vector<std::string>{node->name});
|
|
+ for (auto cur = node->head->next; cur != nullptr; cur = cur->next) {
|
|
+ query.emplace_back(std::vector<std::string>{node->name, cur->arc_name});
|
|
+ if (!vis.count(cur->arc_name)) {
|
|
+ vis.insert(cur->arc_name);
|
|
+ q.push(cur->arc_name);
|
|
+ }
|
|
+ }
|
|
}
|
|
}
|
|
|
|
-std::vector<std::string> DepHandler::get_pre_dependencies(std::string name) {
|
|
+std::vector<std::string> DepHandler::get_pre_dependencies(const std::string &name) {
|
|
std::vector<std::string> res;
|
|
std::queue<std::shared_ptr<Node>> q;
|
|
+ std::unordered_set<std::string> vis;
|
|
+ vis.insert(name);
|
|
q.push(nodes[name]);
|
|
while (!q.empty()) {
|
|
auto &node = q.front();
|
|
q.pop();
|
|
res.emplace_back(node->name);
|
|
for (auto arc_node = node->head->next; arc_node != nullptr; arc_node = arc_node->next) {
|
|
- q.push(nodes[arc_node->arc_name]);
|
|
+ if (!vis.count(arc_node->arc_name)) {
|
|
+ vis.insert(arc_node->arc_name);
|
|
+ q.push(nodes[arc_node->arc_name]);
|
|
+ }
|
|
}
|
|
}
|
|
return res;
|
|
diff --git a/src/plugin_mgr/dep_handler.h b/src/plugin_mgr/dep_handler.h
|
|
index cc8570a..76abf49 100644
|
|
--- a/src/plugin_mgr/dep_handler.h
|
|
+++ b/src/plugin_mgr/dep_handler.h
|
|
@@ -47,11 +47,11 @@ public:
|
|
bool get_node_state(std::string name) {
|
|
return this->nodes[name]->state;
|
|
}
|
|
- void add_node(std::string name, std::vector<std::string> dep_nodes = {});
|
|
- void del_node(std::string name);
|
|
- std::vector<std::string> get_pre_dependencies(std::string name);
|
|
+ void add_node(const std::string &name, std::vector<std::string> dep_nodes = {});
|
|
+ void del_node(const std::string &name);
|
|
+ std::vector<std::string> get_pre_dependencies(const std::string &name);
|
|
// query instance dependency
|
|
- void query_node(std::string name, std::vector<std::vector<std::string>> &query);
|
|
+ void query_node(const std::string &name, std::vector<std::vector<std::string>> &query);
|
|
// query all instance dependencies
|
|
void query_all_top(std::vector<std::vector<std::string>> &query);
|
|
bool have_dep(const std::string &name) {
|
|
diff --git a/src/plugin_mgr/error_code.cpp b/src/plugin_mgr/error_code.cpp
|
|
index 6e09cb0..30cc4f8 100644
|
|
--- a/src/plugin_mgr/error_code.cpp
|
|
+++ b/src/plugin_mgr/error_code.cpp
|
|
@@ -12,7 +12,7 @@ const std::unordered_map<ErrorCode, std::string> ErrorText::error_codes = {
|
|
{ErrorCode::REMOVE_INSTANCE_HAVE_DEP, "instance with pre-dependency"},
|
|
{ErrorCode::LOAD_PLUGIN_FILE_NOT_EXIST, "plugin file does not exist"},
|
|
{ErrorCode::LOAD_PLUGIN_FILE_IS_NOT_SO, "file is not a plugin file"},
|
|
- {ErrorCode::LOAD_PLUGIN_FILE_PERMISSION_DEFINED, "plugin file permission defined"},
|
|
+ {ErrorCode::LOAD_PLUGIN_FILE_PERMISSION_DEFINED, "plugin file permission is not the specified permission"},
|
|
{ErrorCode::LOAD_PLUGIN_EXIST, "plugin already loaded"},
|
|
{ErrorCode::LOAD_PLUGIN_DLOPEN_FAILED, "plugin dlopen failed"},
|
|
{ErrorCode::LOAD_PLUGIN_DLSYM_FAILED, "plugin dlsym failed"},
|
|
diff --git a/src/plugin_mgr/message_manager.cpp b/src/plugin_mgr/message_manager.cpp
|
|
index e2fd3b6..f081f20 100644
|
|
--- a/src/plugin_mgr/message_manager.cpp
|
|
+++ b/src/plugin_mgr/message_manager.cpp
|
|
@@ -25,6 +25,9 @@ int TcpSocket::domain_listen(const char *name) {
|
|
ERROR("[MessageManager] bind error!");
|
|
return -1;
|
|
}
|
|
+ if (chmod(name, S_IRWXU | S_IRGRP | S_IXGRP) == -1) {
|
|
+ ERROR("[MessageManager] " << name << " chmod error!");
|
|
+ }
|
|
if (listen(sock, 20) < 0) {
|
|
ERROR("[MessageManager] listen error!");
|
|
return -1;
|
|
diff --git a/src/plugin_mgr/plugin.h b/src/plugin_mgr/plugin.h
|
|
index 69837af..a2a1815 100644
|
|
--- a/src/plugin_mgr/plugin.h
|
|
+++ b/src/plugin_mgr/plugin.h
|
|
@@ -123,8 +123,10 @@ private:
|
|
class Plugin {
|
|
public:
|
|
Plugin(std::string name, PluginType type) : name(name), type(type), handler(nullptr) { }
|
|
- ~Plugin() {
|
|
- dlclose(handler);
|
|
+ ~Plugin() {
|
|
+ if (handler != nullptr) {
|
|
+ dlclose(handler);
|
|
+ }
|
|
}
|
|
int load(const std::string dl_path);
|
|
std::string get_name() const {
|
|
diff --git a/src/plugin_mgr/plugin_manager.cpp b/src/plugin_mgr/plugin_manager.cpp
|
|
index 0826a60..5ef395c 100644
|
|
--- a/src/plugin_mgr/plugin_manager.cpp
|
|
+++ b/src/plugin_mgr/plugin_manager.cpp
|
|
@@ -13,6 +13,7 @@
|
|
#include "default_path.h"
|
|
#include "utils.h"
|
|
#include <iostream>
|
|
+#include <unordered_set>
|
|
#include <dirent.h>
|
|
#include <sys/stat.h>
|
|
|
|
@@ -203,15 +204,15 @@ ErrorCode PluginManager::load_plugin(const std::string &name, PluginType type) {
|
|
std::string generate_dot(MemoryStore &memory_store, const std::vector<std::vector<std::string>> &query) {
|
|
std::string res;
|
|
res += "digraph G {\n";
|
|
- std::unordered_map<std::string, std::vector<std::string>> sub_graph;
|
|
+ std::unordered_map<std::string, std::unordered_set<std::string>> sub_graph;
|
|
for (auto &vec : query) {
|
|
std::shared_ptr<Instance> instance = memory_store.get_instance(vec[0]);
|
|
- sub_graph[instance->get_plugin_name()].emplace_back(vec[0]);
|
|
+ sub_graph[instance->get_plugin_name()].insert(vec[0]);
|
|
if (vec.size() == 1) {
|
|
continue;
|
|
}
|
|
instance = memory_store.get_instance(vec[1]);
|
|
- sub_graph[instance->get_plugin_name()].emplace_back(vec[1]);
|
|
+ sub_graph[instance->get_plugin_name()].insert(vec[1]);
|
|
res += vec[0] + "->" + vec[1] + ";";
|
|
}
|
|
int id = 0;
|
|
@@ -371,8 +372,12 @@ void PluginManager::pre_load_plugin(PluginType type) {
|
|
while ((entry = readdir(dir)) != nullptr) {
|
|
std::string name = entry->d_name;
|
|
if (end_with(name, ".so")) {
|
|
- Message msg;
|
|
- load_plugin(name, type);
|
|
+ auto ret = load_plugin(name, type);
|
|
+ if (ret != ErrorCode::OK) {
|
|
+ WARN("[PluginManager] " << name << " plugin preload failed, because " << ErrorText::get_error_text(ret) << ".");
|
|
+ } else {
|
|
+ INFO("[PluginManager] " << name << " plugin loaded.");
|
|
+ }
|
|
}
|
|
}
|
|
closedir(dir);
|
|
--
|
|
2.33.0
|
|
|