Skip to content

Commit

Permalink
[eBPF] [CP] Sets push data in 1 second and does not collect idle data
Browse files Browse the repository at this point in the history
  • Loading branch information
yinjiping authored and sharang committed Sep 21, 2023
1 parent 7fa72b4 commit dd4d14c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
17 changes: 15 additions & 2 deletions agent/src/ebpf/kernel/perf_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/*
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions agent/src/ebpf/user/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
14 changes: 3 additions & 11 deletions agent/src/ebpf/user/profile/perf_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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. */
Expand Down
8 changes: 7 additions & 1 deletion server/controller/model/agent_group_config_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit dd4d14c

Please sign in to comment.