Commit Graph

13 Commits

Author SHA1 Message Date
Omar Sandoval
8b264f8823 Update copyright headers to Facebook and add missing headers
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.
2020-05-15 15:13:02 -07:00
Andrey Ignatov
618c7dcbc9 examples: Remove bpf.py
`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>
2020-03-07 11:36:11 -08:00
Andrey Ignatov
98d2aba95c examples/tcp_sock: Fix missed import
In the previous commit used import was removed by mistake. Restore them.

Fixes: 7dd1853 ("examples: Switch tcp_sock to cgroup helpers")
2020-01-29 01:05:37 -08:00
Andrey Ignatov
421bda23f9 examples: Print bpf programs and maps
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>
2020-01-24 10:53:47 -08:00
Andrey Ignatov
10fa4686c1 examples: Print attached cgroup-bpf programs
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>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
36cedcdc6f examples: Add example to traverse cgroup v2 hierarchy
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>
2020-01-14 16:03:20 -08:00
Andrey Ignatov
7dd18535e1 examples: Switch tcp_sock to cgroup helpers
Use cgroup helpers instead of working with socket cgroup manually.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
2020-01-14 16:03:20 -08:00
Omar Sandoval
7356816f61 helpers: get rid of get_tcp_states()
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.
2020-01-14 14:25:32 -08:00
Omar Sandoval
660276a0b8 Format Python code with Black
I'm not a fan of 100% of the Black coding style, but I've spent too much
time manually formatting Python code, so let's just pull the trigger.
2020-01-14 11:51:58 -08:00
Omar Sandoval
bb7a8eedcf helpers: add sk_tcpstate
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.
2020-01-02 19:43:57 -05:00
Andrey Ignatov
7a36136417 examples: Add tcp_sock.py
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>
2020-01-02 19:43:57 -05:00
Omar Sandoval
772254af3f examples: fix fs_inodes.py
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 *.
2019-04-11 15:11:36 -07:00
Omar Sandoval
661af811bd Rename kernel helpers to linux 2019-03-29 01:59:53 -07:00