Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
修复参数读取异常问题,并内置线程黑名单
Browse files Browse the repository at this point in the history
  • Loading branch information
SeeFlowerX committed Dec 27, 2022
1 parent 03eb816 commit de06d68
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func (this *Module) Run() error {
if !found {
return errors.New("cannot find syscall_events map")
}
// rd, err := perf.NewReader(syscallEventsMap, os.Getpagesize()*128)
rd, err := perf.NewReader(syscallEventsMap, os.Getpagesize()*128, false, false)
// rd, err := perf.NewReader(syscallEventsMap, os.Getpagesize()*512)
rd, err := perf.NewReader(syscallEventsMap, os.Getpagesize()*512, false, false)
if err != nil {
errChan <- fmt.Errorf("creating %s reader: %s", syscallEventsMap.String(), err)
return nil
Expand Down
58 changes: 57 additions & 1 deletion src/raw_syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ static int inline send_data_arg_str(struct bpf_raw_tracepoint_args* ctx, struct
}
}
}
data->type = 2;
bpf_perf_event_output(ctx, &syscall_events, BPF_F_CURRENT_CPU, data, sizeof(struct syscall_data_t));
return 0;
}
Expand Down Expand Up @@ -202,6 +203,33 @@ int raw_syscalls_sys_enter(struct bpf_raw_tracepoint_args* ctx) {
bpf_get_current_comm(&data->comm, sizeof(data->comm));

// 线程名过滤?后面考虑有没有必要
// 渲染相关的线程 属实没必要 太多调用了
char thread_blacklist[9][15] = {
"RenderThread",
"RxCachedThreadS",
"mali-cmar-backe",
"mali-utility-wo",
"mali-mem-purge",
"mali-hist-dump",
"hwuiTask0",
"hwuiTask1",
"NDK MediaCodec_",
};
#pragma unroll
for (int i = 0; i < 9; i++) {
bool need_skip = true;
#pragma unroll
for (int j = 0; j < 15; j++) {
if (thread_blacklist[i][j] == 0) break;
if (data->comm[j] != thread_blacklist[i][j]) {
need_skip = false;
break;
}
}
if (need_skip) {
return 0;
}
}

// 基本信息
data->pid = pid;
Expand All @@ -222,7 +250,6 @@ int raw_syscalls_sys_enter(struct bpf_raw_tracepoint_args* ctx) {
bpf_perf_event_output(ctx, &syscall_events, BPF_F_CURRENT_CPU, data, sizeof(struct syscall_data_t));

// 获取参数
data->type = 2;
if ((filter->is_32bit && data->syscall_id == 11) || (!filter->is_32bit && data->syscall_id == 221)) {
// execve 3个参数
// const char *filename char *const argv[] char *const envp[]
Expand Down Expand Up @@ -294,6 +321,7 @@ int raw_syscalls_sys_enter(struct bpf_raw_tracepoint_args* ctx) {
if (data->args[j] != 0) {
__builtin_memset(&data->arg_str, 0, sizeof(data->arg_str));
bpf_probe_read_user(data->arg_str, sizeof(struct timespec), (void*)data->args[j]);
data->type = 2;
bpf_perf_event_output(ctx, &syscall_events, BPF_F_CURRENT_CPU, data, sizeof(struct syscall_data_t));
}
}
Expand Down Expand Up @@ -419,6 +447,34 @@ int raw_syscalls_sys_exit(struct bpf_raw_tracepoint_args* ctx) {
// 获取线程名
__builtin_memset(&data->comm, 0, sizeof(data->comm));
bpf_get_current_comm(&data->comm, sizeof(data->comm));

char thread_blacklist[9][15] = {
"RenderThread",
"RxCachedThreadS",
"mali-cmar-backe",
"mali-utility-wo",
"mali-mem-purge",
"mali-hist-dump",
"hwuiTask0",
"hwuiTask1",
"NDK MediaCodec_",
};
#pragma unroll
for (int i = 0; i < 9; i++) {
bool need_skip = true;
#pragma unroll
for (int j = 0; j < 15; j++) {
if (thread_blacklist[i][j] == 0) break;
if (data->comm[j] != thread_blacklist[i][j]) {
need_skip = false;
break;
}
}
if (need_skip) {
return 0;
}
}

// 基本信息
data->pid = pid;
data->tid = tid;
Expand Down

0 comments on commit de06d68

Please sign in to comment.