ia64/xen-unstable

view tools/misc/xenperf.c @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 06d84bf87159
children 7924b6bd728a
line source
1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
2 ****************************************************************************
3 * (C) 2004 - Rolf Neugebauer - Intel Research Cambridge
4 ****************************************************************************
5 *
6 * File: xenperf.c
7 * Author: Rolf Neugebauer (rolf.neugebauer@intel.com)
8 * Date: Nov 2004
9 *
10 * Description:
11 */
14 #include <xenctrl.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <sys/mman.h>
18 #include <errno.h>
19 #include <string.h>
21 int main(int argc, char *argv[])
22 {
23 int i, j, xc_handle;
24 xc_perfc_desc_t *pcd;
25 unsigned int num, sum, reset = 0, full = 0;
27 if ( argc > 1 )
28 {
29 char *p = argv[1];
30 if ( p[0] == '-' )
31 {
32 switch ( p[1] )
33 {
34 case 'f':
35 full = 1;
36 break;
37 case 'r':
38 reset = 1;
39 break;
40 default:
41 goto error;
42 }
43 }
44 else
45 {
46 error:
47 printf("%s: [-r]\n", argv[0]);
48 printf("no args: print digested counters\n");
49 printf(" -f : print full arrays/histograms\n");
50 printf(" -r : reset counters\n");
51 return 0;
52 }
53 }
55 if ( (xc_handle = xc_interface_open()) == -1 )
56 {
57 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
58 errno, strerror(errno));
59 return 1;
60 }
62 if ( reset )
63 {
64 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_RESET,
65 NULL) < 0 )
66 {
67 fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
68 errno, strerror(errno));
69 return 1;
70 }
72 return 0;
73 }
76 if ( (num = xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_QUERY,
77 NULL)) < 0 )
78 {
79 fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
80 errno, strerror(errno));
81 return 1;
82 }
84 pcd = malloc(sizeof(*pcd) * num);
86 if ( mlock(pcd, sizeof(*pcd) * num) != 0 )
87 {
88 fprintf(stderr, "Could not mlock descriptor buffer: %d (%s)\n",
89 errno, strerror(errno));
90 exit(-1);
91 }
93 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_QUERY, pcd) <= 0 )
94 {
95 fprintf(stderr, "Error getting perf counter description: %d (%s)\n",
96 errno, strerror(errno));
97 return 1;
98 }
100 munlock(pcd, sizeof(*pcd) * num);
102 for ( i = 0; i < num; i++ )
103 {
104 printf ("%-35s ", pcd[i].name);
106 sum = 0;
107 for ( j = 0; j < pcd[i].nr_vals; j++ )
108 sum += pcd[i].vals[j];
109 printf ("T=%10u ", (unsigned int)sum);
111 if ( full || (pcd[i].nr_vals <= 4) )
112 for ( j = 0; j < pcd[i].nr_vals; j++ )
113 printf(" %10u", (unsigned int)pcd[i].vals[j]);
115 printf("\n");
116 }
118 return 0;
119 }