Skip to content

Commit 431c1a1

Browse files
Rtoaxdkruces
authored andcommitted
tools/shmsnoop: Print shmctl command string
Print shmctl command: $ sudo ./shmsnoop.py PID COMM SYS RET ARGs 16413 writer SHMGET 31 key: 0xd2032983, size: 4194304, shmflg: 0x3a4 (IPC_CREAT|0644) 16413 writer SHMAT 7f7f572b8000 shmid: 0x31, shmaddr: 0x0, shmflg: 0x0 16413 writer SHMDT 0 shmaddr: 0x7f7f572b8000 16418 reader SHMGET 31 key: 0xd2032983, size: 4194304, shmflg: 0x1a4 (0644) 16418 reader SHMAT 7f28e81a4000 shmid: 0x31, shmaddr: 0x0, shmflg: 0x0 16418 reader SHMDT 0 shmaddr: 0x7f28e81a4000 16418 reader SHMCTL 0 shmid: 0x31, cmd: 0 (IPC_RMID), buf: 0x0 ^^^^^^^^^^ Signed-off-by: Rong Tao <[email protected]>
1 parent ecda15c commit 431c1a1

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

tools/shmsnoop.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,28 @@ def sys_name(sys):
238238
{ 'name' : 'SHM_EXEC', 'value' : 0o100000 },
239239
]
240240

241+
shmctl_cmds = [
242+
('IPC_RMID', 0),
243+
('IPC_SET', 1),
244+
('IPC_STAT', 2),
245+
('IPC_INFO', 3),
246+
('SHM_LOCK', 11),
247+
('SHM_UNLOCK', 12),
248+
('SHM_STAT', 13),
249+
('SHM_INFO', 14),
250+
('SHM_STAT_ANY', 15),
251+
]
252+
253+
def _decode_cmd(cmd, cmd_list):
254+
for str_cmd, cmd_val in cmd_list:
255+
if cmd == cmd_val:
256+
return str_cmd
257+
return '0x{:x}'.format(cmd)
258+
259+
def shmctl_cmd(cmd):
260+
return _decode_cmd(cmd, shmctl_cmds)
261+
262+
241263
def shmflg_str(val, flags):
242264
cur = filter(lambda x : x['value'] & val, flags)
243265
str = "0x%x" % val
@@ -293,7 +315,8 @@ def print_event(cpu, data, size):
293315
print("shmaddr: 0x%lx" % (event.shmaddr))
294316

295317
if event.sys == SYS_SHMCTL:
296-
print("shmid: 0x%lx, cmd: %lu, buf: 0x%x" % (event.shmid, event.cmd, event.buf))
318+
print("shmid: 0x%lx, cmd: %lu (%s), buf: 0x%x" % (event.shmid,
319+
event.cmd, shmctl_cmd(event.cmd), event.buf))
297320

298321
# loop with callback to print_event
299322
b["events"].open_perf_buffer(print_event, page_cnt=64)

tools/shmsnoop_example.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ PID COMM SYS RET ARGs
1010
19816 client SHMAT 7f4fd8ee7000 shmid: 0x10000, shmaddr: 0x0, shmflg: 0x0
1111
19816 client SHMDT 0 shmaddr: 0x7f4fd8ee7000
1212
19813 server SHMDT 0 shmaddr: 0x7f1cf8b1f000
13-
19813 server SHMCTL 0 shmid: 0x10000, cmd: 0, buf: 0x0
13+
19813 server SHMCTL 0 shmid: 0x10000, cmd: 0 (IPC_RMID), buf: 0x0
1414

1515

1616
Every call the shm* syscall (SHM column) is displayed
@@ -32,15 +32,15 @@ containing "server" with timestamps:
3232
# ./shmsnoop.py -T -n server
3333
TIME(s) PID COMM SYS RET ARGs
3434
0.563194000 19825 server SHMDT 0 shmaddr: 0x7f74362e4000
35-
0.563237000 19825 server SHMCTL 0 shmid: 0x18000, cmd: 0, buf: 0x0
35+
0.563237000 19825 server SHMCTL 0 shmid: 0x18000, cmd: 0 (IPC_RMID), buf: 0x0
3636

3737

3838
A -p option can be used to trace only selected process:
3939

4040
# ./shmsnoop.py -p 19855
4141
PID COMM SYS RET ARGs
4242
19855 server SHMDT 0 shmaddr: 0x7f4329ff8000
43-
19855 server SHMCTL 0 shmid: 0x20000, cmd: 0, buf: 0x0
43+
19855 server SHMCTL 0 shmid: 0x20000, cmd: 0 (IPC_RMID), buf: 0x0
4444

4545
USAGE message:
4646
# ./shmsnoop.py -h

0 commit comments

Comments
 (0)