ss: show socket memory stats for unix sockets if requested

The output format is the same as for tcp sockets but only the following
fields are currently non-zero: sk_rcvbuf, sk_wmem_alloc and sk_sndbuf.

Cc: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
This commit is contained in:
Hannes Frederic Sowa 2013-02-22 15:28:18 +00:00 committed by Stephen Hemminger
parent 5048f9a0c5
commit 51ff9f2453
1 changed files with 31 additions and 16 deletions

View File

@ -1327,6 +1327,29 @@ static char *sprint_bw(char *buf, double bw)
return buf; return buf;
} }
static void print_skmeminfo(struct rtattr *tb[], int attrtype)
{
const __u32 *skmeminfo;
if (!tb[attrtype])
return;
skmeminfo = RTA_DATA(tb[attrtype]);
printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u",
skmeminfo[SK_MEMINFO_RMEM_ALLOC],
skmeminfo[SK_MEMINFO_RCVBUF],
skmeminfo[SK_MEMINFO_WMEM_ALLOC],
skmeminfo[SK_MEMINFO_SNDBUF],
skmeminfo[SK_MEMINFO_FWD_ALLOC],
skmeminfo[SK_MEMINFO_WMEM_QUEUED],
skmeminfo[SK_MEMINFO_OPTMEM]);
if (RTA_PAYLOAD(tb[attrtype]) >=
(SK_MEMINFO_BACKLOG + 1) * sizeof(__u32))
printf(",bl%u", skmeminfo[SK_MEMINFO_BACKLOG]);
printf(")");
}
static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r) static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
{ {
struct rtattr * tb[INET_DIAG_MAX+1]; struct rtattr * tb[INET_DIAG_MAX+1];
@ -1337,22 +1360,7 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r)
nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)));
if (tb[INET_DIAG_SKMEMINFO]) { if (tb[INET_DIAG_SKMEMINFO]) {
const __u32 *skmeminfo = RTA_DATA(tb[INET_DIAG_SKMEMINFO]); print_skmeminfo(tb, INET_DIAG_SKMEMINFO);
printf(" skmem:(r%u,rb%u,t%u,tb%u,f%u,w%u,o%u",
skmeminfo[SK_MEMINFO_RMEM_ALLOC],
skmeminfo[SK_MEMINFO_RCVBUF],
skmeminfo[SK_MEMINFO_WMEM_ALLOC],
skmeminfo[SK_MEMINFO_SNDBUF],
skmeminfo[SK_MEMINFO_FWD_ALLOC],
skmeminfo[SK_MEMINFO_WMEM_QUEUED],
skmeminfo[SK_MEMINFO_OPTMEM]);
if (RTA_PAYLOAD(tb[INET_DIAG_SKMEMINFO]) >=
(SK_MEMINFO_BACKLOG + 1) * sizeof(__u32))
printf(",bl%u", skmeminfo[SK_MEMINFO_BACKLOG]);
printf(")");
} else if (tb[INET_DIAG_MEMINFO]) { } else if (tb[INET_DIAG_MEMINFO]) {
const struct inet_diag_meminfo *minfo const struct inet_diag_meminfo *minfo
= RTA_DATA(tb[INET_DIAG_MEMINFO]); = RTA_DATA(tb[INET_DIAG_MEMINFO]);
@ -2188,6 +2196,11 @@ static int unix_show_sock(struct nlmsghdr *nlh, struct filter *f)
printf(" users:(%s)", ubuf); printf(" users:(%s)", ubuf);
} }
if (show_mem) {
printf("\n\t");
print_skmeminfo(tb, UNIX_DIAG_MEMINFO);
}
printf("\n"); printf("\n");
return 0; return 0;
@ -2214,6 +2227,8 @@ static int unix_show_netlink(struct filter *f, FILE *dump_fp)
req.r.sdiag_family = AF_UNIX; req.r.sdiag_family = AF_UNIX;
req.r.udiag_states = f->states; req.r.udiag_states = f->states;
req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER | UDIAG_SHOW_RQLEN; req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_PEER | UDIAG_SHOW_RQLEN;
if (show_mem)
req.r.udiag_show |= UDIAG_SHOW_MEMINFO;
if (send(fd, &req, sizeof(req), 0) < 0) { if (send(fd, &req, sizeof(req), 0) < 0) {
close(fd); close(fd);