Slide 39
Slide 39 text
eBPF Code and YAML Example
- name: php_request_time_sec
help: PHP ELAPSED TIME SEC from startup to shutdown
bucket_type: exp2
bucket_min: 0
bucket_max: 27
bucket_multiplier: 0.000001 # microseconds to seconds
labels:
- name: request_uri
size: 256
decoders:
- name: string
- name: request_method
size: 8
decoders:
- name: string
- name: bucket
size: 8
decoders:
- name: uint
SEC("usdt//usr/lib/apache2/modules/libphp8.1.so:php:request__startup")
int BPF_USDT(request_startup, char *arg0, char *arg1, char *arg2)
{
u64 ts = bpf_ktime_get_ns();
u32 pid = bpf_get_current_pid_tgid();
struct php_req_key key;
key.pid = pid;
bpf_probe_read_user_str(&key.request_uri, sizeof(key.request_uri), arg1);
bpf_probe_read_user_str(&key.request_method, sizeof(key.request_method), arg2);
bpf_map_update_elem(&php_req, &pid, &ts, BPF_ANY);
return 0;
}
SEC("usdt//usr/lib/apache2/modules/libphp8.1.so:php:request__shutdown")
int BPF_USDT(request_shutdown, char *arg0, char *arg1, char *arg2)
{
u64 *tsp, delta_us, ts = bpf_ktime_get_ns();
u32 pid = bpf_get_current_pid_tgid();
struct php_req_hist_key_t hist_key = {};
bpf_probe_read_user_str(&hist_key.request_uri, sizeof(hist_key.request_uri), arg1);
bpf_probe_read_user_str(&hist_key.request_method, sizeof(hist_key.request_method), arg2);
tsp = bpf_map_lookup_elem(&php_req, &pid);
if (!tsp) {
return 0;
}
delta_us = (ts - *tsp) / 1000;
increment_exp2_histogram(&php_request_time_sec, hist_key, delta_us, MAX_SLOT_PHP_REQ);
return 0;
}