Update to 2.0.1

(cherry picked from commit b7b87030098433923bc6792380f2eef3ef6335be)
This commit is contained in:
xietangxin 2024-04-23 22:26:04 +08:00 committed by openeuler-sync-bot
parent a2a1d2369c
commit 92834f3333
25 changed files with 145 additions and 3996 deletions

View File

@ -1,33 +0,0 @@
From 0f5572c6ee1847ac6b8d5fa892c83797ac4cbc6f Mon Sep 17 00:00:00 2001
From: htpeng <htpengc@isoftstone.com>
Date: Wed, 29 Mar 2023 08:37:46 +0800
Subject: [PATCH 27/30] Fix for popen() cannot get stderr
Signed-off-by: htpeng <htpengc@isoftstone.com>
---
src/probes/virtualized_infos.probe/virt_proc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/probes/virtualized_infos.probe/virt_proc.c b/src/probes/virtualized_infos.probe/virt_proc.c
index d5972a5..b52c63e 100644
--- a/src/probes/virtualized_infos.probe/virt_proc.c
+++ b/src/probes/virtualized_infos.probe/virt_proc.c
@@ -72,7 +72,7 @@ static int is_virsh_installed(void)
char line[LINE_BUF_LEN];
int is_installed = 0;
- if (do_read_line("which virsh", line) < 0) {
+ if (do_read_line("which virsh 2>&1", line) < 0) {
ERROR("[VIRT_PROC] find virsh failed.\n");
return -1;
}
@@ -199,4 +199,4 @@ int virt_proc_init(void)
{
g_host_type_is_pm = 0;
is_host_type_pm(&g_host_type_is_pm);
-}
\ No newline at end of file
+}
--
2.33.0

View File

