Skip to content

Commit

Permalink
mem_watcher:修改表头
Browse files Browse the repository at this point in the history
  • Loading branch information
syxl-time committed Jun 8, 2024
1 parent 1bc3ea6 commit 4b3bc3b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions eBPF_Supermarket/Memory_Subsystem/mem_watcher/mem_watcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,31 +587,32 @@ static int update_addr_times(struct memleak_bpf *skel) {
}

// 在打印时间时,先将时间调整为相对于程序启动的时间
static int print_time(struct memleak_bpf *skel) {
int print_time(struct memleak_bpf *skel) {
const size_t addr_times_key_size = bpf_map__key_size(skel->maps.addr_times);

printf("%-16s %9s\n", "AL_ADDR", "AL_Time");

// Iterate over the addr_times map to print address and time
for (__u64 prev_key = 0, curr_key = 0;; prev_key = curr_key) {
if (bpf_map__get_next_key(skel->maps.addr_times, &prev_key, &curr_key, addr_times_key_size)) {
if (errno == ENOENT) {
break; // no more keys, done!
}
perror("map get next key failed!");
return -errno;
}
for (__u64 prev_key = 0, curr_key = 0;; prev_key = curr_key) {
if (bpf_map__get_next_key(skel->maps.addr_times, &prev_key, &curr_key, addr_times_key_size)) {
if (errno == ENOENT) {
break; // no more keys, done!
}
perror("map get next key failed!");
return -errno;
}

// Read the timestamp for the current address
__u64 timestamp;
if (bpf_map__lookup_elem(skel->maps.addr_times, &curr_key, addr_times_key_size, &timestamp, sizeof(timestamp), 0) == 0) {
printf("Address: 0x%llx, Time: %llds\n", curr_key, timestamp);
}
else {
perror("map lookup failed!");
return -errno;
}
}
printf("------------------------------------------------------\n");
return 0;
// Read the timestamp for the current address
__u64 timestamp;
if (bpf_map__lookup_elem(skel->maps.addr_times, &curr_key, addr_times_key_size, &timestamp, sizeof(timestamp), 0) == 0) {
printf("0x%-16llx %llds\n", curr_key, timestamp); // 添加时间单位"s"
}
else {
perror("map lookup failed!");
return -errno;
}
}
return 0;
}

void disable_kernel_tracepoints(struct memleak_bpf *skel) {
Expand Down Expand Up @@ -907,6 +908,7 @@ static int process_memleak(struct memleak_bpf *skel_memleak, struct env env) {
for (;;) {
if (!env.kernel_trace)
if (env.print_time) {
system("clear");
update_addr_times(skel_memleak);
print_time(skel_memleak);
}
Expand Down

0 comments on commit 4b3bc3b

Please sign in to comment.