Commit Graph

13 Commits

Author SHA1 Message Date
Martin Liska
983ec87a77 contrib: add vmmap.py script
Mimics `cat /proc/$pid/maps` and the script output is:

Start        End          Flgs   Offset Dev   Inode            File path
55dee5284000-55dee53f3000 r-xp 00000000 fd:02 10515            /usr/lib/systemd/systemd
55dee53f3000-55dee5441000 r--p 0016f000 fd:02 10515            /usr/lib/systemd/systemd
55dee5441000-55dee5442000 rw-p 001bd000 fd:02 10515            /usr/lib/systemd/systemd
55dee5f4c000-55dee615d000 rw-p 00000000 00:00 0
7f5fc801c000-7f5fc8024000 r-xp 00000000 fd:02 1181379          /usr/lib64/libffi.so.7.1.0
7f5fc8024000-7f5fc8224000 ---p 00008000 fd:02 1181379          /usr/lib64/libffi.so.7.1.0
7f5fc8224000-7f5fc8225000 r--p 00008000 fd:02 1181379          /usr/lib64/libffi.so.7.1.0
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-25 02:08:46 -08:00
Martin Liska
35f9de75b3 contrib: add memory statistics to ps.py
New output of the command is:

PID     PPID    CPU  ST    VMS     RSS  MEM%  COMM
1       0       0    S   10.4M    6.5M   0.4 init
2       0       0    S       0       0   0.0 [kthreadd]
...
263     1       4    S    2.4G  163.5M   9.5 python3
264     1       5    S    2.4G  163.5M   9.5 python3
265     1       6    S    2.4G  163.5M   9.5 python3
266     1       10   S    2.4G  163.5M   9.5 python3
267     1       12   S    2.4G  163.5M   9.5 python3
268     1       13   S    2.4G  163.5M   9.5 python3
269     1       14   S    2.4G  163.5M   9.5 python3
270     1       15   S    2.4G  163.5M   9.5 python3
271     1       16   S    2.4G  163.5M   9.5 python3
...

