Last active
August 29, 2015 14:10
-
-
Save bahamas10/98bd876ece6ad3abce81 to your computer and use it in GitHub Desktop.
pfiles in zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fcntl.h> | |
#include <stdio.h> | |
#define FILE_TO_OPEN "/etc/passwd" | |
#define TIMES 5000 | |
int main() { | |
int fd; | |
int i; | |
printf("pid: %d\n", getpid()); | |
for (i = 0; i < TIMES; i++) { | |
if (fd = open(FILE_TO_OPEN, O_RDONLY) == -1) { | |
perror("open"); | |
return 1; | |
} | |
} | |
sleep(300); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dave - sjc1-dave-01 sunos ~ $ ./open-5k & | |
[1] 32690 | |
pid: 32690 | |
dave - sjc1-dave-01 sunos ~ $ sudo dtrace -n 'syscall:::entry /pid == $target/ { @[probefunc]=count(); }' -c "sudo pfiles 32690" | |
dtrace: description 'syscall:::entry ' matched 233 probes | |
... | |
(pfiles output) | |
forksys 1 | |
getcwd 1 | |
pipe 1 | |
putmsg 1 | |
recv 1 | |
schedctl 1 | |
setrlimit 1 | |
sigpending 1 | |
so_socketpair 1 | |
sysi86 1 | |
waitsys 1 | |
write 1 | |
getrlimit 2 | |
gtime 2 | |
munmap 2 | |
privsys 2 | |
setpgrp 2 | |
systeminfo 2 | |
lwp_sigmask 3 | |
pollsys 3 | |
setcontext 3 | |
so_socket 3 | |
getgroups 4 | |
setgroups 4 | |
setuid 4 | |
sysconfig 4 | |
setregid 8 | |
setreuid 8 | |
getpid 9 | |
fcntl 10 | |
lseek 10 | |
priocntlsys 11 | |
ioctl 12 | |
brk 15 | |
doorfs 18 | |
getuid 20 | |
fstat 23 | |
sigaction 33 | |
memcntl 36 | |
mmapobj 39 | |
resolvepath 39 | |
lwp_cond_broadcast 40 | |
read 43 | |
mmap 51 | |
close 62 | |
open 65 | |
stat 87 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var net = require('net'); | |
for (var i = 0; i < 5000; i++) | |
net.connect(80, 'daveeddy.com'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dave - sjc1-dave-01 sunos ~ $ ./open-5k-sockets.js & | |
[1] 34728 | |
dave - sjc1-dave-01 sunos ~ $ sudo ptime pfiles 34728 | |
34728: node ./open-5k-sockets.js | |
real 1:28.918439782 | |
user 0.695646071 | |
sys 1:26.230105158 |
8 14722 readlink:entry
libc.so.1`__systemcall6+0x1e
libproc.so.1`load_fdinfo+0x17c
libproc.so.1`Pfdinfo_iter+0x32
pfiles`show_files+0x4b
pfiles`main+0x1b6
pfiles`_start+0x6c
Cut 1k open files down to 4 seconds by LD_PRELOADing a readlink
that does nothing
#include <stdlib.h>
#include <errno.h>
size_t readlink(const char *path, char *buf, size_t bufsize) {
errno = ENOSYS;
return -1;
}
$ cc -shared -fPIC -o readlink.so readlink.c
$ node open-1k-sockets.js &
[1] 88758
$ LD_PRELOAD=./readlink.so /usr/bin/amd64/ptime /usr/bin/amd64/pfiles 88758
... 1000 open sockets ...
real 4.061913621
user 0.354056032
sys 2.692370925
diff --git a/usr/src/lib/libproc/common/Pfdinfo.c b/usr/src/lib/libproc/common/Pfdinfo.c
index 1244397..b5e4d83 100644
--- a/usr/src/lib/libproc/common/Pfdinfo.c
+++ b/usr/src/lib/libproc/common/Pfdinfo.c
@@ -134,10 +134,17 @@ load_fdinfo(struct ps_prochandle *P)
info->pr_offset = pr_llseek(P, fd, 0, SEEK_CUR);
/* attempt to determine the path to it */
- (void) snprintf(path, sizeof (path),
- "%s/%d/path/%d", procfs_path, (int)P->pid, fd);
- len = readlink(path, info->pr_path,
- sizeof (info->pr_path) - 1);
+ switch (info->pr_mode & S_IFMT) {
+ case S_IFSOCK: case S_IFDOOR: /* not applicable */
+ len = -1;
+ break;
+ default:
+ (void) snprintf(path, sizeof (path),
+ "%s/%d/path/%d", procfs_path, (int)P->pid, fd);
+ len = readlink(path, info->pr_path,
+ sizeof (info->pr_path) - 1);
+ break;
+ }
if (len < 0) {
info->pr_path[0] = 0;
without LD_PRELOAD
dave - sjc1-dave-01 sunos ~/pfiles $ ./open-sockets.js &
[1] 75375
dave - sjc1-dave-01 sunos ~/pfiles $ opened 1000 sockets
ptime pfiles 75375 > /dev/null
real 45.522214487
user 0.334410765
sys 44.691393983
with LD_PRELOAD
dave - sjc1-dave-01 sunos ~/pfiles $ ./open-sockets.js &
[1] 75690
dave - sjc1-dave-01 sunos ~/pfiles $ opened 1000 sockets
LD_PRELOAD=./readlink.so /usr/bin/amd64/ptime /usr/bin/amd64/pfiles 75690 > /dev/null
real 3.887839734
user 0.328562456
sys 2.558752763
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dtracing open-5k-sockets
pfiles
(without-n
)