Pstack, Truss, Etc: by Riyaj Shamsudeen
Pstack, Truss, Etc: by Riyaj Shamsudeen
By
Riyaj Shamsudeen
Me
pstack
Truss
t1 t5 Database
engine
t2 t4 System
calls
t3 SAN
layer
Description:
The truss utility traces the system calls and the signal process receives.
Options:
truss [-fcaeildD] [ - [tTvx] [!] syscall ,...] [ - [sS] [!]
signal ,...] [ - [mM] [!] fault ,...] [ - [rw] [!] fd ,...] [ -
[uU] [!] lib ,... : [:] [!] func ,...] [-o outfile] com- mand |
-p pid...
Solaris truss
Hpux- tusc
Linux strace
AIX - truss
Truss - trace system calls and signals
truss p 28393
fstat(18, 0xFFBFA100) = 0
lseek(17, 0x0216B000, SEEK_SET) = 0x0216B000
write(17, "C8021686 )\0\0 )D0\0\0\0".., 4096) = 4096
lseek(17, 0x0219D000, SEEK_SET) = 0x0219D000
read(17, "\0\0\0\00101\001FF \0\0".., 4096) = 4096
Truss Few outputs
$ truss -d -E -p 1873
Base time stamp: 1310009834.7781 [ Wed Jul 6 22:37:14 CDT 2011 ]
0.0124 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.1128 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.1130 0.0000 mmap(0xFFFFFD7FFC1DE000, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE|
MAP_FIXED, 7, 0) = 0xFFFFFD7FFC1DE000
0.2132 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.3138 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.4142 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.5146 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.6150 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.7163 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
0.8181 0.0000 semtimedop(7, 0xFFFFFD7FFFDF9328, 1, 0xFFFFFD7FFFDF9340) Err#11 EAGAIN
13.2066 0.0001 pread(256, "06A2\0\098 AC001A9 . 5\0".., 8192, 0x14030000) = 8192
13.3202 0.0001 pread(261, "06A2\0\0C6 ?C001 P . 5\0".., 8192, 0x1418C000) = 8192
13.3215 0.0000 pread(262, "06A2\0\0 3 EC00101 . 5\0".., 8192, 0x14666000) = 8192
13.3250 0.0000 pread(257, "06A2\0\099 >C001C6 * 5\0".., 8192, 0x14532000) = 8192
13.3618 0.0001 pread(257, "06A2\0\0CE FC00101 . 5\0".., 8192, 0x1479C000) = 8192
13.4259 0.0001 pread(263, "06A2\0\0 B BC001CD . 5\0".., 8192, 0x16384000) = 8192
To trace a process, print timestamp offset from the start of TRUSS command
and print minimal information
truss d p <pid> Example: truss d p 23898
0.7998 0.0002 open("/proc/1456/psinfo", O_RDONLY) = 40
0.7998 0.0000 read(40, "\0\0\00201\0\0\0B005\0\0".., 416) = 416
0.7999 0.0001 close(40) = 0
20.8818 0.0000 open("/proc/2372/psinfo", O_RDONLY) Err#2 ENOENT
20.8826 0.0008 pollsys(0x0EA992B0, 3, 0xFFFFFD7FFFDFAFD0, 0x00000000) = 0
20.8828 0.0002 write(42, "04 Z\0\006\0\0\0\0\0\0\0".., 1114) = 1114
20.8838 0.0010 write(37, "04 Z\0\006\0\0\0\0\0\0\0".., 1114) = 1114
20.8843 0.0005 pollsys(0x0EA992B0, 3, 0xFFFFFD7FFFDFB0E0, 0x00000000) = 2
$ truss -d -D -p 1473 |more
Base time stamp: 1327357172.8340 [ Mon Jan 23 16:19:32 CST 2012 ]
ps ef|grep oracle
truss -d -E -f -o /tmp/dbstart.lst -p 2522
A sqlplus connection process was TRUSSed to get all system calls with f flag.
Demo: startup db
Shared memory segment
0xcc9fa834 = 3433015348
$ipcs ma
Shared Memory:
Shared memory segment was created with that shmget call, 59 shm id.
Demo: startup db
PMON startup
$strings /proc/2540/psinfo
Oracle
ora_pmon_solrac2
PMON attach
Pfiles:
pfiles can be used to associate this file ids with file names.
Pfiles lists the files currently opened by a process. In few
unix platform, this can be achieved by lsof command
also.
pfiles 28393
28393: ar60runb P_CONC_REQUEST_ID=2452107 STARTDATE='012006'
ENDDATE='122006'
Current rlimit: 4096 file descriptors
0: S_IFIFO mode:0000 dev:272,0 ino:7325504 uid:11175 gid:100 size:0
...
17: S_IFREG mode:0644 dev:233,63004 ino:895242 uid:11175 gid:100 size:
102522880
O_RDWR|O_CREAT|O_TRUNC
18: S_IFREG mode:0644 dev:233,63004 ino:895305 uid:11175 gid:100 size:
25491841
O_RDWR|O_CREAT|O_TRUNC
WARNINGS
The following proc tools stop their target processes while inspecting them
and reporting the results: pfiles, pldd, pmap, and pstack.
#! /bin/ksh
pid=$1
(( cnt=1000 ))
while [[ $cnt -gt 0 ]];
do
date
pmap -x $pid
pstack $pid
echo $cnt
(( cnt=cnt-1 ))
sleep 10
done
pmap
Address Kbytes RSS Anon Locked Mode Mapped File
00010000 72 72 - - r-x-- java
00030000 16 16 16 - rwx-- java
00034000 8744 8680 8680 - rwx-- [ heap ]
77980000 1224 1048 - - r--s- dev:273,2000 ino:104403
77CFA000 24 24 24 - rw--R [ anon ]
...
FF39A000 8 8 8 - rwx-- libthread.so.1
FF3A0000 8 8 - - r-x-- libc_psr.so.1
FF3B0000 184 184 - - r-x-- ld.so.1
FF3EE000 8 8 8 - rwx-- ld.so.1
FF3F0000 8 8 8 - rwx-- ld.so.1
FF3FA000 8 8 8 - rwx-- libdl.so.1
FFB80000 24 - - - ----- [ anon ]
FFBF0000 64 64 64 - rw--- [ stack ]
-------- ------- ------- ------- -------
total Kb 182352 65568 26360 -
Process initially started with
a memory usage of 182MB
pmap
Address Kbytes RSS Anon Locked Mode Mapped File
00010000 72 72 - - r-x-- java
00030000 16 16 16 - rwx-- java
00034000 8808 8720 8720 - rwx-- [ heap ]
77980000 1224 1048 - - r--s- dev:273,2000 ino:104403
77CFA000 24 24 24 - rw--R [ anon ]
77F7A000 24 24 24 - rw--R [ anon ]
78000000 72 72 72 - rwx-- [ anon ]
78012000 64 64 64 - rwx-- [ anon ]
7814C000 144 144 144 - rwx-- [ anon ]
78170000 8 8 8 - rwx-- [ anon ]
78172000 8 8 8 - rwx-- [ anon ]
78174000 8 8 8 - rwx-- [ anon ]
78176000 104 104 104 - rwx-- [ anon ]
..
FF3F0000 8 8 8 - rwx-- ld.so.1
FF3FA000 8 8 8 - rwx-- libdl.so.1
FFB80000 24 - - - ----- [ anon ]
FFBF0000 64 64 64 - rw--- [ stack ]
-------- ------- ------- ------- -------
total Kb 281040 210736 171528 -
YATC (Yet Another Test Case)
Example: