debuggers.hg

view tools/misc/xenperf.c @ 10991:7924b6bd728a

Change DOM0_PERFCCONTROL: remove array limit.

Descriptors and values are passed by two distinct buffers.

Signed-off-by: Tristan Gingold <tristan.gingold@bull.net>
author kaf24@firebug.cl.cam.ac.uk
date Mon Aug 07 15:53:06 2006 +0100 (2006-08-07)
parents 06d84bf87159
children 86d26e6ec89b
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 xc_perfc_val_t *pcv;
26 xc_perfc_val_t *val;
27 int num_desc, num_val;
28 unsigned int sum, reset = 0, full = 0;
30 if ( argc > 1 )
31 {
32 char *p = argv[1];
33 if ( p[0] == '-' )
34 {
35 switch ( p[1] )
36 {
37 case 'f':
38 full = 1;
39 break;
40 case 'r':
41 reset = 1;
42 break;
43 default:
44 goto error;
45 }
46 }
47 else
48 {
49 error:
50 printf("%s: [-r]\n", argv[0]);
51 printf("no args: print digested counters\n");
52 printf(" -f : print full arrays/histograms\n");
53 printf(" -r : reset counters\n");
54 return 0;
55 }
56 }
58 if ( (xc_handle = xc_interface_open()) == -1 )
59 {
60 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
61 errno, strerror(errno));
62 return 1;
63 }
65 if ( reset )
66 {
67 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_RESET,
68 NULL, NULL, NULL, NULL) != 0 )
69 {
70 fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
71 errno, strerror(errno));
72 return 1;
73 }
75 return 0;
76 }
78 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_QUERY,
79 NULL, NULL, &num_desc, &num_val) != 0 )
80 {
81 fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
82 errno, strerror(errno));
83 return 1;
84 }
86 pcd = malloc(sizeof(*pcd) * num_desc);
87 pcv = malloc(sizeof(*pcv) * num_val);
89 if ( pcd == NULL
90 || mlock(pcd, sizeof(*pcd) * num_desc) != 0
91 || pcv == NULL
92 || mlock(pcd, sizeof(*pcv) * num_val) != 0)
93 {
94 fprintf(stderr, "Could not alloc or mlock buffers: %d (%s)\n",
95 errno, strerror(errno));
96 exit(-1);
97 }
99 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_QUERY,
100 pcd, pcv, NULL, NULL) != 0 )
101 {
102 fprintf(stderr, "Error getting perf counter: %d (%s)\n",
103 errno, strerror(errno));
104 return 1;
105 }
107 munlock(pcd, sizeof(*pcd) * num_desc);
108 munlock(pcv, sizeof(*pcv) * num_val);
110 val = pcv;
111 for ( i = 0; i < num_desc; i++ )
112 {
113 printf ("%-35s ", pcd[i].name);
115 sum = 0;
116 for ( j = 0; j < pcd[i].nr_vals; j++ )
117 sum += val[j];
118 printf ("T=%10u ", (unsigned int)sum);
120 if ( full || (pcd[i].nr_vals <= 4) )
121 for ( j = 0; j < pcd[i].nr_vals; j++ )
122 printf(" %10u", (unsigned int)val[j]);
124 printf("\n");
125 val += pcd[i].nr_vals;
126 }
128 return 0;
129 }