aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/accounting/getdelays.c
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/accounting/getdelays.c')
-rw-r--r--Documentation/accounting/getdelays.c66
1 files changed, 47 insertions, 19 deletions
diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index b11792abd6b6..e9126e794ed7 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -7,6 +7,8 @@
7 * Copyright (C) Balbir Singh, IBM Corp. 2006 7 * Copyright (C) Balbir Singh, IBM Corp. 2006
8 * Copyright (c) Jay Lan, SGI. 2006 8 * Copyright (c) Jay Lan, SGI. 2006
9 * 9 *
10 * Compile with
11 * gcc -I/usr/src/linux/include getdelays.c -o getdelays
10 */ 12 */
11 13
12#include <stdio.h> 14#include <stdio.h>
@@ -35,13 +37,20 @@
35#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN)) 37#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
36#define NLA_PAYLOAD(len) (len - NLA_HDRLEN) 38#define NLA_PAYLOAD(len) (len - NLA_HDRLEN)
37 39
38#define err(code, fmt, arg...) do { printf(fmt, ##arg); exit(code); } while (0) 40#define err(code, fmt, arg...) \
39int done = 0; 41 do { \
40int rcvbufsz=0; 42 fprintf(stderr, fmt, ##arg); \
41 43 exit(code); \
42 char name[100]; 44 } while (0)
43int dbg=0, print_delays=0; 45
46int done;
47int rcvbufsz;
48char name[100];
49int dbg;
50int print_delays;
51int print_io_accounting;
44__u64 stime, utime; 52__u64 stime, utime;
53
45#define PRINTF(fmt, arg...) { \ 54#define PRINTF(fmt, arg...) { \
46 if (dbg) { \ 55 if (dbg) { \
47 printf(fmt, ##arg); \ 56 printf(fmt, ##arg); \
@@ -49,7 +58,7 @@ __u64 stime, utime;
49 } 58 }
50 59
51/* Maximum size of response requested or message sent */ 60/* Maximum size of response requested or message sent */
52#define MAX_MSG_SIZE 256 61#define MAX_MSG_SIZE 1024
53/* Maximum number of cpus expected to be specified in a cpumask */ 62/* Maximum number of cpus expected to be specified in a cpumask */
54#define MAX_CPUS 32 63#define MAX_CPUS 32
55/* Maximum length of pathname to log file */ 64/* Maximum length of pathname to log file */
@@ -78,8 +87,9 @@ static int create_nl_socket(int protocol)
78 if (rcvbufsz) 87 if (rcvbufsz)
79 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, 88 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
80 &rcvbufsz, sizeof(rcvbufsz)) < 0) { 89 &rcvbufsz, sizeof(rcvbufsz)) < 0) {
81 printf("Unable to set socket rcv buf size to %d\n", 90 fprintf(stderr, "Unable to set socket rcv buf size "
82 rcvbufsz); 91 "to %d\n",
92 rcvbufsz);
83 return -1; 93 return -1;
84 } 94 }
85 95
@@ -186,6 +196,15 @@ void print_delayacct(struct taskstats *t)
186 "count", "delay total", t->swapin_count, t->swapin_delay_total); 196 "count", "delay total", t->swapin_count, t->swapin_delay_total);
187} 197}
188 198
199void print_ioacct(struct taskstats *t)
200{
201 printf("%s: read=%llu, write=%llu, cancelled_write=%llu\n",
202 t->ac_comm,
203 (unsigned long long)t->read_bytes,
204 (unsigned long long)t->write_bytes,
205 (unsigned long long)t->cancelled_write_bytes);
206}
207
189int main(int argc, char *argv[]) 208int main(int argc, char *argv[])
190{ 209{
191 int c, rc, rep_len, aggr_len, len2, cmd_type; 210 int c, rc, rep_len, aggr_len, len2, cmd_type;
@@ -208,7 +227,7 @@ int main(int argc, char *argv[])
208 struct msgtemplate msg; 227 struct msgtemplate msg;
209 228
210 while (1) { 229 while (1) {
211 c = getopt(argc, argv, "dw:r:m:t:p:v:l"); 230 c = getopt(argc, argv, "diw:r:m:t:p:v:l");
212 if (c < 0) 231 if (c < 0)
213 break; 232 break;
214 233
@@ -217,6 +236,10 @@ int main(int argc, char *argv[])
217 printf("print delayacct stats ON\n"); 236 printf("print delayacct stats ON\n");
218 print_delays = 1; 237 print_delays = 1;
219 break; 238 break;
239 case 'i':
240 printf("printing IO accounting\n");
241 print_io_accounting = 1;
242 break;
220 case 'w': 243 case 'w':
221 strncpy(logfile, optarg, MAX_FILENAME); 244 strncpy(logfile, optarg, MAX_FILENAME);
222 printf("write to file %s\n", logfile); 245 printf("write to file %s\n", logfile);
@@ -238,14 +261,12 @@ int main(int argc, char *argv[])
238 if (!tid) 261 if (!tid)
239 err(1, "Invalid tgid\n"); 262 err(1, "Invalid tgid\n");
240 cmd_type = TASKSTATS_CMD_ATTR_TGID; 263 cmd_type = TASKSTATS_CMD_ATTR_TGID;
241 print_delays = 1;
242 break; 264 break;
243 case 'p': 265 case 'p':
244 tid = atoi(optarg); 266 tid = atoi(optarg);
245 if (!tid) 267 if (!tid)
246 err(1, "Invalid pid\n"); 268 err(1, "Invalid pid\n");
247 cmd_type = TASKSTATS_CMD_ATTR_PID; 269 cmd_type = TASKSTATS_CMD_ATTR_PID;
248 print_delays = 1;
249 break; 270 break;
250 case 'v': 271 case 'v':
251 printf("debug on\n"); 272 printf("debug on\n");
@@ -277,7 +298,7 @@ int main(int argc, char *argv[])
277 mypid = getpid(); 298 mypid = getpid();
278 id = get_family_id(nl_sd); 299 id = get_family_id(nl_sd);
279 if (!id) { 300 if (!id) {
280 printf("Error getting family id, errno %d", errno); 301 fprintf(stderr, "Error getting family id, errno %d\n", errno);
281 goto err; 302 goto err;
282 } 303 }
283 PRINTF("family id %d\n", id); 304 PRINTF("family id %d\n", id);
@@ -288,7 +309,7 @@ int main(int argc, char *argv[])
288 &cpumask, strlen(cpumask) + 1); 309 &cpumask, strlen(cpumask) + 1);
289 PRINTF("Sent register cpumask, retval %d\n", rc); 310 PRINTF("Sent register cpumask, retval %d\n", rc);
290 if (rc < 0) { 311 if (rc < 0) {
291 printf("error sending register cpumask\n"); 312 fprintf(stderr, "error sending register cpumask\n");
292 goto err; 313 goto err;
293 } 314 }
294 } 315 }
@@ -298,7 +319,7 @@ int main(int argc, char *argv[])
298 cmd_type, &tid, sizeof(__u32)); 319 cmd_type, &tid, sizeof(__u32));
299 PRINTF("Sent pid/tgid, retval %d\n", rc); 320 PRINTF("Sent pid/tgid, retval %d\n", rc);
300 if (rc < 0) { 321 if (rc < 0) {
301 printf("error sending tid/tgid cmd\n"); 322 fprintf(stderr, "error sending tid/tgid cmd\n");
302 goto done; 323 goto done;
303 } 324 }
304 } 325 }
@@ -310,13 +331,15 @@ int main(int argc, char *argv[])
310 PRINTF("received %d bytes\n", rep_len); 331 PRINTF("received %d bytes\n", rep_len);
311 332
312 if (rep_len < 0) { 333 if (rep_len < 0) {
313 printf("nonfatal reply error: errno %d\n", errno); 334 fprintf(stderr, "nonfatal reply error: errno %d\n",
335 errno);
314 continue; 336 continue;
315 } 337 }
316 if (msg.n.nlmsg_type == NLMSG_ERROR || 338 if (msg.n.nlmsg_type == NLMSG_ERROR ||
317 !NLMSG_OK((&msg.n), rep_len)) { 339 !NLMSG_OK((&msg.n), rep_len)) {
318 struct nlmsgerr *err = NLMSG_DATA(&msg); 340 struct nlmsgerr *err = NLMSG_DATA(&msg);
319 printf("fatal reply error, errno %d\n", err->error); 341 fprintf(stderr, "fatal reply error, errno %d\n",
342 err->error);
320 goto done; 343 goto done;
321 } 344 }
322 345
@@ -356,6 +379,8 @@ int main(int argc, char *argv[])
356 count++; 379 count++;
357 if (print_delays) 380 if (print_delays)
358 print_delayacct((struct taskstats *) NLA_DATA(na)); 381 print_delayacct((struct taskstats *) NLA_DATA(na));
382 if (print_io_accounting)
383 print_ioacct((struct taskstats *) NLA_DATA(na));
359 if (fd) { 384 if (fd) {
360 if (write(fd, NLA_DATA(na), na->nla_len) < 0) { 385 if (write(fd, NLA_DATA(na), na->nla_len) < 0) {
361 err(1,"write error\n"); 386 err(1,"write error\n");
@@ -365,7 +390,9 @@ int main(int argc, char *argv[])
365 goto done; 390 goto done;
366 break; 391 break;
367 default: 392 default:
368 printf("Unknown nested nla_type %d\n", na->nla_type); 393 fprintf(stderr, "Unknown nested"
394 " nla_type %d\n",
395 na->nla_type);
369 break; 396 break;
370 } 397 }
371 len2 += NLA_ALIGN(na->nla_len); 398 len2 += NLA_ALIGN(na->nla_len);
@@ -374,7 +401,8 @@ int main(int argc, char *argv[])
374 break; 401 break;
375 402
376 default: 403 default:
377 printf("Unknown nla_type %d\n", na->nla_type); 404 fprintf(stderr, "Unknown nla_type %d\n",
405 na->nla_type);
378 break; 406 break;
379 } 407 }
380 na = (struct nlattr *) (GENLMSG_DATA(&msg) + len); 408 na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);