diff --git a/agent/src/ebpf/kernel/perf_profiler.c b/agent/src/ebpf/kernel/perf_profiler.c index 09cb561abae..23b241e2c5f 100644 --- a/agent/src/ebpf/kernel/perf_profiler.c +++ b/agent/src/ebpf/kernel/perf_profiler.c @@ -114,10 +114,17 @@ int bpf_perf_event(struct bpf_perf_event_data *ctx) __u64 id = bpf_get_current_pid_tgid(); struct stack_trace_key_t key = { 0 }; - key.cpu = bpf_get_smp_processor_id(); - bpf_get_current_comm(&key.comm, sizeof(key.comm)); key.tgid = id >> 32; key.pid = (__u32)id; + + /* + * CPU idle stacks will not be collected. + */ + if (key.tgid == key.pid && key.pid == 0) + return 0; + + key.cpu = bpf_get_smp_processor_id(); + bpf_get_current_comm(&key.comm, sizeof(key.comm)); key.timestamp = bpf_ktime_get_ns(); /* @@ -151,6 +158,9 @@ int bpf_perf_event(struct bpf_perf_event_data *ctx) if (-EEXIST == key.userstack) __sync_fetch_and_add(drop_count_ptr, 1); + if (key.userstack < 0 && key.kernstack < 0) + return 0; + sample_count = *sample_count_a_ptr; __sync_fetch_and_add(sample_count_a_ptr, 1); @@ -173,6 +183,9 @@ int bpf_perf_event(struct bpf_perf_event_data *ctx) if (-EEXIST == key.userstack) __sync_fetch_and_add(drop_count_ptr, 1); + if (key.userstack < 0 && key.kernstack < 0) + return 0; + sample_count = *sample_count_b_ptr; __sync_fetch_and_add(sample_count_b_ptr, 1); diff --git a/agent/src/ebpf/user/config.h b/agent/src/ebpf/user/config.h index 3f165b59934..5d844f05aef 100644 --- a/agent/src/ebpf/user/config.h +++ b/agent/src/ebpf/user/config.h @@ -167,4 +167,6 @@ enum { */ #define JAVA_SYMS_TABLE_UPDATE_PERIOD 300 // 300 seconds +/* Profiler - maximum data push interval time (in nanosecond). */ +#define MAX_PUSH_MSG_TIME_INTERVAL 1000000000ULL /* 1 seconds */ #endif /* DF_EBPF_CONFIG_H */ diff --git a/agent/src/ebpf/user/profile/perf_profiler.c b/agent/src/ebpf/user/profile/perf_profiler.c index e97e5e62f50..6683561be81 100644 --- a/agent/src/ebpf/user/profile/perf_profiler.c +++ b/agent/src/ebpf/user/profile/perf_profiler.c @@ -83,10 +83,6 @@ static FILE *folded_file; static char *flame_graph_start_time; static char *flame_graph_end_time; -/* "Maximum data push interval time (in seconds). */ -#define MAX_PUSH_MSG_TIME_INTERVAL 10 -/* "Maximum data push messages count. */ -#define MAX_PUSH_MSG_COUNT 1000 /* profiler start time(monotonic seconds). */ static u64 start_time; /* Record the time of the last data push @@ -373,23 +369,19 @@ static void push_and_release_stack_trace_msg(stack_trace_msg_hash_t * h, ASSERT(profiler_tracer != NULL); u64 curr_time, elapsed; - curr_time = gettime(CLOCK_MONOTONIC, TIME_TYPE_SEC); + curr_time = gettime(CLOCK_MONOTONIC, TIME_TYPE_NAN); elapsed = curr_time - last_push_time; /* * If the aggregated stack trace data obtained by the profiler * satisfies one of the following conditions, it should be pushed * to the upper-level processing: * - * 1 If the aggregated count exceeds or equals the maximum push - * count (MAX_PUSH_MSG_COUNT). - * - * 2 If the time interval since the last push exceeds or equals + * If the time interval since the last push exceeds or equals * the maximum time interval (MAX_PUSH_MSG_TIME_INTERVAL). * * Otherwise, it should return directly. */ - if (!((h->hash_elems_count >= MAX_PUSH_MSG_COUNT) || - (elapsed >= MAX_PUSH_MSG_TIME_INTERVAL) || is_force)) + if (!((elapsed >= MAX_PUSH_MSG_TIME_INTERVAL) || is_force)) return; /* update last push time. */ diff --git a/server/controller/model/agent_group_config_example.yaml b/server/controller/model/agent_group_config_example.yaml index 30ebdd2cc11..3419653080e 100644 --- a/server/controller/model/agent_group_config_example.yaml +++ b/server/controller/model/agent_group_config_example.yaml @@ -1143,7 +1143,13 @@ vtap_group_id: g-xxxxxx ## Default: 99 #frequency: 99 - ## CPUID will not be included in the aggregation of stack trace data. + ## Whether to obtain the value of CPUID and decide whether to participate in aggregation. + ## Set to 1: + ## Obtain the value of CPUID and will be included in the aggregation of stack trace data. + ## Set to 0: + ## It will not be included in the aggregation. Any other value is considered invalid, + ## the CPU value for stack trace data reporting is a special value (CPU_INVALID:0xfff) + ## used to indicate that it is an invalid value. ## Default: 0 #cpu: 0