Lines Matching +full:c +full:- +full:version +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
2 /* getdelays.c
4 * Utility to get per-pid and per-tgid delay accounting statistics
7 * Copyright (C) Shailabh Nagar, IBM Corp. 2005
8 * Copyright (C) Balbir Singh, IBM Corp. 2006
9 * Copyright (c) Jay Lan, SGI. 2006
12 * gcc -I/usr/src/linux/include getdelays.c -o getdelays
38 #define GENLMSG_PAYLOAD(glh) (NLMSG_PAYLOAD(glh, 0) - GENL_HDRLEN)
40 #define NLA_PAYLOAD(len) (len - NLA_HDRLEN)
49 char name[100]; variable
76 fprintf(stderr, "getdelays [-dilv] [-w logfile] [-r bufsize] " in usage()
77 "[-m cpumask] [-t tgid] [-p pid]\n"); in usage()
78 fprintf(stderr, " -d: print delayacct stats\n"); in usage()
79 fprintf(stderr, " -i: print IO accounting (works only with -p)\n"); in usage()
80 fprintf(stderr, " -l: listen forever\n"); in usage()
81 fprintf(stderr, " -v: debug on\n"); in usage()
82 fprintf(stderr, " -C: container path\n"); in usage()
95 return -1; in create_nl_socket()
114 return -1; in create_nl_socket()
135 msg.g.version = 0x1; in send_cmd()
137 na->nla_type = nla_type; in send_cmd()
138 na->nla_len = nla_len + NLA_HDRLEN; in send_cmd()
140 msg.n.nlmsg_len += NLMSG_ALIGN(na->nla_len); in send_cmd()
150 buflen -= r; in send_cmd()
152 return -1; in send_cmd()
174 strcpy(name, TASKSTATS_GENL_NAME); in get_family_id()
176 CTRL_ATTR_FAMILY_NAME, (void *)name, in get_family_id()
187 na = (struct nlattr *) ((char *) na + NLA_ALIGN(na->nla_len)); in get_family_id()
188 if (na->nla_type == CTRL_ATTR_FAMILY_ID) { in get_family_id()
194 #define average_ms(t, c) (t / 1000000ULL / (c ? c : 1)) argument
198 * Version compatibility note:
199 * Field availability depends on taskstats version (t->version),
203 * Version feature mapping:
204 * version >= 11 - supports COMPACT statistics
205 * version >= 13 - supports WPCOPY statistics
206 * version >= 14 - supports IRQ statistics
207 * version >= 16 - supports *_max and *_min delay statistics
209 * Always verify version before accessing version-dependent fields
212 #define PRINT_CPU_DELAY(version, t) \ argument
214 if (version >= 16) { \
215 printf("%-10s%15s%15s%15s%15s%15s%15s%15s\n", \
219 (unsigned long long)(t)->cpu_count, \
220 (unsigned long long)(t)->cpu_run_real_total, \
221 (unsigned long long)(t)->cpu_run_virtual_total, \
222 (unsigned long long)(t)->cpu_delay_total, \
223 average_ms((double)(t)->cpu_delay_total, (t)->cpu_count), \
224 delay_ms((double)(t)->cpu_delay_max), \
225 delay_ms((double)(t)->cpu_delay_min)); \
227 printf("%-10s%15s%15s%15s%15s%15s\n", \
231 (unsigned long long)(t)->cpu_count, \
232 (unsigned long long)(t)->cpu_run_real_total, \
233 (unsigned long long)(t)->cpu_run_virtual_total, \
234 (unsigned long long)(t)->cpu_delay_total, \
235 average_ms((double)(t)->cpu_delay_total, (t)->cpu_count)); \
238 #define PRINT_FILED_DELAY(name, version, t, count, total, max, min) \ argument
240 if (version >= 16) { \
241 printf("%-10s%15s%15s%15s%15s%15s\n", \
242 name, "count", "delay total", "delay average", \
245 (unsigned long long)(t)->count, \
246 (unsigned long long)(t)->total, \
247 average_ms((double)(t)->total, (t)->count), \
248 delay_ms((double)(t)->max), \
249 delay_ms((double)(t)->min)); \
251 printf("%-10s%15s%15s%15s\n", \
252 name, "count", "delay total", "delay average"); \
254 (unsigned long long)(t)->count, \
255 (unsigned long long)(t)->total, \
256 average_ms((double)(t)->total, (t)->count)); \
264 PRINT_CPU_DELAY(t->version, t); in print_delayacct()
266 PRINT_FILED_DELAY("IO", t->version, t, in print_delayacct()
270 PRINT_FILED_DELAY("SWAP", t->version, t, in print_delayacct()
274 PRINT_FILED_DELAY("RECLAIM", t->version, t, in print_delayacct()
278 PRINT_FILED_DELAY("THRASHING", t->version, t, in print_delayacct()
282 if (t->version >= 11) { in print_delayacct()
283 PRINT_FILED_DELAY("COMPACT", t->version, t, in print_delayacct()
288 if (t->version >= 13) { in print_delayacct()
289 PRINT_FILED_DELAY("WPCOPY", t->version, t, in print_delayacct()
294 if (t->version >= 14) { in print_delayacct()
295 PRINT_FILED_DELAY("IRQ", t->version, t, in print_delayacct()
306 (unsigned long long)t->nvcsw, (unsigned long long)t->nivcsw); in task_context_switch_counts()
309 static void print_cgroupstats(struct cgroupstats *c) in print_cgroupstats() argument
312 "uninterruptible %llu\n", (unsigned long long)c->nr_sleeping, in print_cgroupstats()
313 (unsigned long long)c->nr_io_wait, in print_cgroupstats()
314 (unsigned long long)c->nr_running, in print_cgroupstats()
315 (unsigned long long)c->nr_stopped, in print_cgroupstats()
316 (unsigned long long)c->nr_uninterruptible); in print_cgroupstats()
323 t->ac_comm, in print_ioacct()
324 (unsigned long long)t->read_bytes, in print_ioacct()
325 (unsigned long long)t->write_bytes, in print_ioacct()
326 (unsigned long long)t->cancelled_write_bytes); in print_ioacct()
331 int c, rc, rep_len, aggr_len, len2; in main() local
337 int nl_sd = -1; in main()
356 c = getopt(argc, argv, "qdiw:r:m:t:p:vlC:c:"); in main()
357 if (c < 0) in main()
360 switch (c) { in main()
373 case 'C': in main()
390 cpumask[sizeof(cpumask) - 1] = '\0'; in main()
406 case 'c': in main()
409 if (sigemptyset(&sigset) == -1) in main()
420 if (execvp(argv[optind - 1], in main()
421 &argv[optind - 1]) < 0) in main()
422 exit(-1); in main()
438 exit(-1); in main()
445 if (fd == -1) { in main()
476 fprintf(stderr, "Select either -t or -C, not both\n"); in main()
530 err->error); in main()
543 len += NLA_ALIGN(na->nla_len); in main()
544 switch (na->nla_type) { in main()
548 aggr_len = NLA_PAYLOAD(na->nla_len); in main()
553 switch (na->nla_type) { in main()
572 if (write(fd, NLA_DATA(na), na->nla_len) < 0) { in main()
584 na->nla_type); in main()
587 len2 += NLA_ALIGN(na->nla_len); in main()
589 NLA_ALIGN(na->nla_len)); in main()
598 na->nla_type); in main()