tools/accounting/getdelays.c
Source file repositories/reference/linux-study-clean/tools/accounting/getdelays.c
File Facts
- System
- Linux kernel
- Corpus path
tools/accounting/getdelays.c- Extension
.c- Size
- 20533 bytes
- Lines
- 767
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.herrno.hunistd.hpoll.hstring.hfcntl.hsys/types.hsys/stat.hsys/socket.hsys/wait.hsignal.htime.hlinux/genetlink.hlinux/taskstats.hlinux/cgroupstats.h
Detected Declarations
struct msgtemplatefunction usagefunction create_nl_socketfunction recv_taskstats_msgfunction send_cmdfunction get_family_idfunction stringfunction versionfunction print_delayacctfunction task_context_switch_countsfunction print_cgroupstatsfunction print_ioacctfunction main
Annotated Snippet
struct msgtemplate {
struct nlmsghdr n;
struct genlmsghdr g;
char buf[MAX_MSG_SIZE];
};
char cpumask[100+6*MAX_CPUS];
static void usage(void)
{
fprintf(stderr, "getdelays [-dilv] [-w logfile] [-r bufsize] "
"[-m cpumask] [-t tgid] [-p pid]\n");
fprintf(stderr, " -d: print delayacct stats\n");
fprintf(stderr, " -i: print IO accounting (works only with -p)\n");
fprintf(stderr, " -l: listen forever\n");
fprintf(stderr, " -v: debug on\n");
fprintf(stderr, " -C: container path\n");
}
/*
* Create a raw netlink socket and bind
*/
static int create_nl_socket(int protocol)
{
int fd;
struct sockaddr_nl local;
fd = socket(AF_NETLINK, SOCK_RAW, protocol);
if (fd < 0)
return -1;
if (rcvbufsz)
if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
&rcvbufsz, sizeof(rcvbufsz)) < 0) {
fprintf(stderr, "Unable to set socket rcv buf size to %d\n",
rcvbufsz);
goto error;
}
memset(&local, 0, sizeof(local));
local.nl_family = AF_NETLINK;
if (bind(fd, (struct sockaddr *) &local, sizeof(local)) < 0)
goto error;
return fd;
error:
close(fd);
return -1;
}
static int recv_taskstats_msg(int sd, struct msgtemplate *msg)
{
struct sockaddr_nl nladdr;
struct iovec iov = {
.iov_base = msg,
.iov_len = sizeof(*msg),
};
struct msghdr hdr = {
.msg_name = &nladdr,
.msg_namelen = sizeof(nladdr),
.msg_iov = &iov,
.msg_iovlen = 1,
};
int ret;
ret = recvmsg(sd, &hdr, 0);
if (ret < 0)
return -1;
if (hdr.msg_flags & MSG_TRUNC) {
errno = EMSGSIZE;
return -1;
}
return ret;
}
static int send_cmd(int sd, __u16 nlmsg_type, __u32 nlmsg_pid,
__u8 genl_cmd, __u16 nla_type,
void *nla_data, int nla_len)
{
struct nlattr *na;
struct sockaddr_nl nladdr;
int r, buflen;
char *buf;
struct msgtemplate msg;
msg.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `errno.h`, `unistd.h`, `poll.h`, `string.h`, `fcntl.h`, `sys/types.h`.
- Detected declarations: `struct msgtemplate`, `function usage`, `function create_nl_socket`, `function recv_taskstats_msg`, `function send_cmd`, `function get_family_id`, `function string`, `function version`, `function print_delayacct`, `function task_context_switch_counts`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.