-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Eunseon Lee <[email protected]>
- Loading branch information
Showing
5 changed files
with
580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
/numamove | ||
/offcputime | ||
/opensnoop | ||
/profile | ||
/readahead | ||
/runqlat | ||
/runqlen | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ APPS = \ | |
numamove \ | ||
offcputime \ | ||
opensnoop \ | ||
profile \ | ||
readahead \ | ||
runqlat \ | ||
runqlen \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* Copyright (c) 2022 LG Electronics */ | ||
#include <vmlinux.h> | ||
#include <bpf/bpf_helpers.h> | ||
#include <bpf/bpf_core_read.h> | ||
#include <bpf/bpf_tracing.h> | ||
#include "profile.h" | ||
#include "maps.bpf.h" | ||
|
||
#define MAX_ENTRIES 10240 | ||
|
||
const volatile bool kernel_stacks_only = false; | ||
const volatile bool user_stacks_only = false; | ||
const volatile bool include_idle = false; | ||
const volatile pid_t targ_pid = -1; | ||
const volatile pid_t targ_tid = -1; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_STACK_TRACE); | ||
__type(key, u32); | ||
} stackmap SEC(".maps"); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_HASH); | ||
__type(key, struct key_t); | ||
__type(value, sizeof(u64)); | ||
__uint(max_entries, MAX_ENTRIES); | ||
} counts SEC(".maps"); | ||
|
||
SEC("perf_event") | ||
int do_perf_event(struct bpf_perf_event_data *ctx) { | ||
u64 id = bpf_get_current_pid_tgid(); | ||
u32 pid = id >> 32; | ||
u32 tid = id; | ||
u64 *valp; | ||
static const u64 zero; | ||
struct key_t key = {}; | ||
|
||
if (!include_idle && tid == 0) | ||
return 0; | ||
|
||
if (targ_pid != -1 && targ_pid != pid) | ||
return 0; | ||
if (targ_tid != -1 && targ_tid != tid) | ||
return 0; | ||
|
||
// create map key | ||
key.pid = pid; | ||
bpf_get_current_comm(&key.name, sizeof(key.name)); | ||
|
||
if (user_stacks_only) | ||
key.kern_stack_id = -1; | ||
else | ||
key.kern_stack_id = bpf_get_stackid(&ctx->regs, &stackmap, 0); | ||
|
||
if (kernel_stacks_only) | ||
key.user_stack_id = -1; | ||
else | ||
key.user_stack_id = bpf_get_stackid(&ctx->regs, &stackmap, BPF_F_USER_STACK); | ||
|
||
valp = bpf_map_lookup_or_try_init(&counts, &key, &zero); | ||
if (valp) | ||
__sync_fetch_and_add(valp, 1); | ||
|
||
return 0; | ||
} | ||
|
||
char LICENSE[] SEC("license") = "GPL"; |
Oops, something went wrong.