Supports also older kernel releases like 4.4.

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-25 02:07:57 -08:00
Martin Liska
e6228245a0 Fix TCP listing contrib script
Since Linux kernel commit 8dbd76e79a16 ("tcp/dccp: fix possible race
__inet_lookup_established()") (in v5.5), it's actually hlist_nulls_head
what is used for items of inet_hashinfo::listening_hash. This commit was
also backported to stable kernels, so with the change it works for all
releases starting with v4.9. The version 4.4 is not supported right now
(nulls head list is probably not known at the time).

Fixes: #268

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-24 13:15:00 -08:00
Martin Liska
adc8c430bb add kernel_sys.py to contrib
This script mimics crash>sys and provides the following output:

CPUS             16
DATE             Fri Jan 27 20:26:24 2023
UPTIME           1 day, 7:29:37
LOAD AVERAGE     0.00, 0.00, 0.00
TASKS            317
NODENAME         tw
RELEASE          6.1.7-1-default
VERSION          #1 SMP PREEMPT_DYNAMIC Wed Jan 18 11:12:34 UTC 2023 (872045c)
MACHINE          x86_64
MEMORY           12.67 GiB

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-02-24 12:22:00 -08:00
Omar Sandoval
5276af94fd contrib: add kcore_list.py
I used this to look at RAM regions on different architectures.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-21 14:26:54 -08:00
Omar Sandoval
cf3c4e736e contrib: vmstat.py: move implementation comment out of docstring
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:44:04 -08:00
Martin Liska
d5c3be72c3 add vmstat.py script to contrib
The script mimics what crash> kmem -V does, the script
reports the following:

Event                                           Count
VM_ZONE_STAT:
NR_FREE_PAGES                                  512147
NR_ZONE_LRU_BASE                               234271
NR_ZONE_INACTIVE_ANON                          234271
NR_ZONE_ACTIVE_ANON                               196
NR_ZONE_INACTIVE_FILE                           97200
NR_ZONE_ACTIVE_FILE                            110611
NR_ZONE_UNEVICTABLE                              1000
NR_ZONE_WRITE_PENDING                              84
NR_MLOCK                                            0
NR_BOUNCE                                           0
NR_ZSPAGES                                          0
NR_FREE_CMA_PAGES                                   0

VM_NODE_STAT:
NR_LRU_BASE                                    234322
NR_INACTIVE_ANON                               234322
NR_ACTIVE_ANON                                    196
NR_INACTIVE_FILE                                97200
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-02-03 11:37:19 -08:00
Martin Liska
7b0cdcf4a5 port contrib/tcp_sock.py to v5.19+
Since Linux kernel commit cae3873c5b3a ("net: inet: Retire port only
listening_hash") (in v5.19), listening_hash is removed and we need
to iterate lhash2 table.

The script reports now:
LISTEN                                           [::]:22                                         [::]:0      /system.slice/sshd.service
LISTEN                                        0.0.0.0:22                                      0.0.0.0:0      /system.slice/sshd.service
LISTEN                                          [::1]:631                                        [::]:0      /system.slice/cups.service
LISTEN                                      127.0.0.1:25                                      0.0.0.0:0      /system.slice/postfix.service
LISTEN                                          [::1]:25                                         [::]:0      /system.slice/postfix.service
LISTEN                                      127.0.0.1:631                                     0.0.0.0:0      /system.slice/cups.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:45906  /system.slice/sshd.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:48066  /system.slice/sshd.service
ESTABLISHED                            192.168.122.99:22                                192.168.122.1:41128  /system.slice/sshd.service

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 10:24:11 -08:00
Martin Liska
b86417c8a2 add mount.py contrib script
Provides crash-like output:

Mount            Type         Devname      Dirname
ffff8fed001d8500 rootfs       rootfs       /
ffff8fed06a197c0 proc         proc         /proc
ffff8fed06a192c0 sysfs        sysfs        /sys
ffff8fed06a18c80 devtmpfs     devtmpfs     /dev
ffff8fed06a18b40 securityfs   securityfs   /sys/kernel/security
ffff8fed06a19cc0 tmpfs        tmpfs        /dev/shm
ffff8fed06a18500 devpts       devpts       /dev/pts
ffff8fed06a18dc0 tmpfs        tmpfs        /run
...

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-27 09:56:57 -08:00
Martin Liska
724d15563d enhance ps
New output:

PID     PPID    CPU  ST COMM
1       0       4    S  systemd
2       0       13   S  [kthreadd]
3       2       0    I  [rcu_gp]
4       2       0    I  [rcu_par_gp]
5       2       0    I  [slub_flushwq]
6       2       0    I  [netns]
8       2       0    I  [kworker/0:0H]
10      2       0    I  [mm_percpu_wq]
11      2       0    I  [rcu_tasks_kthre]
...

Signed-off-by: Martin Liska <mliska@suse.cz>
Co-authored-by: Omar Sandoval <osandov@osandov.com>
2023-01-27 08:19:50 -08:00
Martin Liska
c710ea7713 fs_inodes: catch proper exception for None path
When inode_path returns None and it's passed to fsdecode,
I get TypeError exception:

```
  File "/usr/lib64/python3.10/os.py", line 823, in fsdecode
    filename = fspath(filename)  # Does type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not NoneType
```

Thus catch both exception types.

Signed-off-by: Martin Liska <mliska@suse.cz>
2023-01-26 08:43:16 -08:00
Omar Sandoval
cefe76bc3e contrib: make lsmod.py handle CONFIG_MODULE_UNLOAD=n
This is a nice example for Type.has_member().

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-22 10:25:13 -08:00
Omar Sandoval
a0a54edc1f Create contrib directory
It's come up several times that it'd be nice to have somewhere to dump
drgn scripts that people write while debugging without requiring them to
be cleaned up and scrutinized in code review. Serapheim Dimitropoulos
noted that several projects have a "contrib" directory for this purpose.
See [1]. Let's create one, document it, exclude it from pre-commit, and
move our (mostly unmaintained) examples there.

1: https://drewdevault.com/2020/06/06/Add-a-contrib-directory.html

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2022-11-16 13:17:50 -08:00