Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions agent/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ pub struct EbpfYamlConfig {
pub io_event_collect_mode: usize,
#[serde(with = "humantime_serde")]
pub io_event_minimal_duration: Duration,
pub java_symbol_file_max_space_limit: u8,
#[serde(with = "humantime_serde")]
pub java_symbol_file_refresh_defer_interval: Duration,
pub on_cpu_profile: OnCpuProfile,
Expand Down Expand Up @@ -425,8 +424,7 @@ impl Default for EbpfYamlConfig {
go_tracing_timeout: 120,
io_event_collect_mode: 1,
io_event_minimal_duration: Duration::from_millis(1),
java_symbol_file_max_space_limit: 10,
java_symbol_file_refresh_defer_interval: Duration::from_secs(600),
java_symbol_file_refresh_defer_interval: Duration::from_secs(60),
on_cpu_profile: OnCpuProfile::default(),
off_cpu_profile: OffCpuProfile::default(),
memory_profile: MemoryProfile::default(),
Expand Down Expand Up @@ -810,23 +808,18 @@ impl YamlConfig {
c.ebpf.ring_size = 65536;
}
if c.ebpf.max_socket_entries < 100000 || c.ebpf.max_socket_entries > 2000000 {
c.ebpf.max_socket_entries = 524288;
c.ebpf.max_socket_entries = 131072;
}
if c.ebpf.socket_map_max_reclaim < 100000 || c.ebpf.socket_map_max_reclaim > 2000000 {
c.ebpf.socket_map_max_reclaim = 520000;
c.ebpf.socket_map_max_reclaim = 120000;
}
if c.ebpf.max_trace_entries < 100000 || c.ebpf.max_trace_entries > 2000000 {
c.ebpf.max_trace_entries = 524288;
}
if c.ebpf.java_symbol_file_max_space_limit < 2
|| c.ebpf.java_symbol_file_max_space_limit > 100
{
c.ebpf.java_symbol_file_max_space_limit = 10
c.ebpf.max_trace_entries = 131072;
}
if c.ebpf.java_symbol_file_refresh_defer_interval < Duration::from_secs(5)
|| c.ebpf.java_symbol_file_refresh_defer_interval > Duration::from_secs(3600)
{
c.ebpf.java_symbol_file_refresh_defer_interval = Duration::from_secs(600)
c.ebpf.java_symbol_file_refresh_defer_interval = Duration::from_secs(60)
}
c.ebpf.off_cpu_profile.min_block = c
.ebpf
Expand Down
15 changes: 7 additions & 8 deletions agent/src/ebpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ OBJS := user/elf.o \
$(patsubst %.c,%.o,$(wildcard user/extended/profile/*.c)) \
user/profile/perf_profiler.o \
user/profile/stringifier.o \
user/profile/java/df_jattach.o \
user/profile/java/gen_syms_file.o
user/profile/java/jvm_symbol_collect.o \
user/profile/java/collect_symbol_files.o

JAVA_TOOL := deepflow-jattach
JAVA_AGENT_VERSION := 1
JAVA_AGENT_VERSION := 2
JAVA_AGENT_GNU_SO := df_java_agent_v$(JAVA_AGENT_VERSION).so
JAVA_AGENT_MUSL_SO := df_java_agent_musl_v$(JAVA_AGENT_VERSION).so
JAVA_AGENT_SO := $(JAVA_AGENT_GNU_SO) $(JAVA_AGENT_MUSL_SO)
JAVA_AGENT_SRC := user/profile/java/agent.c
JAVA_AGENT_SRC := user/profile/java/symbol_collect_agent.c
JAVA_AGENT_MACROS := -DAGENT_LIB_NAME="\"$(JAVA_AGENT_GNU_SO)\"" -DAGENT_MUSL_LIB_NAME="\"$(JAVA_AGENT_MUSL_SO)\""

STATIC_OBJS := $(addprefix $(STATIC_OBJDIR)/,$(OBJS))
Expand Down Expand Up @@ -135,8 +135,7 @@ endif

all: build

SOCKET_TRACE_ELFS := \
user/socket_trace_bpf_common.c \
SOCKET_TRACE_ELFS := user/socket_trace_bpf_common.c \
user/socket_trace_bpf_3_10_0.c \
user/socket_trace_bpf_5_2_plus.c \
user/socket_trace_bpf_kylin.c
Expand Down Expand Up @@ -216,9 +215,9 @@ tools: $(LIBTRACE)
$(call msg,TOOLS,deepflow-ebpfctl)
$(Q)$(CC) $(CFLAGS) --static -g -O2 user/ctrl_tracer.c user/ctrl.c $(LIBTRACE) -o deepflow-ebpfctl -lelf -lz -lpthread

$(JAVA_TOOL): $(JAVA_AGENT_SO) user/profile/java/df_jattach.c user/log.c user/common.c libs/jattach/build/libjattach.a
$(JAVA_TOOL): $(JAVA_AGENT_SO) user/log.c user/common.c user/mem.c user/vec.c user/profile/java/jvm_symbol_collect.c libs/jattach/build/libjattach.a
$(call msg,TOOLS,$@)
@$(GNU_CC) $(CFLAGS) -DJAVA_AGENT_ATTACH_TOOL user/profile/java/df_jattach.c user/log.c user/common.c libs/jattach/build/libjattach.a -o $@ -ldl -lpthread
@$(GNU_CC) $(CFLAGS) -DJAVA_AGENT_ATTACH_TOOL user/log.c user/common.c user/mem.c user/vec.c user/profile/java/jvm_symbol_collect.c libs/jattach/build/libjattach.a -o $@ -ldl -lpthread
@rm -rf user/profile/deepflow_jattach_bin.c
@./tools/bintobuffer ./$@ user/profile/deepflow_jattach_bin.c deepflow_jattach_bin

Expand Down
7 changes: 1 addition & 6 deletions agent/src/ebpf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,6 @@ extern "C" {
/*
* start continuous profiler
* @freq sample frequency, Hertz. (e.g. 99 profile stack traces at 99 Hertz)
* @java_syms_space_limit The maximum space occupied by the Java symbol files
* in the '/' directory of the target POD container.The recommended range for
* values is [2, 100], which means it falls within the interval of 2Mi to 100Mi.
* If the configuration value is outside this range, the default value of
* 10(10Mi), will be used.
* @java_syms_update_delay To allow Java to run for an extended period and gather
* more symbol information, we delay symbol retrieval when encountering unknown
* symbols. The unit of measurement used is seconds.
Expand All @@ -587,7 +582,6 @@ extern "C" {
*/
pub fn start_continuous_profiler(
freq: c_int,
java_syms_space_limit: c_int,
java_syms_update_delay: c_int,
callback: extern "C" fn(_data: *mut stack_profile_data),
) -> c_int;
Expand Down Expand Up @@ -709,6 +703,7 @@ extern "C" {
pub fn enable_oncpu_profiler() -> c_int;

pub fn disable_oncpu_profiler() -> c_int;
pub fn show_collect_pool();

cfg_if::cfg_if! {
if #[cfg(feature = "extended_profile")] {
Expand Down
33 changes: 19 additions & 14 deletions agent/src/ebpf/samples/rust/profiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn cp_container_id_safe(cp: *mut stack_profile_data) -> String {
}
}

#[allow(dead_code)]
fn increment_counter(num: u32, counter_type: u32) {
if counter_type == 0 {
let mut counter = COUNTER.lock().unwrap();
Expand Down Expand Up @@ -121,7 +122,7 @@ extern "C" fn socket_trace_callback(_sd: *mut SK_BPF_DATA) {}

extern "C" fn continuous_profiler_callback(cp: *mut stack_profile_data) {
unsafe {
process_stack_trace_data_for_flame_graph(cp);
//process_stack_trace_data_for_flame_graph(cp);
increment_counter((*cp).count, 1);
increment_counter(1, 0);
//let data = sk_data_str_safe(cp);
Expand All @@ -143,6 +144,7 @@ extern "C" fn continuous_profiler_callback(cp: *mut stack_profile_data) {
}
}

#[allow(dead_code)]
fn get_counter(counter_type: u32) -> u32 {
if counter_type == 0 {
*COUNTER.lock().unwrap()
Expand Down Expand Up @@ -173,9 +175,9 @@ fn main() {
1, /* Number of worker threads, indicating how many user-space threads participate in data processing */
64, /* Number of page frames occupied by kernel-shared memory, must be a power of 2. Used for perf data transfer */
65536, /* Size of the circular buffer queue, must be a power of 2. e.g: 2, 4, 8, 16, 32, 64, 128 */
524288, /* Maximum number of hash table entries for socket tracing, depends on the actual number of concurrent requests in the scenario */
524288, /* Maximum number of hash table entries for thread/coroutine tracing sessions */
520000, /* Maximum threshold for cleaning socket map entries. If the current number of map entries exceeds this value, map cleaning operation is performed */
131072, /* Maximum number of hash table entries for socket tracing, depends on the actual number of concurrent requests in the scenario */
131072, /* Maximum number of hash table entries for thread/coroutine tracing sessions */
120000, /* Maximum threshold for cleaning socket map entries. If the current number of map entries exceeds this value, map cleaning operation is performed */
) != 0
{
println!("running_socket_tracer() error.");
Expand All @@ -184,7 +186,7 @@ fn main() {

// Used to test our DeepFlow products, written as 97 frequency, so that
// it will not affect the sampling test of deepflow agent (using 99Hz).
if start_continuous_profiler(97, 10, 300, continuous_profiler_callback) != 0 {
if start_continuous_profiler(97, 60, continuous_profiler_callback) != 0 {
println!("start_continuous_profiler() error.");
::std::process::exit(1);
}
Expand Down Expand Up @@ -215,17 +217,20 @@ fn main() {
std::thread::sleep(Duration::from_secs(1));
}

thread::sleep(Duration::from_secs(150));
stop_continuous_profiler();
print!(
"====== capture count {}, sum {}\n",
get_counter(0),
get_counter(1)
);
release_flame_graph_hash();
//thread::sleep(Duration::from_secs(150));
//stop_continuous_profiler();
//print!(
// "====== capture count {}, sum {}\n",
// get_counter(0),
// get_counter(1)
//);
//release_flame_graph_hash();
}

loop {
thread::sleep(Duration::from_secs(5));
thread::sleep(Duration::from_secs(15));
unsafe {
show_collect_pool();
}
}
}
2 changes: 1 addition & 1 deletion agent/src/ebpf/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ARCH ?= $(shell uname -m)
CC ?= gcc
CFLAGS ?= -std=gnu99 --static -g -O2 -ffunction-sections -fdata-sections -fPIC -fno-omit-frame-pointer -Wall -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers

EXECS := test_symbol test_offset test_insns_cnt test_bihash test_vec test_fetch_container_id test_parse_range test_set_ports_bitmap
EXECS := test_symbol test_offset test_insns_cnt test_bihash test_vec test_fetch_container_id test_parse_range test_set_ports_bitmap test_pid_check
ifeq ($(ARCH), x86_64)
#-lbcc -lstdc++
LDLIBS += ../libtrace.a -ljattach -lbcc_bpf -lGoReSym -lbddisasm -ldwarf -lelf -lz -lpthread -lbcc -lstdc++ -ldl
Expand Down
62 changes: 62 additions & 0 deletions agent/src/ebpf/test/test_pid_check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 Yunshan Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <sys/stat.h>
#include <math.h>
#include <bcc/perf_reader.h>
#include "../user/config.h"
#include "../user/utils.h"
#include "../user/common.h"
#include "../user/mem.h"
#include "../user/log.h"
#include "../user/types.h"
#include "../user/vec.h"
#include "../user/tracer.h"
#include "../user/socket.h"
#include "../user/profile/perf_profiler.h"
#include "../user/elf.h"
#include "../user/load.h"

#define TEST_NAME "test_pid_check"
static int check_test_running_pid(void)
{
int pid = find_pid_by_name(TEST_NAME, getpid());
if (pid > 0) {
ebpf_warning("The deepflow-agent with process ID %d is already "
"running. You can disable the continuous profiling "
"feature of the deepflow-agent to skip this check.\n",
pid);
return ETR_EXIST;
}

return ETR_NOTEXIST;
}

int main(void)
{
bpf_tracer_init(NULL, true);
if (check_test_running_pid() == ETR_EXIST)
return 0;

char buf[1024];
exec_command("./test_pid_check", "", buf, sizeof(buf));
ebpf_info("--- %s\n", buf);
if (strstr(buf, "is already running")) {
ebpf_info("TEST success.\n");
return 0;
}
return -1;
}
Loading