Mainly unused imports, unused variables, unnecessary f-strings, and
regex literals missing the r prefix. I'm not adding it to the CI linter
because it's too noisy, though.
Signed-off-by: Omar Sandoval <osandov@osandov.com>
drgn was originally my side project, but for awhile now it's also been
my work project. Update the copyright headers to reflect this, and add a
copyright header to various files that were missing it.
`examples/linux/bpf.py` was superseded by `tools/bpf_inspect.py` so no
reason to keep it around anymore. Remove it.
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Add example to print basic info about bpf programs and maps (id, type,
name).
Example output:
# python36 -m drgn examples/linux/bpf.py
Usage: examples/linux/bpf.py { prog | map }
# python36 -m drgn examples/linux/bpf.py p | head
9: BPF_PROG_TYPE_CGROUP_SKB name
10: BPF_PROG_TYPE_CGROUP_SKB name
23368: BPF_PROG_TYPE_CGROUP_SOCK_ADDR name tw_ipt_bind
23369: BPF_PROG_TYPE_CGROUP_SOCK_ADDR name tw_ipt_connect
23370: BPF_PROG_TYPE_SOCK_OPS name tw_ipt_listen
23371: BPF_PROG_TYPE_CGROUP_SOCK_ADDR name tw_ipt_sendmsg
59538: BPF_PROG_TYPE_CGROUP_SYSCTL name tw_sysctl
97104: BPF_PROG_TYPE_SCHED_CLS name fbflow_egress
97105: BPF_PROG_TYPE_SCHED_CLS name fbflow_ingress
97106: BPF_PROG_TYPE_KPROBE name fbflow_tcp_conn
# python36 -m drgn examples/linux/bpf.py m | head
8: BPF_MAP_TYPE_LPM_TRIE name
9: BPF_MAP_TYPE_LPM_TRIE name
12: BPF_MAP_TYPE_PERCPU_ARRAY name fbflow_pkt_info
16305: BPF_MAP_TYPE_ARRAY name tw_ipt_cfg
16306: BPF_MAP_TYPE_ARRAY name tw_tcp_ports_ma
16307: BPF_MAP_TYPE_LRU_HASH name tw_ipt_lo_sk
42606: BPF_MAP_TYPE_HASH name tw_sysctl_ro
55338: BPF_MAP_TYPE_HASH name hash_min
55341: BPF_MAP_TYPE_HASH name hash_8k_1
55342: BPF_MAP_TYPE_HASH name hash_8k_8
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Support additional argument `bpf` in `cgroup.py` that, if specified,
prints only cgroups with attached BPF programs in a way similar to
`bpftool cgroup tree`. W/o the `bpf` argument the tool works as before.
For example:
# python36 -m drgn examples/linux/cgroup.py /sys/fs/cgroup/workload.slice/ bpf
/workload.slice
98761 BPF_CGROUP_SOCK_OPS 2 ned_cgrp_dctcp
/workload.slice/workload-tw.slice/nc_0.58_dev082.prn2_598fe2e810bc4_2.task
93488 BPF_CGROUP_INET_INGRESS 0 tw_ingress
93487 BPF_CGROUP_INET_EGRESS 0 tw_egress
93482 BPF_CGROUP_SOCK_OPS 2 tw_ipt_listen
93480 BPF_CGROUP_INET6_BIND 0 tw_ipt_bind
93481 BPF_CGROUP_INET6_CONNECT 0 tw_ipt_connect
93483 BPF_CGROUP_UDP6_SENDMSG 0 tw_ipt_sendmsg
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Add simple example to traverse cgroup v2 hierarchy.
It can be run w/o arguments and in this case root cgroup will be used:
# python36 -m drgn examples/linux/cgroup.py | wc -l
1081
# python36 -m drgn examples/linux/cgroup.py | shuf -n 3
/system.slice/nfs-idmapd.service
/user.slice/user-0.slice/user@0.service/dev-hugepages.mount
/system.slice/crond.service
Or a path in cgroup v2 filesystem can be specified to limit the
traversal by this path:
# python36 -m drgn examples/linux/cgroup.py /sys/fs/cgroup/www.slice
/www.slice
/www.slice/hack.service
/www.slice/flow.service
Signed-off-by: Andrey Ignatov <rdna@fb.com>
After thinking about this some more, I decided that although it makes
sense for scripts to convert a type to an IntEnum class, I'd prefer that
the helpers take and return drgn Objects rather than these classes.
Although it doesn't correspond to a Linux kernel function, it is more
convenient than open-coding it everywhere, especially since the leading
__ causes Python to mangle the name if it's inside of a class.
Add example script that goes over all TCP sockets and for every socket
prints:
- TCP state;
- IP:port pair;
- cgroup v2 path.
The script shows basic operations with sockets including getting `struct
sock`, `struct inet_sock`, socket fields and cgroup v2 of socket.
It provides output similar to `ss -nt` or `ss -lnt`:
% sudo python36 -m drgn examples/linux/tcp_sock.py | shuf -n 5
TIME_WAIT [::1]:2560 [::1]:44041
ESTABLISHED [::1]:54178 [::1]:11101 system.slice/async-distillery-server.service
LISTEN [::]:3201 [::]:0 system.slice/fbflow.service
ESTABLISHED [2401:db00:21:718a:face:0:31:0]:2406 [2401:db00:12:a106:face:0:1e:0]:46306 system.slice/configerator_proxy2.service
LISTEN 0.0.0.0:11150 0.0.0.0:0 system.slice/system-mcrouter.slice/mcrouter@tao.service
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Commit 48c5f37d01 ("Make read_once() a method again, as
Object.read_()") mistakenly changed fs_inodes.py to a benchmark I was
running. Additionally, commit 393a1f3149 ("Document with Sphinx")
changed the for_each_mount() helper to only yield the struct mount *.