@ -1,24 +0,0 @@
From 5dca2b18cda90ef8cb66cff7b1f860062f248021 Mon Sep 17 00:00:00 2001
From: Vchanger <chenzhen126@huawei.com>
Date: Wed, 19 Apr 2023 14:20:52 +0800
Subject: [PATCH] Fix segmentation fault of gala-gopher cmd
---
src/daemon/main.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 60a509c..bb39f08 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -65,6 +65,7 @@ static int CmdProcessing(int argc, char *argv[])
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"config_path", required_argument, 0, 'c'},
+ {NULL, 0, 0, NULL}
};
char short_options[] = {
--
2.33.0

View File

@ -1,28 +0,0 @@
From ebc4a770ef1657c93fadf48d40294d3cb7e1cb29 Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Thu, 27 Apr 2023 16:59:17 +0800
Subject: [PATCH] adapt block_rq_issue tracepoint args in kernel-5.10
---
src/probes/extends/ebpf.probe/src/ioprobe/io_trace_bpf.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/probes/extends/ebpf.probe/src/ioprobe/io_trace_bpf.h b/src/probes/extends/ebpf.probe/src/ioprobe/io_trace_bpf.h
index 2109c87..f24078d 100644
--- a/src/probes/extends/ebpf.probe/src/ioprobe/io_trace_bpf.h
+++ b/src/probes/extends/ebpf.probe/src/ioprobe/io_trace_bpf.h
@@ -315,7 +315,11 @@ static __always_inline struct io_latency_s* get_io_latency(struct io_trace_s* io
KRAWTRACE(block_rq_issue, bpf_raw_tracepoint_args)
{
struct io_trace_s *io_trace = NULL;
+#if (CURRENT_KERNEL_VERSION >= KERNEL_VERSION(5, 10, 0))
+ struct request* req = (struct request *)ctx->args[0];
+#else
struct request* req = (struct request *)ctx->args[1];
+#endif
io_trace = get_io_trace(req);
if (io_trace == NULL) {
--
2.33.0

View File

@ -1,27 +0,0 @@
From 57ab187ddd2915d0eaff2b472e22fb15e7374c09 Mon Sep 17 00:00:00 2001
From: sjxur <sjxur@isoftstone.com>
Date: Sun, 23 Apr 2023 17:49:27 +0800
Subject: [PATCH] bugfix:The log time is not the local time
Conficts: del part of change comment code
---
src/common/logs.cpp | 2 +-
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/common/logs.cpp b/src/common/logs.cpp
index fc338c3..f8c0c35 100644
--- a/src/common/logs.cpp
+++ b/src/common/logs.cpp
@@ -383,7 +383,7 @@ static int append_debug_logger(struct log_mgr_s * mgr)
SharedAppenderPtr append(new RollingFileAppender(g_debug_abs_path, DEBUG_LOGS_FILESIZE, 1, true, true));
- log4cplus::tstring pattern = LOG4CPLUS_TEXT("%d{%m/%d/%y %H:%M:%S} - %m");
+ log4cplus::tstring pattern = LOG4CPLUS_TEXT("%D{%m/%d/%y %H:%M:%S} - %m");
append->setLayout(std::unique_ptr<log4cplus::Layout>(new log4cplus::PatternLayout(pattern)));
g_debug_logger.addAppender(append);
--
2.33.0

View File

@ -1,84 +0,0 @@
From b5fae1956af6c3c7f151bbf8919eb1c1a69a28ba Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Wed, 29 Mar 2023 09:26:34 +0800
Subject: [PATCH 28/30] bugfix:add check whether cadvisor is installed
---
src/common/container.c | 2 +-
.../cadvisor.probe/cadvisor_probe.py | 19 +++++++++++++++----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/common/container.c b/src/common/container.c
index c5b64a4..7d6ab27 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -117,7 +117,7 @@ static bool __is_dockerd()
static bool __is_isulad()
{
if (__is_install_rpm("/bin/rpm -ql iSulad")) {
- return __is_service_running("/usr/bin/systemctl service iSulad"); {
+ return __is_service_running("/usr/bin/systemctl status isulad"); {
current_docker_command = ISULAD;
return true;
}
diff --git a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
index 8b65117..81226d0 100644
--- a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
+++ b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
@@ -16,7 +16,7 @@ CONTAINER_NAME_LEN = 64
CONTAINER_STATUS_RUNNING = 0
FILTER_BY_TASKPROBE = "task"
PROJECT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # /opt/gala-gopher/
-PATTERN = re.compile(r'/[a-z0-9]+')
+PATTERN = re.compile(r'[/-][a-z0-9]+')
COUNTER = "counter"
LABEL = "label"
g_meta = None
@@ -248,6 +248,10 @@ class CadvisorProbe(Probe):
return False
def start_cadvisor(self):
+ p = subprocess.Popen("which cadvisor", stdout=subprocess.PIPE, shell=True)
+ p.communicate(timeout=5)
+ if p.returncode != 0:
+ raise Exception('[cadvisor_probe] cAdvisor not installed')
p = subprocess.Popen("/usr/bin/ps -ef | /usr/bin/grep /usr/bin/cadvisor | /usr/bin/grep -v grep | \
/usr/bin/awk '{print $2}'", stdout=subprocess.PIPE, shell=True)
(rawout, serr) = p.communicate(timeout=5)
@@ -310,7 +314,13 @@ class CadvisorProbe(Probe):
g_metric[table_name] = dict()
metric_str = libconf.loads(line[(line.index("{") + 1):line.index("} ")])
- if metric_str.id.startswith("/system.slice"):
+ '''
+ docker use systemd as cgroupfs in k8s, cadvisor metric id like:
+ {id="/system.slice/docker-1044qbdeeedqdff...scope"}
+ normal metric_id like:
+ {id="/docker/1044qbdeeedqdff..."}
+ '''
+ if metric_str.id.startswith("/system.slice") and 'docker-' not in metric_str.id:
continue
if metric_str.id.startswith("/user.slice"):
continue
@@ -388,7 +398,8 @@ if __name__ == "__main__":
cadvisor_probe = CadvisorProbe(object_lib, container_lib, params.port)
try:
cadvisor_probe.start_cadvisor()
- except ParamException as e:
+ except Exception as e:
+ print(e)
cadvisor_running_flag = False
basic_probe = BasicLabelProbe(object_lib, container_lib)
@@ -401,7 +412,7 @@ if __name__ == "__main__":
basic_probe.get_basic_infos()
if cadvisor_running_flag:
try:
- cadvisor_probe.get_metrics(s, params.port)
+ cadvisor_probe.get_metrics(s, cadvisor_probe.port)
except Exception as e:
print("[cadvisor_probe]get metrics failed. Err: %s" % repr(e))
s = requests.Session()
--
2.33.0

View File

@ -1,46 +0,0 @@
From 8cdc9f0c63f897240f1325faf287250c19e3b57a Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Mon, 8 May 2023 17:25:24 +0800
Subject: [PATCH] bugfix: fix gala-gopher -h print err
---
res/event_multy_language.rc | 2 +-
src/daemon/main.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/res/event_multy_language.rc b/res/event_multy_language.rc
index 0fb255b..04d580e 100644
--- a/res/event_multy_language.rc
+++ b/res/event_multy_language.rc
@@ -228,7 +228,7 @@ events_en_US =
}
);
-events_chinese =
+events_zh_CN =
(
{
entity_name = "cpu",
diff --git a/src/daemon/main.c b/src/daemon/main.c
index bb39f08..5007486 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -87,12 +87,12 @@ static int CmdProcessing(int argc, char *argv[])
int option_index = 0;
cmd = getopt_long(argc, argv, short_options, long_options, &option_index);
if (cmd == -1)
- break;
+ return -1;
switch (cmd) {
case 'h':
- ShowUsage();
- break;
+ // print usage later
+ return -1;
case 'c':
ret = ParseConfigPath(optarg);
break;
--
2.33.0

View File

@ -1,163 +0,0 @@
From 3bc3d1d20a220ab3a0a9093059289cc841bd45e2 Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Mon, 27 Mar 2023 11:38:26 +0800
Subject: [PATCH 26/30] bugfix: fix system_proc collect data err
---
src/daemon/daemon.c | 2 +-
.../ebpf.probe/src/lvsprobe/trace_lvs.bpf.c | 2 +-
.../cadvisor.probe/cadvisor_probe.py | 4 ++++
src/probes/system_infos.probe/system_net.c | 4 ++--
src/probes/system_infos.probe/system_procs.c | 18 +++++++++++++-----
src/probes/system_infos.probe/system_procs.h | 11 +----------
6 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index f3ab821..b10ca60 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -26,7 +26,7 @@
#include "daemon.h"
#include "object.h"
-#define RM_MAP_CMD "/usr/bin/find %s/* | /usr/bin/grep -v '%s\\|%s\\|%s' | /usr/bin/xargs rm -f"
+#define RM_MAP_CMD "/usr/bin/find %s/* 2> /dev/null | /usr/bin/grep -v '%s\\|%s\\|%s' | /usr/bin/xargs rm -f"
static const ResourceMgr *resouce_msg;
#if GALA_GOPHER_INFO("inner func declaration")
diff --git a/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c b/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c
index cc2747c..ceb6548 100644
--- a/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/lvsprobe/trace_lvs.bpf.c
@@ -187,7 +187,7 @@ KPROBE(ip_vs_conn_expire, pt_regs)
value_p = bpf_map_lookup_elem(&lvs_link_map, &key);
if (value_p == (void *)0) {
bpf_printk("===LVS ubind dest not in hash map.\n");
- return;
+ return 0;
}
value_p->state = IP_VS_TCP_S_CLOSE;
value_p->close_ts = bpf_ktime_get_ns();
diff --git a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
index 65db0f5..8b65117 100644
--- a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
+++ b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
@@ -200,6 +200,10 @@ class BasicLabelProbe(Probe):
self.container_lib.get_all_container.restype = POINTER(ContainerTbl)
tbl_p = self.container_lib.get_all_container()
+ if not tbl_p:
+ print("[cadvisor_probe] no active containers in system")
+ return 0
+
for i in range(tbl_p.contents.num):
if tbl_p.contents.cs[i].status != CONTAINER_STATUS_RUNNING:
continue
diff --git a/src/probes/system_infos.probe/system_net.c b/src/probes/system_infos.probe/system_net.c
index 0962a9b..ce5cc04 100644
--- a/src/probes/system_infos.probe/system_net.c
+++ b/src/probes/system_infos.probe/system_net.c
@@ -99,7 +99,7 @@ int system_tcp_probe(void)
/* output */
(void)nprobe_fprintf(stdout, "|%s|%s|%llu|%llu|%llu|%llu|%llu|\n",
METRICS_TCP_NAME,
- "/proc/dev/snmp",
+ "/proc/net/snmp",
g_snmp_stats.tcp_curr_estab,
(g_snmp_stats.tcp_in_segs > temp.tcp_in_segs) ? (g_snmp_stats.tcp_in_segs - temp.tcp_in_segs) : 0,
(g_snmp_stats.tcp_out_segs > temp.tcp_out_segs) ? (g_snmp_stats.tcp_out_segs - temp.tcp_out_segs) : 0,
@@ -109,7 +109,7 @@ int system_tcp_probe(void)
(void)nprobe_fprintf(stdout, "|%s|%s|%llu|%llu|\n",
METRICS_UDP_NAME,
- "/proc/dev/snmp",
+ "/proc/net/snmp",
(g_snmp_stats.udp_in_datagrams > temp.udp_in_datagrams) ?
(g_snmp_stats.udp_in_datagrams - temp.udp_in_datagrams) : 0,
(g_snmp_stats.udp_out_datagrams > temp.udp_out_datagrams) ?
diff --git a/src/probes/system_infos.probe/system_procs.c b/src/probes/system_infos.probe/system_procs.c
index d2d3c9a..1c32f53 100644
--- a/src/probes/system_infos.probe/system_procs.c
+++ b/src/probes/system_infos.probe/system_procs.c
@@ -27,7 +27,7 @@
#define PROC_STAT "/proc/%s/stat"
#define PROC_START_TIME_CMD "/usr/bin/cat /proc/%s/stat | awk '{print $22}'"
#define PROC_FD "/proc/%s/fd"
-#define PROC_FD_CNT_CMD "/usr/bin/ls -l /proc/%s/fd 2>/dev/null | wc -l 2>/dev/null"
+#define PROC_FD_CNT_CMD "/usr/bin/ls /proc/%s/fd 2>/dev/null | wc -l 2>/dev/null"
#define PROC_IO "/proc/%s/io"
#define PROC_IO_CMD "/usr/bin/cat /proc/%s/io"
#define PROC_SMAPS "/proc/%s/smaps_rollup"
@@ -459,6 +459,10 @@ static int get_proc_mss(const char *pid, proc_info_t *proc_info)
u32 value = 0;
char fname_or_cmd[LINE_BUF_LEN];
char line[LINE_BUF_LEN];
+ char key[LINE_BUF_LEN];
+ char smap_key_list[PROC_MSS_MAX][LINE_BUF_LEN] = {"Shared_Clean:", "Shared_Dirty:", "Private_Clean:",
+ "Private_Dirty:", "Referenced:", "LazyFree:", "Swap:", "SwapPss:"};
+ int smap_index = 0;
fname_or_cmd[0] = 0;
(void)snprintf(fname_or_cmd, LINE_BUF_LEN, PROC_SMAPS, pid);
@@ -471,8 +475,9 @@ static int get_proc_mss(const char *pid, proc_info_t *proc_info)
if (f == NULL) {
goto out;
}
- while (!feof(f) && (index < PROC_MSS_MAX)) {
+ while (!feof(f)) {
line[0] = 0;
+ key[0] = 0;
if (fgets(line, LINE_BUF_LEN, f) == NULL) {
goto out;
}
@@ -481,12 +486,15 @@ static int get_proc_mss(const char *pid, proc_info_t *proc_info)
continue;
}
value = 0;
- int ret = sscanf(line, "%*s %lu %*s", &value);
+ int ret = sscanf(line, "%s %lu %*s", key, &value);
if (ret < 1) {
goto out;
}
- do_set_proc_mss(proc_info, value, index);
- index++;
+ if (strcmp(smap_key_list[smap_index], key) != 0) {
+ continue;
+ }
+ do_set_proc_mss(proc_info, value, smap_index);
+ smap_index++;
}
out:
if (f != NULL) {
diff --git a/src/probes/system_infos.probe/system_procs.h b/src/probes/system_infos.probe/system_procs.h
index 9c9a77d..58cf4f8 100644
--- a/src/probes/system_infos.probe/system_procs.h
+++ b/src/probes/system_infos.probe/system_procs.h
@@ -50,23 +50,14 @@ enum proc_stat_e {
};
enum proc_mss_e {
- PROC_MSS_RESIDENT = 0,
- PROC_MSS_SHARED_CLEAN,
+ PROC_MSS_SHARED_CLEAN = 0,
PROC_MSS_SHARED_DIRTY,
PROC_MSS_PRIVATE_CLEAN,
PROC_MSS_PROVATE_DIRTY,
PROC_MSS_REFERENCED,
- PROC_MSS_ANONYMOUS,
PROC_MSS_LAZYFREE,
- PROC_MSS_ANONYMOUS_THP,
PROC_MSS_SWAP,
- PROC_MSS_SHARED_HUGETLB,
- PROC_MSS_PRIVATE_HUGETLB,
- PROC_MSS_PSS,
- PROC_MSS_PSS_LOCKED,
PROC_MSS_SWAP_PSS,
- PROC_MSS_CHECK_SHNEM_SWAP,
-
PROC_MSS_MAX
};
--
2.33.0

View File

@ -1,79 +0,0 @@
From 40c9ea4431e3e2aecfa54dcc48bef55f602be497 Mon Sep 17 00:00:00 2001
From: luzhihao <luzhihao@huawei.com>
Date: Thu, 11 May 2023 14:41:19 +0800
Subject: [PATCH] bugfix: zombie task.
---
src/probes/extends/ebpf.probe/src/ksliprobe/ksliprobe.c | 1 +
src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c | 1 +
src/probes/extends/ebpf.probe/src/sliprobe/redissli.c | 1 +
src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c | 3 +++
4 files changed, 6 insertions(+)
diff --git a/src/probes/extends/ebpf.probe/src/ksliprobe/ksliprobe.c b/src/probes/extends/ebpf.probe/src/ksliprobe/ksliprobe.c
index ac8484e..8f5513f 100644
--- a/src/probes/extends/ebpf.probe/src/ksliprobe/ksliprobe.c
+++ b/src/probes/extends/ebpf.probe/src/ksliprobe/ksliprobe.c
@@ -162,6 +162,7 @@ static int init_conn_mgt_process(int msg_evt_map_fd)
fprintf(stderr, "Failed to create connection read/write message event handler thread.\n");
return -1;
}
+ (void)pthread_detach(msg_evt_hdl_thd);
printf("Connection read/write message event handler thread successfully started!\n");
return 0;
diff --git a/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c b/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c
index 34e749c..bee69b9 100644
--- a/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c
+++ b/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsliprobe.c
@@ -194,6 +194,7 @@ static int init_conn_mgt_process(int msg_evt_map_fd)
fprintf(stderr, "Failed to create connection read/write message event handler thread.\n");
return -1;
}
+ (void)pthread_detach(msg_evt_hdl_thd);
printf("Connection read/write message event handler thread successfully started!\n");
return 0;
diff --git a/src/probes/extends/ebpf.probe/src/sliprobe/redissli.c b/src/probes/extends/ebpf.probe/src/sliprobe/redissli.c
index 19c6fb7..e9b8591 100644
--- a/src/probes/extends/ebpf.probe/src/sliprobe/redissli.c
+++ b/src/probes/extends/ebpf.probe/src/sliprobe/redissli.c
@@ -131,6 +131,7 @@ static int init_conn_mgt_process(int cmd_evt_map_fd)
fprintf(stderr, "Failed to create connection command event handler thread.\n");
return -1;
}
+ (void)pthread_detach(cmd_evt_hdl_thd);
printf("Connection command event handler thread successfully started!\n");
return 0;
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
index f050c27..41ad62e 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
@@ -1386,6 +1386,7 @@ cleanup:
ERROR("[STACKPROBE]: attach memleak bpf failed %d\n", err);
return -1;
}
+ (void)pthread_detach(uprobe_attach_thd);
#endif
INFO("[STACKPROBE]: attach memleak bpf succeed.\n");
@@ -1576,6 +1577,7 @@ static void init_wr_flame_pthreads(struct svg_stack_trace_s *svg_st, const char
g_stop = 1;
return;
}
+ (void)pthread_detach(wr_flame_thd);
INFO("[STACKPROBE]: %s wr_flame_pthread successfully started!\n", flame_name);
return;
@@ -1641,6 +1643,7 @@ static void init_java_support_proc(StackprobeConfig *conf)
ERROR("[STACKPROBE]: Failed to create java_support_pthread.\n");
return;
}
+ (void)pthread_detach(attach_thd);
INFO("[STACKPROBE]: java_support_pthread successfully started!\n");
return;
--
2.33.0

View File

@ -1,52 +0,0 @@
From 921f54938ae1f5b4d3d9486832c98896aaa88ddf Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Thu, 27 Apr 2023 09:24:12 +0800
Subject: [PATCH] cadvisor_probe:convert container_id type to bytes
---
.../cadvisor.probe/cadvisor_probe.py | 20 +++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
index 81226d0..3f87134 100644
--- a/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
+++ b/src/probes/extends/python.probe/cadvisor.probe/cadvisor_probe.py
@@ -220,15 +220,17 @@ class BasicLabelProbe(Probe):
self.get_all_containers()
for container_id in self.container_ids:
+ # ctype c_char_p is bytes in python3, convert str to bytes
+ container_id_bytes = str.encode(container_id)
g_metric[table_name][container_id] = dict()
g_metric[table_name][container_id]['container_id'] = container_id
- g_metric[table_name][container_id]['proc_id'] = self.get_container_pid(container_id)
- g_metric[table_name][container_id]['name'] = self.get_container_name(container_id)
- g_metric[table_name][container_id]['cpucg_inode'] = self.get_container_cpucg_inode(container_id)
- g_metric[table_name][container_id]['memcg_inode'] = self.get_container_memcg_inode(container_id)
- g_metric[table_name][container_id]['pidcg_inode'] = self.get_container_pidcg_inode(container_id)
- g_metric[table_name][container_id]['mnt_ns_id'] = self.get_container_mntns_id(container_id)
- g_metric[table_name][container_id]['net_ns_id'] = self.get_container_netns_id(container_id)
+ g_metric[table_name][container_id]['proc_id'] = self.get_container_pid(container_id_bytes)
+ g_metric[table_name][container_id]['name'] = self.get_container_name(container_id_bytes)
+ g_metric[table_name][container_id]['cpucg_inode'] = self.get_container_cpucg_inode(container_id_bytes)
+ g_metric[table_name][container_id]['memcg_inode'] = self.get_container_memcg_inode(container_id_bytes)
+ g_metric[table_name][container_id]['pidcg_inode'] = self.get_container_pidcg_inode(container_id_bytes)
+ g_metric[table_name][container_id]['mnt_ns_id'] = self.get_container_mntns_id(container_id_bytes)
+ g_metric[table_name][container_id]['net_ns_id'] = self.get_container_netns_id(container_id_bytes)
g_metric[table_name][container_id]['value'] = '0'
@@ -334,7 +336,9 @@ class CadvisorProbe(Probe):
g_metric[table_name][hashed_metric_str]['container_id'] = container_id
metric_name = line[line.index("_") + 1:line.index("{")]
- value = line[(line.index(" ") + 1):self.find_2nd_index(line, " ")]
+ value_start_index = line.index("}") + 1
+ value_end_index = value_start_index + self.find_2nd_index(line[value_start_index:], " ")
+ value = line[value_start_index:value_end_index]
try:
if g_meta[table_name][metric_name] == COUNTER:
if metric_name in g_metric[table_name][hashed_metric_str]:
--
2.33.0

View File

@ -1,629 +0,0 @@
From 7e2c2a1364b0e26098927ad5e976b6f9cddb5744 Mon Sep 17 00:00:00 2001
From: wo_cow <niuqianqian@huawei.com>
Date: Mon, 20 Mar 2023 14:51:22 +0800
Subject: [PATCH 19/30] change return type of uprobe from void to int
---
.../src/dnsmasqprobe/trace_dnsmasq.bpf.c | 2 +-
.../src/haproxyprobe/trace_haproxy.bpf.c | 6 ++--
.../ebpf.probe/src/httpprobe/sslprobe.bpf.c | 17 ++++++-----
.../ebpf.probe/src/include/__bpf_usr.h | 17 ++++++-----
.../src/nginxprobe/nginx_probe.bpf.c | 29 ++++++++++---------
.../src/pgsliprobe/pgsli_uprobe.bpf.c | 10 +++----
.../ebpf.probe/src/sliprobe/redissli.bpf.c | 26 ++++++++++-------
.../src/stackprobe/stack_bpf/memleak.bpf.c | 24 +++++++++++++--
.../ebpf.probe/src/taskprobe/glibc.bpf.c | 2 ++
9 files changed, 81 insertions(+), 52 deletions(-)
diff --git a/src/probes/extends/ebpf.probe/src/dnsmasqprobe/trace_dnsmasq.bpf.c b/src/probes/extends/ebpf.probe/src/dnsmasqprobe/trace_dnsmasq.bpf.c
index 7338fce..cc49723 100644
--- a/src/probes/extends/ebpf.probe/src/dnsmasqprobe/trace_dnsmasq.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/dnsmasqprobe/trace_dnsmasq.bpf.c
@@ -63,5 +63,5 @@ UPROBE(send_from, pt_regs)
/* update hash map */
bpf_map_update_elem(&dns_query_link_map, &key, &value, BPF_ANY);
- return;
+ return 0;
}
\ No newline at end of file
diff --git a/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.bpf.c b/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.bpf.c
index 6280ce8..ff0c9e1 100644
--- a/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.bpf.c
@@ -127,7 +127,7 @@ UPROBE(back_establish, pt_regs)
/* update hash map */
bpf_map_update_elem(&haproxy_link_map, &key, &value, BPF_ANY);
- return;
+ return 0;
}
UPROBE(stream_free, pt_regs)
@@ -142,7 +142,7 @@ UPROBE(stream_free, pt_regs)
value_p = bpf_map_lookup_elem(&haproxy_link_map, &key);
if (value_p == (void *)0) {
bpf_printk("===haproxy free stream not in hash map.\n");
- return;
+ return 0;
}
/* update link state */
value_p->state = SI_ST_CLO;
@@ -150,5 +150,5 @@ UPROBE(stream_free, pt_regs)
/* update hash map */
bpf_map_update_elem(&haproxy_link_map, &key, value_p, BPF_ANY);
- return;
+ return 0;
}
\ No newline at end of file
diff --git a/src/probes/extends/ebpf.probe/src/httpprobe/sslprobe.bpf.c b/src/probes/extends/ebpf.probe/src/httpprobe/sslprobe.bpf.c
index 00e41e8..478baae 100644
--- a/src/probes/extends/ebpf.probe/src/httpprobe/sslprobe.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/httpprobe/sslprobe.bpf.c
@@ -72,23 +72,24 @@ UPROBE_RET(SSL_read, pt_regs, CTX_USER)
if (PROBE_GET_PARMS(SSL_read, ctx, val, CTX_USER) < 0 || (int)PT_REGS_RC(ctx) < REQ_BUF_SIZE) {
bpf_printk("SSL_read fail...");
- return;
+ return 0;
}
key.tgid = bpf_get_current_pid_tgid() >> TGID_LSHIFT_LEN;
ssl_st_p = (struct ssl_st*)PROBE_PARM1(val);
key.skfd = get_fd_from_ssl(ssl_st_p, MSG_READ);
data = bpf_map_lookup_elem(&conn_map, &key);
if (data == NULL || data->status == READY_FOR_SEND) {
- return;
+ return 0;
}
bpf_probe_read(buf, REQ_BUF_SIZE, (const char *)PROBE_PARM2(val));
data->method = parse_req_method(buf);
if (data->method == HTTP_UNKNOWN) {
data->status = READY_FOR_RECVIVE;
- return;
+ return 0;
}
data->status = READY_FOR_SEND;
data->recvtime = bpf_ktime_get_ns();
+ return 0;
}
UPROBE_RET(SSL_write, pt_regs, CTX_USER)
@@ -102,23 +103,23 @@ UPROBE_RET(SSL_write, pt_regs, CTX_USER)
if (PROBE_GET_PARMS(SSL_write, ctx, val, CTX_USER) < 0 || (int)PT_REGS_RC(ctx) <= REQ_BUF_SIZE - 1) {
bpf_printk("SSL_write fail...");
- return;
+ return 0;
}
ckey.tgid = bpf_get_current_pid_tgid() >> TGID_LSHIFT_LEN ;
ssl_st_p = (struct ssl_st*)PROBE_PARM1(val);
ckey.skfd = get_fd_from_ssl(ssl_st_p, MSG_WRITE);
cdata = bpf_map_lookup_elem(&conn_map, &ckey);
if (cdata == NULL || cdata->status == READY_FOR_RECVIVE) {
- return;
+ return 0;
}
cskey.sk = (struct sock *)cdata->sock;
if (cskey.sk == 0) {
- return;
+ return 0;
}
csdata = (struct conn_samp_data_t *)bpf_map_lookup_elem(&conn_samp_map, &cskey);
if (csdata == NULL) {
- return;
+ return 0;
}
csdata->method = cdata->method;
csdata->status = READY_FOR_SKBSENT;
@@ -128,5 +129,5 @@ UPROBE_RET(SSL_write, pt_regs, CTX_USER)
cdata->status = READY_FOR_RECVIVE;
cdata->recvtime = 0;
cdata->method = HTTP_UNKNOWN;
- return;
+ return 0;
}
\ No newline at end of file
diff --git a/src/probes/extends/ebpf.probe/src/include/__bpf_usr.h b/src/probes/extends/ebpf.probe/src/include/__bpf_usr.h
index 95e7160..75ac747 100644
--- a/src/probes/extends/ebpf.probe/src/include/__bpf_usr.h
+++ b/src/probes/extends/ebpf.probe/src/include/__bpf_usr.h
@@ -53,40 +53,41 @@
if (ret < 0) { \
bpf_printk("---UPROBE_RET[" #func "] push failed.\n"); \
} \
+ return 0; \
} while (0)
#if (CURRENT_LIBBPF_VERSION >= LIBBPF_VERSION(0, 8))
#define UPROBE(func, type) \
bpf_section("uprobe") \
- void ubpf_##func(struct type *ctx)
+ int ubpf_##func(struct type *ctx)
#define URETPROBE(func, type) \
bpf_section("uretprobe") \
- void ubpf_ret_##func(struct type *ctx)
+ int ubpf_ret_##func(struct type *ctx)
#define UPROBE_RET(func, type, prog_id) \
bpf_section("uprobe") \
- void __uprobe_bpf_##func(struct type *ctx) { \
+ int __uprobe_bpf_##func(struct type *ctx) { \
UPROBE_PARMS_STASH(func, ctx, prog_id); \
} \
\
bpf_section("uretprobe") \
- void __uprobe_ret_bpf_##func(struct type *ctx)
+ int __uprobe_ret_bpf_##func(struct type *ctx)
#else
#define UPROBE(func, type) \
bpf_section("uprobe/" #func) \
- void ubpf_##func(struct type *ctx)
+ int ubpf_##func(struct type *ctx)
#define URETPROBE(func, type) \
bpf_section("uretprobe/" #func) \
- void ubpf_ret_##func(struct type *ctx)
+ int ubpf_ret_##func(struct type *ctx)
#define UPROBE_RET(func, type, prog_id) \
bpf_section("uprobe/" #func) \
- void __uprobe_bpf_##func(struct type *ctx) { \
+ int __uprobe_bpf_##func(struct type *ctx) { \
UPROBE_PARMS_STASH(func, ctx, prog_id); \
} \
\
bpf_section("uretprobe/" #func) \
- void __uprobe_ret_bpf_##func(struct type *ctx)
+ int __uprobe_ret_bpf_##func(struct type *ctx)
#endif
#endif
diff --git a/src/probes/extends/ebpf.probe/src/nginxprobe/nginx_probe.bpf.c b/src/probes/extends/ebpf.probe/src/nginxprobe/nginx_probe.bpf.c
index 159966d..a710d07 100644
--- a/src/probes/extends/ebpf.probe/src/nginxprobe/nginx_probe.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/nginxprobe/nginx_probe.bpf.c
@@ -66,19 +66,19 @@ UPROBE(ngx_http_upstream_handler, pt_regs)
struct ngx_connection_s *c = (struct ngx_connection_s *)_(evt->data);
if (c == (void *)0)
- return;
+ return 0;
struct ngx_http_request_s *r = (struct ngx_http_request_s *)_(c->data);
if (r == (void *)0)
- return;
+ return 0;
struct ngx_http_upstream_s *u = (struct ngx_http_upstream_s *)_(r->upstream);
if (u == (void *)0)
- return;
+ return 0;
c = (struct ngx_connection_s *)_(r->connection);
if (c == (void *)0)
- return;
+ return 0;
struct ngx_metric metric = {0};
@@ -92,17 +92,17 @@ UPROBE(ngx_http_upstream_handler, pt_regs)
ngx_str_t *p_name;
bpf_probe_read_user(&p_name, sizeof(void **), &(u->peer.name));
if (p_name == (void *)0)
- return;
+ return 0;
unsigned char *dt;
bpf_probe_read_user(&dt, sizeof(void **), &(p_name->data));
if (dt == (void *)0)
- return;
+ return 0;
bpf_probe_read_user_str(metric.dst_ip_str, INET6_ADDRSTRLEN, dt);
bpf_map_update_elem(&hs, &(metric.src_ip), &metric, BPF_ANY);
- return;
+ return 0;
}
UPROBE(ngx_stream_proxy_init_upstream, pt_regs)
@@ -112,6 +112,7 @@ UPROBE(ngx_stream_proxy_init_upstream, pt_regs)
struct ngx_stream_session_s *s = (struct ngx_stream_session_s *)PT_REGS_PARM1(ctx);
bpf_map_update_elem(&para_hs, &tid, &s, BPF_ANY);
+ return 0;
}
URETPROBE(ngx_stream_proxy_init_upstream, pt_regs)
@@ -132,7 +133,7 @@ URETPROBE(ngx_stream_proxy_init_upstream, pt_regs)
t = (struct ngx_stream_session_s **)bpf_map_lookup_elem(&para_hs, &tid);
if (t == (void *)0) {
bpf_printk("bpf_map_lookup_elem para_hs tid:%lu failed\n", tid);
- return;
+ return 0;
}
s = *t;
@@ -147,24 +148,24 @@ URETPROBE(ngx_stream_proxy_init_upstream, pt_regs)
bpf_probe_read_user(&stream, sizeof(void **), &(s->upstream));
if (stream == (void *)0) {
bpf_printk("stream null:%p\n", stream);
- return;
+ return 0;
}
p_name = _(stream->peer.name);
if (p_name == (void *)0) {
bpf_printk("peer.name null\n");
- return;
+ return 0;
}
unsigned char *dt = _(p_name->data);
if (dt == (void *)0) {
bpf_printk("name->data null\n");
- return;
+ return 0;
}
bpf_probe_read_user_str(metric.dst_ip_str, INET6_ADDRSTRLEN, dt);
bpf_map_update_elem(&hs, &(metric.src_ip), &metric, BPF_ANY);
- return;
+ return 0;
}
UPROBE(ngx_close_connection, pt_regs)
@@ -179,9 +180,9 @@ UPROBE(ngx_close_connection, pt_regs)
bpf_copy_ip_addr(client_addr, &src_ip);
metric = (struct ngx_metric *)bpf_map_lookup_elem(&hs, &src_ip);
if (metric == (void *)0)
- return;
+ return 0;
metric->is_finish = 1;
bpf_map_update_elem(&hs, &src_ip, metric, BPF_ANY);
- return;
+ return 0;
}
\ No newline at end of file
diff --git a/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsli_uprobe.bpf.c b/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsli_uprobe.bpf.c
index 2630ce9..eb1241c 100644
--- a/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsli_uprobe.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/pgsliprobe/pgsli_uprobe.bpf.c
@@ -77,29 +77,29 @@ UPROBE(SSL_read, pt_regs)
URETPROBE(SSL_read, pt_regs)
{
- u32 tgid __maybe_unused = bpf_get_current_pid_tgid() >> INT_LEN;
struct probe_val val;
if (PROBE_GET_PARMS(SSL_read, ctx, val, PROG_SSL_READ) < 0) {
- return;
+ return 0;
}
struct ssl_st* ssl_st_p = (struct ssl_st*)PROBE_PARM1(val);
int fd = get_fd_from_ssl(ssl_st_p, MSG_READ);
if (fd < 0) {
- return;
+ return 0;
}
process_rdwr_msg(fd, (const char *)PROBE_PARM2(val), (int)PT_REGS_RC(ctx), MSG_READ, ctx);
+ return 0;
}
UPROBE(SSL_write, pt_regs)
{
- u32 tgid __maybe_unused = bpf_get_current_pid_tgid() >> INT_LEN;
struct ssl_st* ssl_st_p = (struct ssl_st*)PT_REGS_PARM1(ctx);
int fd = get_fd_from_ssl(ssl_st_p, MSG_WRITE);
if (fd < 0) {
- return;
+ return 0;
}
process_rdwr_msg(fd, (char *)PT_REGS_PARM2(ctx), (int)PT_REGS_PARM3(ctx), MSG_WRITE, ctx);
+ return 0;
}
diff --git a/src/probes/extends/ebpf.probe/src/sliprobe/redissli.bpf.c b/src/probes/extends/ebpf.probe/src/sliprobe/redissli.bpf.c
index 207ac00..f3f609c 100644
--- a/src/probes/extends/ebpf.probe/src/sliprobe/redissli.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/sliprobe/redissli.bpf.c
@@ -126,17 +126,18 @@ UPROBE(readQueryFromClient, pt_regs)
conn_data = create_conn_from_client(c);
}
if (conn_data == (void *)0) {
- return;
+ return 0;
}
// 当前周期已有采样数据时,不更新客户端连接
if (conn_data->cmd_nums > 0) {
- return;
+ return 0;
}
conn_data->last_read_ts_nsec = ts_nsec;
conn_data->rd_bufsize = 0;
conn_data->rd_listsize = 0;
+ return 0;
}
// 监控 redis 命令处理函数,获取命令的元数据信息
@@ -152,12 +153,12 @@ UPROBE(processCommand, pt_regs)
conn_data = get_conn_from_client(c);
if (conn_data == (void *)0) {
- return;
+ return 0;
}
// 当前周期已有采样数据时,后续数据不再处理
if (conn_data->cmd_nums > 0) {
- return;
+ return 0;
}
// 添加一个新请求
@@ -189,13 +190,13 @@ URETPROBE(processCommand, pt_regs)
u64 cur_listpos;
if (PROBE_GET_PARMS(processCommand, ctx, val, PROG_PROCESSCOMMAND) < 0) {
- return;
+ return 0;
}
c = (client *)PROBE_PARM1(val);
conn_data = get_conn_from_client(c);
if (conn_data == (void *)0) {
- return;
+ return 0;
}
cmd = &(conn_data->cmds[0]);
@@ -215,6 +216,7 @@ URETPROBE(processCommand, pt_regs)
cmd->end_ts_nsec = ts_nsec;
cmd->finished = 1;
}
+ return 0;
}
// 监控 writeToClient 事件,获取应答消息离开应用层的时间点
@@ -227,7 +229,7 @@ UPROBE(writeToClient, pt_regs)
conn_data = get_conn_from_client(c);
if (conn_data == (void *)0) {
- return;
+ return 0;
}
conn_data->cur_bufpos = _(c->bufpos);
conn_data->cur_listpos = _(c->reply_bytes);
@@ -258,13 +260,13 @@ URETPROBE(writeToClient, pt_regs)
u64 period;
if (PROBE_GET_PARMS(writeToClient, ctx, val, PROG_WRITETOCLIENT) < 0) {
- return;
+ return 0;
}
c = (client *)PROBE_PARM1(val);
conn_data = get_conn_from_client(c);
if (conn_data == (void *)0) {
- return;
+ return 0;
}
// 更新客户端连接已处理的响应字节数
@@ -278,7 +280,7 @@ URETPROBE(writeToClient, pt_regs)
}
if (conn_data->cmd_nums == 0) {
- return;
+ return 0;
}
// 当已处理的响应字节数大于 redis 请求的写入位置时,则该请求在应用层处理完毕,记录该请求的结束时间点
@@ -302,6 +304,7 @@ URETPROBE(writeToClient, pt_regs)
conn_data->last_smp_ts_nsec = ts_nsec;
conn_data->cmd_nums = 0;
}
+ return 0;
}
// 端口 redis 客户端连接
@@ -317,7 +320,7 @@ UPROBE(freeClient, pt_regs)
init_conn_key(&conn_key, fd, tgid);
conn_data = (struct conn_data_t *)bpf_map_lookup_elem(&conn_map, &conn_key);
if (conn_data == (void *)0) {
- return;
+ return 0;
}
if (conn_data->cmd_nums > 0 && conn_data->cmds[0].finished) {
@@ -325,4 +328,5 @@ UPROBE(freeClient, pt_regs)
}
bpf_map_delete_elem(&conn_map, &conn_key);
+ return 0;
}
\ No newline at end of file
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/memleak.bpf.c b/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/memleak.bpf.c
index 280b614..a7759d6 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/memleak.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/memleak.bpf.c
@@ -185,6 +185,7 @@ UPROBE(malloc, pt_regs)
{
u64 size = (u64)PT_REGS_PARM1(ctx);
alloc_enter(size);
+ return 0;
}
URETPROBE(malloc, pt_regs)
@@ -192,6 +193,7 @@ URETPROBE(malloc, pt_regs)
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(calloc, pt_regs)
@@ -199,12 +201,14 @@ UPROBE(calloc, pt_regs)
u64 nmemb = (u64)PT_REGS_PARM1(ctx);
u64 size = (u64)PT_REGS_PARM2(ctx);
alloc_enter(nmemb * size);
+ return 0;
}
URETPROBE(calloc, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(realloc, pt_regs)
@@ -214,24 +218,28 @@ UPROBE(realloc, pt_regs)
free_enter(ctx, ptr);
alloc_enter(size);
+ return 0;
}
URETPROBE(realloc, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(mmap, pt_regs)
{
u64 size = (u64)PT_REGS_PARM2(ctx);
alloc_enter(size);
+ return 0;
}
URETPROBE(mmap, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(posix_memalign, pt_regs)
@@ -241,6 +249,7 @@ UPROBE(posix_memalign, pt_regs)
u64 pid = bpf_get_current_pid_tgid();
bpf_map_update_elem(&memalign_allocate, &pid, &memptr, BPF_ANY);
alloc_enter(size);
+ return 0;
}
URETPROBE(posix_memalign, pt_regs)
@@ -249,72 +258,83 @@ URETPROBE(posix_memalign, pt_regs)
u64 addr;
u64 *memptr = (u64 *)bpf_map_lookup_elem(&memalign_allocate, &pid);
if (memptr == 0)
- return;
+ return 0;
bpf_map_delete_elem(&memalign_allocate, &pid);
if (bpf_probe_read_user(&addr, sizeof(u64), &memptr))
- return;
+ return 0;
alloc_exit(ctx, addr);
+ return 0;
}
UPROBE(valloc, pt_regs)
{
u64 size = (u64)PT_REGS_PARM1(ctx);
alloc_enter(size);
+ return 0;
}
URETPROBE(valloc, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(memalign, pt_regs)
{
u64 size = (u64)PT_REGS_PARM1(ctx);
alloc_enter(size);
+ return 0;
}
URETPROBE(memalign, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(pvalloc, pt_regs)
{
u64 size = (u64)PT_REGS_PARM1(ctx);
alloc_enter(size);
+ return 0;
}
URETPROBE(pvalloc, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(aligned_alloc, pt_regs)
{
u64 size = (u64)PT_REGS_PARM2(ctx);
alloc_enter(size);
+ return 0;
}
URETPROBE(aligned_alloc, pt_regs)
{
u64 ret = (u64)PT_REGS_RC(ctx);
alloc_exit(ctx, ret);
+ return 0;
}
UPROBE(free, pt_regs)
{
u64 size = (u64)PT_REGS_PARM2(ctx);
free_enter(ctx, size);
+ return 0;
}
UPROBE(munmap, pt_regs)
{
u64 size = (u64)PT_REGS_PARM1(ctx);
free_enter(ctx, size);
+ return 0;
}
diff --git a/src/probes/extends/ebpf.probe/src/taskprobe/glibc.bpf.c b/src/probes/extends/ebpf.probe/src/taskprobe/glibc.bpf.c
index 3487b22..d4e4373 100644
--- a/src/probes/extends/ebpf.probe/src/taskprobe/glibc.bpf.c
+++ b/src/probes/extends/ebpf.probe/src/taskprobe/glibc.bpf.c
@@ -72,11 +72,13 @@ static __always_inline void update_gethostname_res(struct pt_regs* ctx)
UPROBE(func, pt_regs) \
{ \
start_fn(); \
+ return 0; \
} \
\
URETPROBE(func, pt_regs) \
{ \
stop_fn(ctx); \
+ return 0; \
}
UPROBE_GLIBC(getaddrinfo, store_dns_op_start_ts, update_gethostname_res)
--
2.33.0

View File

@ -1,39 +0,0 @@
From e724fefbd1cbaa610894eab418b3721e798a9c1f Mon Sep 17 00:00:00 2001
From: wo_cow <niuqianqian@huawei.com>
Date: Mon, 8 May 2023 19:41:04 +0800
Subject: [PATCH] fix access violation
---
src/common/container.c | 2 +-
src/common/container.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/common/container.c b/src/common/container.c
index c7981a1..fc081d3 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -486,7 +486,7 @@ int get_elf_path(unsigned int pid, char elf_path[], int max_path_len, const char
{
char cmd[COMMAND_LEN] = {0};
char elf_relative_path[PATH_LEN] = {0};
- char container_id[CONTAINER_ABBR_ID_LEN] = {0};
+ char container_id[CONTAINER_ABBR_ID_LEN + 1] = {0};
char container_path[PATH_LEN] = {0};
// 1. get elf_path
diff --git a/src/common/container.h b/src/common/container.h
index b2dade9..e06a64b 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -29,7 +29,7 @@ enum container_status_e {
typedef struct container_info_s {
enum container_status_e status;
- char abbrContainerId[CONTAINER_ID_LEN];
+ char abbrContainerId[CONTAINER_ID_LEN + 1];
} container_info;
typedef struct container_tbl_s {
--
2.33.0

View File

@ -1,28 +0,0 @@
From 76b7748bd24ab02ac8f26917e590a41fd185c1e7 Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Fri, 12 May 2023 14:38:18 +0800
Subject: [PATCH] fix:add default data of event conf
---
src/common/event.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/common/event.c b/src/common/event.c
index 17fda5c..af98d07 100644
--- a/src/common/event.c
+++ b/src/common/event.c
@@ -27,9 +27,9 @@
#endif
static struct evt_ts_hash_t *g_evt_head = NULL;
-static unsigned int g_evt_period = 0;
+static unsigned int g_evt_period = 600;
static EventsConfig *g_evt_conf;
-static char g_lang_type[MAX_EVT_GRP_NAME_LEN];
+static char g_lang_type[MAX_EVT_GRP_NAME_LEN] = "zh_CN";
static void hash_clear_older_evt(time_t cur_time);
static unsigned int hash_count_evt(void);
--
2.33.0

View File

@ -1,401 +0,0 @@
From ecdfe5a9a67568bbfdd99d478ad425e66fa2d5e6 Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Tue, 9 May 2023 09:15:02 +0800
Subject: [PATCH] fix: change license software name
---
src/common/event.c | 2 +-
src/common/kern_config.c | 2 +-
src/egress/egress.c | 2 +-
src/egress/egress.h | 2 +-
src/ingress/ingress.c | 2 +-
src/ingress/ingress.h | 2 +-
src/lib/base.h | 2 +-
src/lib/config/config.c | 2 +-
src/lib/config/config.h | 2 +-
src/lib/fifo/fifo.c | 2 +-
src/lib/fifo/fifo.h | 2 +-
src/lib/imdb/imdb.c | 2 +-
src/lib/imdb/imdb.h | 2 +-
src/lib/imdb/metrics.c | 2 +-
src/lib/kafka/kafka.c | 2 +-
src/lib/kafka/kafka.h | 2 +-
src/lib/meta/meta.c | 2 +-
src/lib/meta/meta.h | 2 +-
src/lib/probe/extend_probe.c | 2 +-
src/lib/probe/extend_probe.h | 2 +-
src/lib/probe/nprobe_fprintf.h | 2 +-
src/lib/probe/probe.c | 2 +-
src/lib/probe/probe.h | 2 +-
src/probes/event.probe/event.c | 2 +-
src/probes/event.probe/event.h | 2 +-
.../extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c | 2 +-
src/resource/resource.c | 2 +-
src/resource/resource.h | 2 +-
src/web_server/web_server.c | 2 +-
src/web_server/web_server.h | 2 +-
30 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/src/common/event.c b/src/common/event.c
index 31eb899..17fda5c 100644
--- a/src/common/event.c
+++ b/src/common/event.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/common/kern_config.c b/src/common/kern_config.c
index 2615652..3d8a22f 100644
--- a/src/common/kern_config.c
+++ b/src/common/kern_config.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/egress/egress.c b/src/egress/egress.c
index 0935d82..ec2484b 100644
--- a/src/egress/egress.c
+++ b/src/egress/egress.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/egress/egress.h b/src/egress/egress.h
index 316c1af..0c40bfe 100644
--- a/src/egress/egress.h
+++ b/src/egress/egress.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/ingress/ingress.c b/src/ingress/ingress.c
index 51a17c8..d7b5f64 100644
--- a/src/ingress/ingress.c
+++ b/src/ingress/ingress.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/ingress/ingress.h b/src/ingress/ingress.h
index 927b5ed..da6ee87 100644
--- a/src/ingress/ingress.h
+++ b/src/ingress/ingress.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/base.h b/src/lib/base.h
index a5d9c21..3d97816 100644
--- a/src/lib/base.h
+++ b/src/lib/base.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/config/config.c b/src/lib/config/config.c
index d8ce2a5..ac836cb 100644
--- a/src/lib/config/config.c
+++ b/src/lib/config/config.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/config/config.h b/src/lib/config/config.h
index 6eefc69..30af00a 100644
--- a/src/lib/config/config.h
+++ b/src/lib/config/config.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/fifo/fifo.c b/src/lib/fifo/fifo.c
index 7b5d784..be4a90a 100644
--- a/src/lib/fifo/fifo.c
+++ b/src/lib/fifo/fifo.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/fifo/fifo.h b/src/lib/fifo/fifo.h
index 88d445a..ae2b03c 100644
--- a/src/lib/fifo/fifo.h
+++ b/src/lib/fifo/fifo.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/imdb/imdb.c b/src/lib/imdb/imdb.c
index 453c1fe..51508b2 100644
--- a/src/lib/imdb/imdb.c
+++ b/src/lib/imdb/imdb.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/imdb/imdb.h b/src/lib/imdb/imdb.h
index 4d93c40..7832ea6 100644
--- a/src/lib/imdb/imdb.h
+++ b/src/lib/imdb/imdb.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/imdb/metrics.c b/src/lib/imdb/metrics.c
index 64f6335..89c75f5 100644
--- a/src/lib/imdb/metrics.c
+++ b/src/lib/imdb/metrics.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/kafka/kafka.c b/src/lib/kafka/kafka.c
index a240cd4..b6d4a4e 100644
--- a/src/lib/kafka/kafka.c
+++ b/src/lib/kafka/kafka.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/kafka/kafka.h b/src/lib/kafka/kafka.h
index 1e5c52a..bbe921a 100644
--- a/src/lib/kafka/kafka.h
+++ b/src/lib/kafka/kafka.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/meta/meta.c b/src/lib/meta/meta.c
index 12b3576..632741a 100644
--- a/src/lib/meta/meta.c
+++ b/src/lib/meta/meta.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/meta/meta.h b/src/lib/meta/meta.h
index 2be952d..809b8a0 100644
--- a/src/lib/meta/meta.h
+++ b/src/lib/meta/meta.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/probe/extend_probe.c b/src/lib/probe/extend_probe.c
index c7de9ed..8c989ce 100644
--- a/src/lib/probe/extend_probe.c
+++ b/src/lib/probe/extend_probe.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/probe/extend_probe.h b/src/lib/probe/extend_probe.h
index cd7721f..204e5d6 100644
--- a/src/lib/probe/extend_probe.h
+++ b/src/lib/probe/extend_probe.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/probe/nprobe_fprintf.h b/src/lib/probe/nprobe_fprintf.h
index 400626c..97e2f72 100644
--- a/src/lib/probe/nprobe_fprintf.h
+++ b/src/lib/probe/nprobe_fprintf.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/probe/probe.c b/src/lib/probe/probe.c
index fb9bfdb..ab84fd3 100644
--- a/src/lib/probe/probe.c
+++ b/src/lib/probe/probe.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/lib/probe/probe.h b/src/lib/probe/probe.h
index 31fdf20..8faabca 100644
--- a/src/lib/probe/probe.h
+++ b/src/lib/probe/probe.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/probes/event.probe/event.c b/src/probes/event.probe/event.c
index 37578de..7d0f8ca 100644
--- a/src/probes/event.probe/event.c
+++ b/src/probes/event.probe/event.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/probes/event.probe/event.h b/src/probes/event.probe/event.h
index 42fc824..b52ae86 100644
--- a/src/probes/event.probe/event.h
+++ b/src/probes/event.probe/event.h
@@ -1,6 +1,6 @@
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c
index ed6ae19..05d93fb 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/resource/resource.c b/src/resource/resource.c
index 730ecd7..8d62265 100644
--- a/src/resource/resource.c
+++ b/src/resource/resource.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/resource/resource.h b/src/resource/resource.h
index 4308e1e..b5f4edb 100644
--- a/src/resource/resource.h
+++ b/src/resource/resource.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/web_server/web_server.c b/src/web_server/web_server.c
index d65abca..4d8141a 100644
--- a/src/web_server/web_server.c
+++ b/src/web_server/web_server.c
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
diff --git a/src/web_server/web_server.h b/src/web_server/web_server.h
index f436988..f3c53ee 100644
--- a/src/web_server/web_server.h
+++ b/src/web_server/web_server.h
@@ -1,6 +1,6 @@
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
- * iSulad licensed under the Mulan PSL v2.
+ * gala-gopher licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
--
2.33.0

View File

@ -1,96 +0,0 @@
From 80629a576c18dbf132cd9d6a3a6bfc7ae3af516d Mon Sep 17 00:00:00 2001
From: algorithmofdish <hexiujun1@huawei.com>
Date: Wed, 26 Apr 2023 16:58:02 +0800
Subject: [PATCH] fix: fix fd leakage problem
Conficts: src/probes/extends/ebpf.probe/src/{lib->stackprobe}/java_support.c
---
src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.c | 4 ++++
src/probes/extends/ebpf.probe/src/stackprobe/java_support.c | 2 ++
test/test_probes/test_probes.c | 6 ++++++
3 files changed, 12 insertions(+)
diff --git a/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.c b/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.c
index 39e1827..cc5e771 100644
--- a/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.c
+++ b/src/probes/extends/ebpf.probe/src/haproxyprobe/trace_haproxy.c
@@ -55,8 +55,12 @@ static void get_host_ip(const unsigned char *value, unsigned short family)
}
fp = popen(cmd, "r");
+ if (fp == NULL) {
+ return;
+ }
if (fgets(buffer, INET6_ADDRSTRLEN, fp) == NULL) {
printf("Fail get_host_ip.\n");
+ (void)pclose(fp);
return ;
}
(void)pclose(fp);
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c b/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c
index 1aacb99..4a2c736 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c
@@ -211,6 +211,7 @@ static int __check_proc_to_attach(int proc_obj_map_fd)
while (fgets(line, sizeof(line), f)) {
if (sscanf(line, "%d", &pid) != 1) {
+ (void)pclose(f);
return -1;
}
if (proc_obj_map_fd != 0) { // whitelist_enable
@@ -241,6 +242,7 @@ static int __check_proc_to_attach(int proc_obj_map_fd)
}
}
+ (void)pclose(f);
return ret;
}
diff --git a/test/test_probes/test_probes.c b/test/test_probes/test_probes.c
index 6f23117..3c608ca 100644
--- a/test/test_probes/test_probes.c
+++ b/test/test_probes/test_probes.c
@@ -332,14 +332,17 @@ void TestSystemProcProbe(void)
snprintf(cmd, COMMAND_LEN - 1, "touch /tmp/gala-gopher-app.conf");
f = popen(cmd, "r");
CU_ASSERT(f != NULL);
+ (void)pclose(f);
snprintf(cmd, COMMAND_LEN - 1, "echo \'application = ({ comm = \"sleep\", cmdline = \"\"})\' >/tmp/gala-gopher-app.conf");
f = popen(cmd, "r");
CU_ASSERT(f != NULL);
+ (void)pclose(f);
snprintf(cmd, COMMAND_LEN - 1, "sleep 60 &");
f = popen(cmd, "r");
CU_ASSERT(f != NULL);
+ (void)pclose(f);
system_proc_init(&params.task_whitelist);
CU_ASSERT(&params.task_whitelist != NULL);
@@ -353,10 +356,12 @@ void TestSystemProcProbe(void)
snprintf(cmd, COMMAND_LEN - 1, "rm -rf /tmp/gala-gopher-app.conf");
f = popen(cmd, "r");
CU_ASSERT(f != NULL);
+ (void)pclose(f);
snprintf(cmd, COMMAND_LEN - 1, "rm -rf /sys/fs/bpf/gala-gopher");
f = popen(cmd, "r");
CU_ASSERT(f != NULL);
+ (void)pclose(f);
ProbeDestroy(g_probe);
system_proc_destroy();
@@ -388,6 +393,7 @@ void TestEventProbe(void)
snprintf(cmd, COMMAND_LEN - 1, "echo \"%s\" >> /var/log/messages", EVENT_ERR_CODE);
f = popen(cmd, "r");
CU_ASSERT(f != NULL);
+ pclose(f);
g_probe = ProbeCreate();
CU_ASSERT(g_probe != NULL);
--
2.33.0

View File

@ -1,36 +0,0 @@
From 2408b163c4c0a2fdfeac4e710b24391e87b9f6a5 Mon Sep 17 00:00:00 2001
From: dowzyx <zhaoyuxing2@huawei.com>
Date: Wed, 10 May 2023 11:20:25 +0800
Subject: [PATCH] fix: fix install error
---
build/install.sh | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/build/install.sh b/build/install.sh
index d92f135..fce8aeb 100755
--- a/build/install.sh
+++ b/build/install.sh
@@ -37,7 +37,9 @@ function install_daemon_bin()
echo "${GOPHER_BIN_FILE} not exist. please check if build success."
exit 1
fi
-
+ if [ ! -d ${GOPHER_BIN_TARGET_DIR} ]; then
+ mkdir -p ${GOPHER_BIN_TARGET_DIR}
+ fi
# install gala-gopher bin
cp -f ${GOPHER_BIN_FILE} ${GOPHER_BIN_TARGET_DIR}
echo "install ${GOPHER_BIN_FILE} success."
@@ -65,7 +67,7 @@ function install_conf()
# install gala-gopher.conf
if [ ! -d ${GOPHER_CONF_TARGET_DIR} ]; then
- mkdir ${GOPHER_CONF_TARGET_DIR}
+ mkdir -p ${GOPHER_CONF_TARGET_DIR}
fi
cp -f ${GOPHER_CONF_FILE} ${GOPHER_CONF_TARGET_DIR}
echo "install ${GOPHER_CONF_FILE} success."
--
2.33.0

View File

@ -1,50 +0,0 @@
From 78afbbed90b312ff308b5be0fba24d42a3f122ca Mon Sep 17 00:00:00 2001
From: xietangxin <xietangxin@huawei.com>
Date: Thu, 13 Apr 2023 14:35:00 +0800
Subject: [PATCH] fix httpprobe find libssl path
---
src/daemon/daemon.c | 2 +-
src/probes/extends/ebpf.probe/src/httpprobe/httpprobe.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index b10ca60..3b16a75 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -172,7 +172,7 @@ static void DaemonKeeplive(int sig)
(void)pthread_detach(probe->tid);
INFO("[DAEMON] keeplive create probe(%s) thread.\n", probe->name);
- break;
+ continue;
}
}
return;
diff --git a/src/probes/extends/ebpf.probe/src/httpprobe/httpprobe.c b/src/probes/extends/ebpf.probe/src/httpprobe/httpprobe.c
index 477fe43..e64a706 100644
--- a/src/probes/extends/ebpf.probe/src/httpprobe/httpprobe.c
+++ b/src/probes/extends/ebpf.probe/src/httpprobe/httpprobe.c
@@ -42,6 +42,7 @@
#define APACHE_PATH "which httpd"
#define NGINX_SSL_PATH "ldd $(which nginx) | grep libssl | awk '{print $3}'"
#define APACHE_SSL_PATH "ldd /etc/httpd/modules/mod_ssl.so | grep libssl | awk '{print $3}'"
+#define HTTPD_SSL_PATH "/etc/httpd/modules/mod_ssl.so"
#define LOAD_HTTP_PROBE(probe_name, end, load) \
OPEN(probe_name, end, load); \
@@ -81,8 +82,9 @@ static void get_libssl_path(char *nginx_sslpath, char *apache_sslpath)
}
pclose(f1);
f1 = popen(APACHE_PATH, "r");
- if (fgets(buf, PATH_LEN, f1) != NULL && strlen(buf) > 0 && !(buf[strlen(buf) - 1] = 0) && access(buf, F_OK) == 0) {
- if ((f2 = popen(NGINX_SSL_PATH, "r")) != NULL && fgets(apache_sslpath, PATH_LEN, f2) != NULL) {
+ if (fgets(buf, PATH_LEN, f1) != NULL && strlen(buf) > 0 && !(buf[strlen(buf) - 1] = 0) &&
+ access(buf, F_OK) == 0 && access(HTTPD_SSL_PATH, F_OK) == 0) {
+ if ((f2 = popen(APACHE_SSL_PATH, "r")) != NULL && fgets(apache_sslpath, PATH_LEN, f2) != NULL) {
if (strlen(apache_sslpath) != 0) {
apache_sslpath[strlen(apache_sslpath) - 1] = 0;
}
--
2.33.0

View File

@ -1,102 +0,0 @@
From 9ad26e3d4abfb78e99b8d75da384e36badbde75a Mon Sep 17 00:00:00 2001
From: dowzyx <zhaoyuxing2@huawei.com>
Date: Thu, 16 Mar 2023 16:09:07 +0800
Subject: [PATCH 23/30] fix: modify unit of some metrics to second
---
.../extends/java.probe/jvm.probe/jvm_probe.meta | 14 +++++++-------
.../jvm.probe/src/agent/JvmProbeAgent.java | 13 +++++++------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta b/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta
index bb9d01a..d80341a 100755
--- a/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta
+++ b/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta
@@ -18,12 +18,12 @@ measurements:
name: "runtime",
},
{
- description: "....",
+ description: "JVM implementation vender.",
type: "label",
name: "vendor",
},
{
- description: "....",
+ description: "the JVM implementation version.",
type: "label",
name: "version",
},
@@ -163,7 +163,7 @@ measurements:
name: "tgid",
},
{
- description: "....",
+ description: "name representing a memory pool.",
type: "key",
name: "pool",
},
@@ -210,8 +210,8 @@ measurements:
name: "tgid",
},
{
- description: "....",
- type: "label",
+ description: "name representing a buffer pool.",
+ type: "key",
name: "pool",
},
{
@@ -242,8 +242,8 @@ measurements:
name: "tgid",
},
{
- description: "....",
- type: "label",
+ description: "name representing a GC.",
+ type: "key",
name: "gc",
},
{
diff --git a/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java b/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
index 488c73c..d7f635d 100644
--- a/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
+++ b/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
@@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException;
public class JvmProbeAgent {
private static final int MSEC_PER_SEC = 1000;
- private static final int NSEC_PER_SEC = 1000000;
+ private static final int NSEC_PER_SEC = 1000000000;
private static final String METRIC_FILE_NAME = "jvm-metrics.txt";
private static String pid;
private static String nspid;
@@ -79,10 +79,11 @@ public class JvmProbeAgent {
}
private static void processCollector(RuntimeMXBean runtimeBean, OperatingSystemMXBean osBean) {
- long processStartTime = runtimeBean.getStartTime(); // ms
+ long processStartTime = runtimeBean.getStartTime(); // ms
try {
- Long processCpuTime = callLongGetter(osBean.getClass().getMethod("getProcessCpuTime"), osBean); // ns
- writeMetricRecords(String.format("|jvm_process|%s|%d|%d|\n", pid, processStartTime, processCpuTime));
+ Long processCpuTime = callLongGetter(osBean.getClass().getMethod("getProcessCpuTime"), osBean); // ns
+ writeMetricRecords(String.format("|jvm_process|%s|%f|%f|\n",
+ pid, ((double)processStartTime / MSEC_PER_SEC), ((double)processCpuTime / NSEC_PER_SEC)));
} catch (Exception e) {
//System.out.println("error");
}
@@ -169,8 +170,8 @@ public class JvmProbeAgent {
// gc
private static void gcCollector(List<GarbageCollectorMXBean> garbageCollectors) {
for (GarbageCollectorMXBean gc : garbageCollectors) {
- writeMetricRecords(String.format("|jvm_gc|%s|%s|%d|%d|\n",
- pid, gc.getName(), gc.getCollectionCount(), gc.getCollectionTime())); // ms
+ writeMetricRecords(String.format("|jvm_gc|%s|%s|%d|%f|\n",
+ pid, gc.getName(), gc.getCollectionCount(), ((double)gc.getCollectionTime() / MSEC_PER_SEC)));
}
}
--
2.33.0

View File

@ -1,47 +0,0 @@
From cabacb208974b002f01268e988a0b32062d0f730 Mon Sep 17 00:00:00 2001
From: sjxur <sjxur@isoftstone.com>
Date: Wed, 19 Apr 2023 16:32:20 +0800
Subject: [PATCH] fix prepare_dependence
---
build/build.sh | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/build/build.sh b/build/build.sh
index d66da9a..696a902 100755
--- a/build/build.sh
+++ b/build/build.sh
@@ -228,6 +228,30 @@ function prepare_dependence()
return 1
fi
+ yum install -y libbpf-devel
+ if [ $? -ne 0 ];then
+ echo "Error: Failed to install libbpf-devel."
+ return 1
+ fi
+
+ yum install -y clang
+ if [ $? -ne 0 ];then
+ echo "Error: Failed to install clang."
+ return 1
+ fi
+
+ yum install -y llvm
+ if [ $? -ne 0 ];then
+ echo "Error: Failed to install llvm."
+ return 1
+ fi
+
+ yum install -y java-1.8.0-openjdk-devel
+ if [ $? -ne 0 ];then
+ echo "Error: Failed to install java-1.8.0-openjdk-devel"
+ return 1
+ fi
+
return 0
}
--
2.33.0

Binary file not shown.

BIN
gala-gopher-2.0.1.tar.gz Normal file

Binary file not shown.

View File

@ -1,47 +1,99 @@
#needsrootforbuild
%define __os_install_post %{nil}
%define vmlinux_ver 5.10.0-126.0.0.66.oe2203.%{_arch}
%define without_baseinfo 0
%define without_virt 0
%define without_flamegraph 0
%define without_l7 0
%define without_tcp 0
%define without_socket 0
%define without_io 0
%define without_proc 0
%define without_jvm 0
%define without_postgre_sli 0
%define without_opengauss_sli 0
%define without_nginx 1
%define without_tprofiling 0
%define without_kafka 1
%define without_hw 1
%define without_ksli 0
%define without_container 0
%define without_sermant 1
%define disable_report_event 0
%define disable_kafka_channel 0
%define disable_flamegraph_svg 0
Summary: Intelligent ops toolkit for openEuler
Name: gala-gopher
Version: 1.0.2
Release: 4
Version: 2.0.1
Release: 1
License: Mulan PSL v2
URL: https://gitee.com/openeuler/gala-gopher
Source: %{name}-%{version}.tar.gz
BuildRoot: %{_builddir}/%{name}-%{version}
BuildRequires: systemd cmake gcc-c++ elfutils-devel libcurl-devel
BuildRequires: clang >= 10.0.1 llvm java-1.8.0-openjdk-devel
BuildRequires: libconfig-devel librdkafka-devel libmicrohttpd-devel
BuildRequires: libbpf-devel >= 2:0.3 uthash-devel log4cplus-devel
BuildRequires: CUnit CUnit-devel dmidecode junit ethtool bpftool procps-ng iproute
Requires: bash glibc elfutils bpftool dmidecode
Requires: python3-psycopg2 python3-yaml flamegraph iproute libcurl
Requires: libbpf >= 2:0.3 kmod net-tools ethtool cadvisor python3-libconf python3-requests
BuildRequires: systemd cmake gcc-c++ elfutils-devel clang llvm bpftool >= 6.8
BuildRequires: libconfig-devel libevent-devel openssl-devel libbpf-devel >= 2:0.8 uthash-devel
BuildRequires: jsoncpp-devel git libstdc++-devel
# for DT
#BuildRequires: CUnit-devel
%if !0%{?disable_kafka_channel}
BuildRequires: librdkafka-devel
%endif
%if !0%{?without_flamegraph}
BuildRequires: libcurl-devel
%endif
%if !0%{?without_jvm}
BuildRequires: java-1.8.0-openjdk-devel
%endif
%if !0%{?without_l7}
BuildRequires: jsoncpp-devel java-1.8.0-openjdk-devel
%endif
Requires: bash gawk procps-ng glibc elfutils libbpf >= 2:0.8
Requires: libconfig libevent iproute jsoncpp libstdc++
%if !0%{?disable_kafka_channel}
Requires: librdkafka
%endif
%if !0%{?without_baseinfo}
Requires: ethtool systemd iproute
%endif
%if !0%{?without_virt}
Requires: systemd
%endif
%if !0%{?without_tcp}
Requires: iproute conntrack-tools
%endif
%if !0%{?without_proc}
Requires: kmod
%endif
%if !0%{?without_flamegraph}
%if !0%{?disable_flamegraph_svg}
Requires: flamegraph
%endif
Requires: libcurl
%endif
%if !0%{?without_opengauss_sli}
Requires: python3-psycopg2 python3-yaml net-tools
%endif
%if !0%{?without_container}
Requires: cadvisor python3-libconf python3-requests net-tools util-linux
%endif
%if !0%{?without_postgre_sli}
Requires: iproute
%endif
%if !0%{?without_l7}
Requires: jsoncpp conntrack-tools
%endif
%if !0%{?without_tprofiling}
Requires: lsof
%endif
Patch1: refactor-modify-jvmprobe-to-support-pod.patch
Patch2: change-return-type-of-uprobe-from-void-to-int.patch
Patch3: fix-modify-unit-of-some-metrics-to-second.patch
Patch4: bugfix-fix-system_proc-collect-data-err.patch
Patch5: Fix-for-popen-cannot-get-stderr.patch
Patch6: bugfix-add-check-whether-cadvisor-is-installed.patch
Patch7: stackprobe-fix-inaccurate-call-stack-count.-add-samp.patch
Patch8: fix-httpprobe-find-libssl-path.patch
Patch9: Fix-segmentation-fault-of-gala-gopher-cmd.patch
Patch10: fix-prepare_dependence.patch
Patch11: bugfix-The-log-time-is-not-the-local-time.patch
Patch12: fix-fix-fd-leakage-problem.patch
Patch13: cadvisor_probe-convert-container_id-type-to-bytes.patch
Patch14: adapt-block_rq_issue-tracepoint-args-in-kernel-5.10.patch
Patch15: modify-desc-from-chinese-to-english.patch
Patch16: bugfix-fix-gala-gopher-h-print-err.patch
Patch17: fix-change-license-software-name.patch
Patch18: fix-fix-install-error.patch
Patch19: bugfix-zombie-task.patch
Patch20: fix-add-default-data-of-event-conf.patch
Patch21: fix-access-violation.patch
Patch22: ioprobe-fix-command-injection.patch
%description
gala-gopher is a low-overhead eBPF-based probes framework
@ -49,30 +101,65 @@ gala-gopher is a low-overhead eBPF-based probes framework
%prep
%autosetup -n %{name}-%{version} -p1
%build
BUILD_OPTS=(
-DENABLE_BASEINFO=%[0%{?without_baseinfo}?0:1]
-DENABLE_VIRT=%[0%{?without_virt}?0:1]
-DENABLE_FLAMEGRAPH=%[0%{?without_flamegraph}?0:1]
-DENABLE_L7=%[0%{?without_l7}?0:1]
-DENABLE_TCP=%[0%{?without_tcp}?0:1]
-DENABLE_SOCKET=%[0%{?without_tcp}?0:1]
-DENABLE_IO=%[0%{?without_io}?0:1]
-DENABLE_PROC=%[0%{?without_proc}?0:1]
-DENABLE_JVM=%[0%{?without_jvm}?0:1]
-DENABLE_POSTGRE_SLI=%[0%{?without_postgre_sli}?0:1]
-DENABLE_OPENGAUSS_SLI=%[0%{?without_opengauss_sli}?0:1]
-DENABLE_NGINX=%[0%{?without_nginx}?0:1]
-DENABLE_TPROFILING=%[0%{?without_tprofiling}?0:1]
-DENABLE_KAFKA=%[0%{?without_kafka}?0:1]
-DENABLE_HW=%[0%{?without_hw}?0:1]
-DENABLE_KSLI=%[0%{?without_ksli}?0:1]
-DENABLE_CONTAINER=%[0%{?without_cadvisor}?0:1]
-DENABLE_SERMANT=%[0%{?without_sermant}?0:1]
-DENABLE_REPORT_EVENT=%[0%{?disable_report_event}?0:1]
-DKAFKA_CHANNEL=%[0%{?disable_kafka_channel}?0:1]
-DFLAMEGRAPH_SVG=%[0%{?disable_flamegraph_svg}?0:1]
)
pushd build
sh build.sh --release %{vmlinux_ver}
export PATH=$PATH:/usr/lib64/llvm12/bin
sh build.sh --debug "${BUILD_OPTS[@]}"
popd
%check
pushd test
sh test_modules.sh
sh test_extend_probes.sh
sh test_probes.sh
popd
# pushd test
# sh test_modules.sh "${BUILD_OPTS[@]}"
# popd
%install
install -d %{buildroot}/etc/gala-gopher
install -d %{buildroot}/opt/gala-gopher
install -d %{buildroot}%{_bindir}
install -d %{buildroot}/usr/libexec/gala-gopher/
mkdir -p %{buildroot}/usr/lib/systemd/system
install -m 0600 service/gala-gopher.service %{buildroot}/usr/lib/systemd/system/gala-gopher.service
pushd build
sh install.sh %{buildroot}%{_bindir} %{buildroot}/opt/gala-gopher %{buildroot}/etc/gala-gopher
sh install.sh %{buildroot}%{_bindir} %{buildroot}/opt/gala-gopher %{buildroot}/etc/gala-gopher %{buildroot}/usr/libexec/gala-gopher/ %{buildroot}/opt/gala-gopher
popd
%post
%systemd_post gala-gopher.service
if [ -d /var/log/gala-gopher ]; then
othermode=$(expr $(stat -L -c "%a" /var/log/gala-gopher) % 10)
if [ $othermode -ne 0 ]; then
chmod 750 /var/log/gala-gopher
chmod 750 /var/log/gala-gopher/debug
chmod 640 /var/log/gala-gopher/debug/gopher.log
fi
fi
%preun
%systemd_preun gala-gopher.service
@ -84,23 +171,26 @@ fi
%systemd_postun_with_restart gala-gopher.service
%files
%defattr(-,root,root)
%dir /opt/gala-gopher
%dir /opt/gala-gopher/extend_probes
%dir /opt/gala-gopher/meta
%dir /opt/gala-gopher/lib
%{_bindir}/*
/opt/gala-gopher/extend_probes/*
/opt/gala-gopher/meta/*
/opt/gala-gopher/lib/*
/etc/gala-gopher/res/event_multy_language.rc
%config(noreplace) /etc/gala-gopher/*.conf
%config(noreplace) /etc/gala-gopher/extend_probes/*.conf
%exclude /opt/gala-gopher/extend_probes/*.pyc
%exclude /opt/gala-gopher/extend_probes/*.pyo
/usr/lib/systemd/system/gala-gopher.service
%attr(0750,root,root) %dir /opt/gala-gopher
%attr(0550,root,root) %dir /opt/gala-gopher/extend_probes
%attr(0750,root,root) %dir /opt/gala-gopher/meta
%attr(0750,root,root) %dir /opt/gala-gopher/btf
%attr(0550,root,root) %dir /opt/gala-gopher/lib
%attr(0550,root,root) %{_bindir}/*
%attr(0550,root,root) /opt/gala-gopher/extend_probes/*
%attr(0640,root,root) /opt/gala-gopher/meta/*
#%attr(0640,root,root) /opt/gala-gopher/btf/*
%attr(0550,root,root) /opt/gala-gopher/lib/*
%attr(0640,root,root) %config(noreplace) /etc/gala-gopher/probes.init
%attr(0640,root,root) %config(noreplace) /etc/gala-gopher/*.conf
%attr(0640,root,root) %config(noreplace) /etc/gala-gopher/extend_probes/*.conf
%attr(0600,root,root) /usr/lib/systemd/system/gala-gopher.service
%attr(0550,root,root) /usr/libexec/gala-gopher/init_probes.sh
%changelog
* Wed Apr 24 2024 Tangxin Xie <xietangxin@huawei.com> - 2.0.0-1
- Update to 2.0.1
* Fri Mar 8 2024 Zhen Chen <chenzhen126@huawei.com> - 1.0.2-4
- fix command injection in ioprobe

View File

@ -1,93 +0,0 @@
From e37d4df29ff7191bff516f30a0640ed1a0791264 Mon Sep 17 00:00:00 2001
From: Vchanger <chenzhen126@huawei.com>
Date: Mon, 4 Mar 2024 20:22:55 +0800
Subject: [PATCH] ioprobe: fix command injection
---
src/common/common.h | 1 +
src/common/util.c | 24 +++++++++++++++++++
.../extends/ebpf.probe/src/ioprobe/ioprobe.c | 8 ++++++-
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/src/common/common.h b/src/common/common.h
index e7a8dee..5965444 100644
--- a/src/common/common.h
+++ b/src/common/common.h
@@ -196,5 +196,6 @@ int __snprintf(char **buf, const int bufLen, int *remainLen, const char *format,
char is_digit_str(const char *s);
int get_system_uuid(char *buffer, unsigned int size);
int copy_file(const char *dst_file, const char *src_file);
+int check_path_for_security(const char *path);
#endif
diff --git a/src/common/util.c b/src/common/util.c
index 98d5b12..9f7c861 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -22,6 +22,9 @@
#include <stdarg.h>
#include "common.h"
+const char* command_injection_characters[] = {"|", ";", "&", "$", ">", "<", "(", ")", "./", "/.", "?", "*",
+ "\'", "`", "[", "]", "\\", "!", "\n"};
+
char *get_cur_date(void)
{
/* return date str, ex: 2021/05/17 */
@@ -240,5 +243,26 @@ int copy_file(const char *dst_file, const char *src_file) {
free(buffer);
fclose(fp1);
fclose(fp2);
+ return 0;
+}
+
+/*
+ * Check the path to avoid command injection
+ * @path: path executed as command
+ */
+int check_path_for_security(const char *path)
+{
+ if (path == NULL || strlen(path) == 0) {
+ return 0;
+ }
+
+ int command_injection_characters_len = sizeof(command_injection_characters) / sizeof(command_injection_characters[0]);
+
+ for (int i = 0; i < command_injection_characters_len; ++i) {
+ if (strstr(path, command_injection_characters[i])) {
+ return 1;
+ }
+ }
+
return 0;
}
\ No newline at end of file
diff --git a/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c b/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c
index af7b1ea..dc809dd 100644
--- a/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c
+++ b/src/probes/extends/ebpf.probe/src/ioprobe/ioprobe.c
@@ -108,7 +108,7 @@ static char* __get_first_letter_pos(char *buf)
pos++;
p = buf + pos;
}
-
+
if (pos >= len) {
return NULL;
}
@@ -166,6 +166,12 @@ static int get_devt(char *dev_name, int *major, int *minor)
sys_file[0] = 0;
(void)snprintf(sys_file, PATH_LEN, "/sys/block/%s/dev", dev_name);
+
+ if (check_path_for_security(sys_file)) {
+ fprintf(stderr, "invalid dev name\n", dev_name);
+ return -1;
+ }
+
if (access(sys_file, 0)) {
sys_file[0] = 0;
(void)snprintf(sys_file, PATH_LEN, "/sys/block/*/%s/../dev", dev_name);
--
2.33.0

View File

@ -1,25 +0,0 @@
From c1787926da3435a53de49fc3ff70122f38509952 Mon Sep 17 00:00:00 2001
From: dowzyx <zhaoyuxing2@huawei.com>
Date: Fri, 28 Apr 2023 11:23:24 +0800
Subject: [PATCH] modify desc from chinese to english
---
.../extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java b/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
index d7f635d..e421983 100644
--- a/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
+++ b/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
@@ -72,7 +72,7 @@ public class JvmProbeAgent {
private static void infoCollector(RuntimeMXBean runtimeBean) {
String jvmName = runtimeBean.getVmName();
- String jvmVersion = runtimeBean.getVmVersion(); // 原始的为getSpecVersion();
+ String jvmVersion = runtimeBean.getVmVersion(); // or getSpecVersion();
String jvmVender = runtimeBean.getVmVendor();
writeMetricRecords(String.format("|jvm_info|%s|%s|%s|%s|%d|\n", pid, jvmName, jvmVender, jvmVersion, 1));
--
2.33.0

File diff suppressed because it is too large Load Diff

View File

@ -1,668 +0,0 @@
From f084483fae4e051b872a4bc812ffa3dc73039c76 Mon Sep 17 00:00:00 2001
From: wo_cow <niuqianqian@huawei.com>
Date: Fri, 31 Mar 2023 19:07:09 +0800
Subject: [PATCH 29/30] stackprobe: fix inaccurate call stack count. add
sample_perioud param
---
.../src/stackprobe/conf/stackprobe.conf | 1 +
.../src/stackprobe/conf/stackprobe_conf.h | 3 +
.../src/stackprobe/conf/stackprobe_config.c | 11 ++
.../ebpf.probe/src/stackprobe/flame_graph.c | 77 +-------
.../ebpf.probe/src/stackprobe/flame_graph.h | 5 +-
.../ebpf.probe/src/stackprobe/java_support.c | 2 +-
.../src/stackprobe/jvmti/jvm_agent.c | 2 +-
.../extends/ebpf.probe/src/stackprobe/stack.h | 3 +-
.../src/stackprobe/stack_bpf/stackprobe_bpf.h | 4 +-
.../ebpf.probe/src/stackprobe/stackprobe.c | 177 +++++++++++++-----
.../ebpf.probe/src/stackprobe/stackprobe.h | 2 +
.../extends/ebpf.probe/src/stackprobe/svg.h | 9 +
.../ebpf.probe/src/stackprobe/symbol.c | 1 -
13 files changed, 175 insertions(+), 122 deletions(-)
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe.conf b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe.conf
index 0b3d0ac..4d50eb2 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe.conf
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe.conf
@@ -2,6 +2,7 @@ general =
{
whitelist_enable = false;
period = 180; # unit is second
+ sample_period = 10; # unit is ms
log_dir = "/var/log/gala-gopher/stacktrace/logs";
svg_dir = "/var/log/gala-gopher/stacktrace";
flame_dir = "/var/log/gala-gopher/flamegraph";
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_conf.h b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_conf.h
index d872b4d..a1b9913 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_conf.h
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_conf.h
@@ -23,6 +23,8 @@
#define PROC_MAX_RANGE 64
#define PERIOD_MAX 600
#define PERIOD_MIN 30
+#define SAMPLE_PERIOD_MAX 1000
+#define SAMPLE_PERIOD_MIN 10
typedef enum {
SWITCH_ON = 0,
@@ -31,6 +33,7 @@ typedef enum {
typedef struct {
int period;
+ int samplePeriod;
char logDir[PATH_LEN];
char svgDir[PATH_LEN];
char flameDir[PATH_LEN];
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c
index 282cbbd..ed6ae19 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/conf/stackprobe_config.c
@@ -184,6 +184,17 @@ static int configLoadGeneral(void *config, config_setting_t *settings)
}
generalConfig->period = intVal;
+ ret = config_setting_lookup_int(settings, "sample_period", &intVal);
+ if (ret == 0) {
+ ERROR("[STACKPROBE]: load config for general sample_period failed.\n");
+ return -1;
+ }
+ if (intVal < SAMPLE_PERIOD_MIN || intVal > SAMPLE_PERIOD_MAX) {
+ ERROR("[STACKPROBE]: Please check config for general sample_period, val shold inside 10~1000.\n");
+ return -1;
+ }
+ generalConfig->samplePeriod = intVal;
+
ret = config_setting_lookup_string(settings, "log_dir", &strVal);
if (ret == 0) {
ERROR("[STACKPROBE]: load config for general log_dir failed.\n");
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c b/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c
index fd03699..cb70ec0 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c
@@ -25,7 +25,6 @@
#include <sys/wait.h>
#include <sys/types.h>
#include <fcntl.h>
-#include <curl/curl.h>
#ifdef BPF_PROG_KERN
#undef BPF_PROG_KERN
@@ -38,16 +37,7 @@
#include "bpf.h"
#include "flame_graph.h"
-#define POST_MAX_STEP_SIZE 1048576 // 1M
-static int g_post_max = POST_MAX_STEP_SIZE;
-
-struct post_info_s {
- int post_flag;
- int remain_size;
- char *buf_start;
- char *buf;
- CURL *curl;
-};
+extern int g_post_max;
struct MemoryStruct {
char *memory;
@@ -108,13 +98,6 @@ static FILE *__open_flame_graph_fp(struct stack_svg_mng_s *svg_mng)
return sfg->fp;
}
-static FILE *__get_flame_graph_fp(struct stack_svg_mng_s *svg_mng)
-{
- struct stack_flamegraph_s *sfg;
-
- sfg = &(svg_mng->flame_graph);
- return sfg->fp;
-}
static void __mkdir_flame_graph_path(struct stack_svg_mng_s *svg_mng)
{
@@ -192,51 +175,7 @@ static void __reopen_flame_graph_file(struct stack_svg_mng_s *svg_mng)
__set_flame_graph_flags(svg_mng, FLAME_GRAPH_NEW);
}
-#define HISTO_TMP_LEN (2 * STACK_SYMBS_LEN)
-static char __histo_tmp_str[HISTO_TMP_LEN];
-
-static int __do_wr_stack_histo(struct stack_svg_mng_s *svg_mng,
- struct stack_trace_histo_s *stack_trace_histo, int first, struct post_info_s *post_info)
-{
- FILE *fp = __get_flame_graph_fp(svg_mng);
- if (!fp) {
- ERROR("[FLAMEGRAPH]: Invalid fp.\n");
- return -1;
- }
- __histo_tmp_str[0] = 0;
-
- if (first) {
- (void)snprintf(__histo_tmp_str, HISTO_TMP_LEN, "%s %llu",
- stack_trace_histo->stack_symbs_str, stack_trace_histo->count);
- } else {
- (void)snprintf(__histo_tmp_str, HISTO_TMP_LEN, "\n%s %llu",
- stack_trace_histo->stack_symbs_str, stack_trace_histo->count);
- }
-
- if (post_info->post_flag) {
- int written = post_info->buf - post_info->buf_start;
- int ret = __snprintf(&post_info->buf, post_info->remain_size, &post_info->remain_size, "%s", __histo_tmp_str);
- if (ret < 0) {
- int new_post_max = g_post_max + POST_MAX_STEP_SIZE;
- char *temp = (char *)realloc(post_info->buf_start, new_post_max);
- if(temp == NULL) {
- ERROR("[FLAMEGRAPH]: Not enough post memory (realloc failed), current capacity is %d.\n",
- g_post_max);
- } else {
- post_info->buf_start = temp;
- post_info->buf = post_info->buf_start + written;
- post_info->remain_size += POST_MAX_STEP_SIZE;
- g_post_max = new_post_max;
- INFO("[FLAMEGRAPH]: post memory realloc to %d\n", g_post_max);
- (void)__snprintf(&post_info->buf, post_info->remain_size, &post_info->remain_size, "%s", __histo_tmp_str);
- }
- }
- }
-
- (void)fputs(__histo_tmp_str, fp);
- return 0;
-}
static size_t __write_memory_cb(void *contents, size_t size, size_t nmemb, void *userp)
{
@@ -362,8 +301,7 @@ static void __init_curl_handle(struct post_server_s *post_server, struct post_in
}
}
-static void __do_wr_flamegraph(struct stack_svg_mng_s *svg_mng, struct stack_trace_histo_s *head,
- struct post_server_s *post_server, int en_type)
+static void __do_wr_flamegraph(struct stack_svg_mng_s *svg_mng, struct post_server_s *post_server, int en_type)
{
int first_flag = 0;
struct post_info_s post_info = {.remain_size = g_post_max, .post_flag = 0};
@@ -374,11 +312,8 @@ static void __do_wr_flamegraph(struct stack_svg_mng_s *svg_mng, struct stack_tra
__init_curl_handle(post_server, &post_info);
- struct stack_trace_histo_s *item, *tmp;
- H_ITER(head, item, tmp) {
- (void)__do_wr_stack_histo(svg_mng, item, first_flag, &post_info);
- first_flag = 0;
- }
+ iter_histo_tbl(svg_mng, en_type, &first_flag, &post_info);
+
if (post_info.post_flag) {
__curl_post(post_server, &post_info, en_type);
}
@@ -389,10 +324,10 @@ static void __do_wr_flamegraph(struct stack_svg_mng_s *svg_mng, struct stack_tra
#endif
-void wr_flamegraph(struct stack_svg_mng_s *svg_mng, struct stack_trace_histo_s *head, int en_type,
+void wr_flamegraph(struct stack_svg_mng_s *svg_mng, int en_type,
struct post_server_s *post_server)
{
- __do_wr_flamegraph(svg_mng, head, post_server, en_type);
+ __do_wr_flamegraph(svg_mng, post_server, en_type);
if (is_svg_tmout(svg_mng)) {
(void)create_svg_file(svg_mng,
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.h b/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.h
index ea29107..d596328 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.h
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.h
@@ -20,8 +20,9 @@
#include "svg.h"
#include "stackprobe.h"
-void wr_flamegraph(struct stack_svg_mng_s *svg_mng, struct stack_trace_histo_s *head, int en_type,
- struct post_server_s *post_server);
+int do_wr_stack_histo(struct stack_svg_mng_s *svg_mng,
+ struct stack_trace_histo_s *stack_trace_histo, int first, struct post_info_s *post_info);
+void wr_flamegraph(struct stack_svg_mng_s *svg_mng, int en_type, struct post_server_s *post_server);
int set_flame_graph_path(struct stack_svg_mng_s *svg_mng, const char* path, const char *flame_name);
int set_post_server(struct post_server_s *post_server, const char *pyroscopeServer);
void clean_post_server();
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c b/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c
index 48b4386..e7088fb 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/java_support.c
@@ -63,7 +63,7 @@ static struct jvm_agent_hash_t *jvm_agent_head = NULL;
#define FIND_JAVA_PROC_COMM "ps -e -o pid,comm | grep java | awk '{print $1}'"
#define PROC_COMM "/usr/bin/cat /proc/%u/comm 2> /dev/null"
#define ATTACH_BIN_PATH "/opt/gala-gopher/extend_probes/jvm_attach"
-#define ATTACH_CMD "%s %u %u load %s true %s" // jvm_attach <pid> <nspid> load /tmp/jvm_agent.so true /tmp/java-symbolization-123
+#define ATTACH_CMD "%s %u %u load %s true %s" // jvm_attach <pid> <nspid> load /tmp/jvm_agent.so true /tmp/java-sym-123
#define HOST_SO_DIR "/opt/gala-gopher/extend_probes"
#define AGENT_SO_FILE "jvm_agent.so"
#define HOST_JAVA_SYM_PATH "/proc/%u/root/tmp/java-sym-%u/%s" // /proc/<pid>/root/tmp/java-sym-<pid>/java-symbols.bin
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/jvmti/jvm_agent.c b/src/probes/extends/ebpf.probe/src/stackprobe/jvmti/jvm_agent.c
index 21b1780..f8450ac 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/jvmti/jvm_agent.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/jvmti/jvm_agent.c
@@ -103,7 +103,7 @@ void get_class_name_from_csig(char *dest, size_t dest_size, const char *sig) {
for(i = 0; i < (dest_size - 1) && src[i]; i++) {
char c = src[i];
if (c == '/') c = '.';
- if (c == ';') break;
+ if (c == ';' || c == '$') break;
dest[i] = c;
}
dest[i] = 0;
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stack.h b/src/probes/extends/ebpf.probe/src/stackprobe/stack.h
index 82fda3f..5b6f7e3 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stack.h
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stack.h
@@ -20,12 +20,11 @@
#include "common.h"
#define AGGRE_PERIOD (1 * 30 * 1000) // 30s
-#define SAMPLE_PERIOD (10) // 10ms
#define TMOUT_PERIOD (AGGRE_PERIOD / 1000) // Second as unit
#define PROC_CACHE_MAX_COUNT 100 // Cache 100 proc symbols
#define DIV_ROUND_UP(NUM, DEN) ((NUM + DEN - 1) / DEN)
-#define PERCPU_SAMPLE_COUNT (2 * DIV_ROUND_UP(AGGRE_PERIOD, SAMPLE_PERIOD))
+#define MAX_PERCPU_SAMPLE_COUNT (2 * DIV_ROUND_UP(AGGRE_PERIOD, 10)) // samplePeriod as 10ms
struct convert_data_t {
u32 whitelist_enable;
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/stackprobe_bpf.h b/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/stackprobe_bpf.h
index 5626bd5..1ab3b13 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/stackprobe_bpf.h
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stack_bpf/stackprobe_bpf.h
@@ -54,7 +54,7 @@ struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE);
__uint(key_size, sizeof(u32));
__uint(value_size, PERF_MAX_STACK_DEPTH * sizeof(u64));
- __uint(max_entries, PERCPU_SAMPLE_COUNT);
+ __uint(max_entries, MAX_PERCPU_SAMPLE_COUNT);
} stackmap_a SEC(".maps");
@@ -63,7 +63,7 @@ struct {
__uint(type, BPF_MAP_TYPE_STACK_TRACE);
__uint(key_size, sizeof(u32));
__uint(value_size, PERF_MAX_STACK_DEPTH * sizeof(u64));
- __uint(max_entries, PERCPU_SAMPLE_COUNT);
+ __uint(max_entries, MAX_PERCPU_SAMPLE_COUNT);
} stackmap_b SEC(".maps");
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
index eafe5ad..dcc26c7 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
@@ -64,6 +64,8 @@
#define IS_IEG_ADDR(addr) ((addr) != 0xcccccccccccccccc && (addr) != 0xffffffffffffffff)
#define MEMLEAK_SEC_NUM 4
+#define HISTO_TMP_LEN (2 * STACK_SYMBS_LEN)
+#define POST_MAX_STEP_SIZE 1048576 // 1M
#define BPF_GET_MAP_FD(obj, map_name) \
({ \
@@ -85,7 +87,7 @@
__ret; \
})
-typedef int (*AttachFunc)(struct svg_stack_trace_s *svg_st);
+typedef int (*AttachFunc)(struct svg_stack_trace_s *svg_st, StackprobeConfig *conf);
typedef int (*PerfProcessFunc)(void *ctx, int cpu, void *data, u32 size);
enum pid_state_t {
@@ -116,6 +118,9 @@ struct bpf_link_hash_t {
struct bpf_link_hash_value v; // value
};
+
+static char __histo_tmp_str[HISTO_TMP_LEN];
+int g_post_max = POST_MAX_STEP_SIZE;
static struct probe_params params = {.period = DEFAULT_PERIOD};
static volatile sig_atomic_t g_stop;
static struct stack_trace_s *g_st = NULL;
@@ -198,12 +203,10 @@ static void destroy_proc_cache_tbl(struct stack_trace_s *st)
return;
}
- struct proc_cache_s *proc_hash_tbl = st->proc_cache;
struct proc_cache_s *item, *tmp;
-
- H_ITER(proc_hash_tbl, item, tmp) {
+ H_ITER(st->proc_cache, item, tmp) {
__destroy_proc_cache(item);
- H_DEL(proc_hash_tbl, item);
+ H_DEL(st->proc_cache, item);
(void)free(item);
}
st->proc_cache = NULL;
@@ -322,7 +325,7 @@ static struct raw_stack_trace_s *create_raw_stack_trace(struct stack_trace_s *st
{
struct raw_stack_trace_s *raw_stack_trace;
- size_t stack_size = st->cpus_num * PERCPU_SAMPLE_COUNT;
+ size_t stack_size = st->cpus_num * MAX_PERCPU_SAMPLE_COUNT;
size_t mem_size = sizeof(struct raw_stack_trace_s);
mem_size += (stack_size * sizeof(struct raw_trace_s));
@@ -353,9 +356,19 @@ static int add_raw_stack_id(struct raw_stack_trace_s *raw_st, struct raw_trace_s
#endif
+#define STACK_LAYER_ELSE 0
+#define STACK_LAYER_1ST 1
+#define STACK_LAYER_2ND 2 // only for Java
+#define STACK_LAYER_3RD 3 // only for Java
+
+// For deep call stacks (especially prone to Java programs), it is easy to sample incomplete call stacks.
+// If the function name at the first layer of the call stack contains ".",
+// it means that this is must be an incomplete call stack.
+// We query whether the first two layers of this call stack are contained in other call stacks (eg. A),
+// and then count this call on the A call stack.
#if 1
static int __stack_addrsymbs2string(struct proc_symbs_s *proc_symbs, struct addr_symb_s *addr_symb,
- int first, char *p, int size)
+ int *layer, char *p, int size)
{
int ret;
char *symb;
@@ -366,21 +379,33 @@ static int __stack_addrsymbs2string(struct proc_symbs_s *proc_symbs, struct addr
char *cur_p = p;
int len = size;
-#if 1
- symb = addr_symb->sym ?: addr_symb->mod;
- if (first) {
- if (proc_symbs->pod[0] != 0) {
- ret = __snprintf(&cur_p, len, &len, "[Pod]%s; ", proc_symbs->pod);
- }
- if (proc_symbs->container_name[0] != 0) {
- ret = __snprintf(&cur_p, len, &len, "[Con]%s; ", proc_symbs->container_name);
+ if (addr_symb->sym == NULL) {
+ return 0;
+ }
+ symb = addr_symb->sym;
+
+ if (*layer == STACK_LAYER_1ST) {
+ if (strstr(symb, ".") != NULL) {
+ ret = __snprintf(&cur_p, len, &len, "; %s", symb);
+ *layer = STACK_LAYER_2ND;
+ } else {
+ if (proc_symbs->pod[0] != 0) {
+ ret = __snprintf(&cur_p, len, &len, "[Pod]%s; ", proc_symbs->pod);
+ }
+ if (proc_symbs->container_name[0] != 0) {
+ ret = __snprintf(&cur_p, len, &len, "[Con]%s; ", proc_symbs->container_name);
+ }
+ ret = __snprintf(&cur_p, len, &len, "[%d]%s; %s", proc_symbs->proc_id, proc_symbs->comm, symb);
+ *layer = STACK_LAYER_ELSE;
}
- ret = __snprintf(&cur_p, len, &len, "[%d]%s; %s", proc_symbs->proc_id, proc_symbs->comm, symb);
+ } else if (*layer == STACK_LAYER_2ND) {
+ ret = __snprintf(&cur_p, len, &len, "; %s", symb);
+ *layer = STACK_LAYER_3RD;
} else {
ret = __snprintf(&cur_p, len, &len, "; %s", symb);
+ *layer = STACK_LAYER_ELSE;
}
-#endif
if (ret < 0) {
return -1;
}
@@ -391,7 +416,7 @@ static int __stack_symbs2string(struct stack_symbs_s *stack_symbs, struct proc_s
char symbos_str[], size_t size)
{
int len;
- int first_flag = 1;
+ int layer = STACK_LAYER_1ST;
int remain_len = size;
char *pos = symbos_str;
struct addr_symb_s *addr_symb;
@@ -399,28 +424,19 @@ static int __stack_symbs2string(struct stack_symbs_s *stack_symbs, struct proc_s
for (int i = 0; i < PERF_MAX_STACK_DEPTH; i++) {
addr_symb = &(stack_symbs->user_stack_symbs[i]);
if (addr_symb->orign_addr != 0) {
- len = __stack_addrsymbs2string(proc_symbs, addr_symb, first_flag, pos, remain_len);
- if (len < 0) {
+ len = __stack_addrsymbs2string(proc_symbs, addr_symb, &layer, pos, remain_len);
+ if (layer == STACK_LAYER_3RD) {
return -1;
}
- remain_len -= len;
- pos += len;
- first_flag = 0;
- }
- }
-
- for (int i = 0; i < PERF_MAX_STACK_DEPTH; i++) {
- addr_symb = &(stack_symbs->kern_stack_symbs[i]);
- if (addr_symb->orign_addr != 0) {
- len = __stack_addrsymbs2string(proc_symbs, addr_symb, first_flag, pos, remain_len);
if (len < 0) {
return -1;
}
remain_len -= len;
pos += len;
- first_flag = 0;
}
}
+
+ symbos_str[size - 1] = 0;
return 0;
}
@@ -428,7 +444,8 @@ static int add_stack_histo(struct stack_trace_s *st, struct stack_symbs_s *stack
struct proc_symbs_s *proc_symbs, enum stack_svg_type_e en_type, s64 count)
{
char str[STACK_SYMBS_LEN];
- struct stack_trace_histo_s *item = NULL, *new_item;
+ struct stack_trace_histo_s *item = NULL, *new_item = NULL;
+ struct stack_trace_histo_s *tmp;
str[0] = 0;
if (__stack_symbs2string(stack_symbs, proc_symbs, str, STACK_SYMBS_LEN)) {
@@ -448,6 +465,20 @@ static int add_stack_histo(struct stack_trace_s *st, struct stack_symbs_s *stack
return 0;
}
+ // Java incomplete call stack merge
+ if (str[0] == ';') {
+ char tmp_str[__FUNC_NAME_LEN] = {0};
+ (void)snprintf(tmp_str, __FUNC_NAME_LEN, "[%d]", proc_symbs->proc_id);
+ H_ITER(st->svg_stack_traces[en_type]->histo_tbl, item, tmp) {
+ if (strstr(item->stack_symbs_str, tmp_str) && strstr(item->stack_symbs_str, str)) {
+ st->stats.count[STACK_STATS_HISTO_FOLDED]++;
+ item->count = item->count + count;
+ return 0;
+ }
+ }
+ return -1;
+ }
+
H_FIND_S(st->svg_stack_traces[en_type]->histo_tbl, str, item);
if (item) {
st->stats.count[STACK_STATS_HISTO_FOLDED]++;
@@ -461,6 +492,7 @@ static int add_stack_histo(struct stack_trace_s *st, struct stack_symbs_s *stack
}
new_item->stack_symbs_str[0] = 0;
(void)strncpy(new_item->stack_symbs_str, str, STACK_SYMBS_LEN - 1);
+ new_item->stack_symbs_str[STACK_SYMBS_LEN - 1] = 0;
new_item->count = count < 0 ? 0 : count;
H_ADD_S(st->svg_stack_traces[en_type]->histo_tbl, stack_symbs_str, new_item);
@@ -473,11 +505,9 @@ static void clear_stack_histo(struct svg_stack_trace_s *svg_st)
return;
}
- struct stack_trace_histo_s *stack_trace_histo_tbl = svg_st->histo_tbl;
struct stack_trace_histo_s *item, *tmp;
-
- H_ITER(stack_trace_histo_tbl, item, tmp) {
- H_DEL(stack_trace_histo_tbl, item);
+ H_ITER(svg_st->histo_tbl, item, tmp) {
+ H_DEL(svg_st->histo_tbl, item);
(void)free(item);
}
svg_st->histo_tbl = NULL;
@@ -1035,12 +1065,13 @@ err:
return -1;
}
-static int attach_oncpu_bpf_prog(struct svg_stack_trace_s *svg_st)
+static int attach_oncpu_bpf_prog(struct svg_stack_trace_s *svg_st, StackprobeConfig *conf)
{
int ret;
+ int samplePeriod = conf->generalConfig->samplePeriod;
struct perf_event_attr attr_type_sw = {
- .sample_freq = SAMPLE_PERIOD,
+ .sample_freq = samplePeriod, // default 10ms
.freq = 1,
.type = PERF_TYPE_SOFTWARE,
.config = PERF_COUNT_SW_CPU_CLOCK,
@@ -1270,7 +1301,7 @@ static void *__uprobe_attach_check(void *arg)
}
-static int attach_memleak_bpf_prog(struct svg_stack_trace_s *svg_st)
+static int attach_memleak_bpf_prog(struct svg_stack_trace_s *svg_st, StackprobeConfig *conf)
{
int err;
#if 0
@@ -1393,6 +1424,66 @@ static void *__running(void *arg)
return NULL;
}
+static FILE *__get_flame_graph_fp(struct stack_svg_mng_s *svg_mng)
+{
+ struct stack_flamegraph_s *sfg;
+
+ sfg = &(svg_mng->flame_graph);
+ return sfg->fp;
+}
+
+int __do_wr_stack_histo(struct stack_svg_mng_s *svg_mng,
+ struct stack_trace_histo_s *stack_trace_histo, int first, struct post_info_s *post_info)
+{
+ FILE *fp = __get_flame_graph_fp(svg_mng);
+ if (!fp) {
+ ERROR("[STACKPROBE]: Invalid fp.\n");
+ return -1;
+ }
+
+ __histo_tmp_str[0] = 0;
+
+ if (first) {
+ (void)snprintf(__histo_tmp_str, HISTO_TMP_LEN, "%s %llu",
+ stack_trace_histo->stack_symbs_str, stack_trace_histo->count);
+ } else {
+ (void)snprintf(__histo_tmp_str, HISTO_TMP_LEN, "\n%s %llu",
+ stack_trace_histo->stack_symbs_str, stack_trace_histo->count);
+ }
+ if (post_info->post_flag) {
+ int written = post_info->buf - post_info->buf_start;
+ int ret = __snprintf(&post_info->buf, post_info->remain_size, &post_info->remain_size, "%s", __histo_tmp_str);
+ if (ret < 0) {
+ int new_post_max = g_post_max + POST_MAX_STEP_SIZE;
+ char *temp = (char *)realloc(post_info->buf_start, new_post_max);
+ if(temp == NULL) {
+ ERROR("[STACKPROBE]: Not enough post memory (realloc failed), current capacity is %d.\n",
+ g_post_max);
+ } else {
+ post_info->buf_start = temp;
+ post_info->buf = post_info->buf_start + written;
+ post_info->remain_size += POST_MAX_STEP_SIZE;
+ g_post_max = new_post_max;
+ INFO("[STACKPROBE]: post memory realloc to %d\n", g_post_max);
+ (void)__snprintf(&post_info->buf, post_info->remain_size, &post_info->remain_size, "%s", __histo_tmp_str);
+ }
+ }
+ }
+
+ (void)fputs(__histo_tmp_str, fp);
+ return 0;
+}
+
+void iter_histo_tbl(struct stack_svg_mng_s *svg_mng, int en_type, int *first_flag, struct post_info_s *post_info)
+{
+ struct stack_trace_histo_s *item, *tmp;
+ H_ITER(g_st->svg_stack_traces[en_type]->histo_tbl, item, tmp) {
+ (void)__do_wr_stack_histo(svg_mng, item, *first_flag, post_info);
+ *first_flag = 0;
+ }
+ return;
+}
+
static void switch_stackmap()
{
struct stack_trace_s *st = g_st;
@@ -1410,8 +1501,10 @@ static void switch_stackmap()
if (st->svg_stack_traces[i] == NULL) {
continue;
}
- (void)stack_id2histogram(st, i, st->is_stackmap_a);
- wr_flamegraph(st->svg_stack_traces[i]->svg_mng, st->svg_stack_traces[i]->histo_tbl, i, &st->post_server);
+ if (stack_id2histogram(st, i, st->is_stackmap_a) != 0) {
+ continue;
+ }
+ wr_flamegraph(st->svg_stack_traces[i]->svg_mng , i, &st->post_server);
clear_raw_stack_trace(st->svg_stack_traces[i], st->is_stackmap_a);
}
record_running_ctx(st);
@@ -1468,7 +1561,7 @@ static int init_enabled_svg_stack_traces(StackprobeConfig *conf)
}
if (flameProcs[i].func) {
- if (flameProcs[i].func(svg_st)) {
+ if (flameProcs[i].func(svg_st, conf)) {
goto err;
}
}
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h
index 2e3cfcc..b09cdba 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h
@@ -141,4 +141,6 @@ struct stack_trace_s {
int pmu_fd[]; // It must be put to the last.
};
+void iter_histo_tbl(struct stack_svg_mng_s *svg_mng, int en_type, int *first_flag, struct post_info_s *post_info);
+
#endif
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/svg.h b/src/probes/extends/ebpf.probe/src/stackprobe/svg.h
index d763e7b..a707342 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/svg.h
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/svg.h
@@ -19,6 +19,15 @@
#include <time.h>
#include "stack.h"
+#include <curl/curl.h>
+
+struct post_info_s {
+ int post_flag;
+ int remain_size;
+ char *buf_start;
+ char *buf;
+ CURL *curl;
+};
#define DAYS_TIME (24 * 60 *60) // 1 DAY
#define WEEKS_TIME (DAYS_TIME * 7) // 1 WEEK
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/symbol.c b/src/probes/extends/ebpf.probe/src/stackprobe/symbol.c
index 2f7e06b..0c4ffaf 100644
--- a/src/probes/extends/ebpf.probe/src/stackprobe/symbol.c
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/symbol.c
@@ -1049,7 +1049,6 @@ int proc_search_addr_symb(struct proc_symbs_s *proc_symbs,
}
continue;
}
-
// search debug symbs
ret = search_elf_symb(proc_symbs->mods[i]->debug_symbs,
addr, addr, comm, addr_symb);
--
2.33.0