direct-io.hg

view tools/misc/xenperf.c @ 3231:9035b6656818

bitkeeper revision 1.1159.187.48 (41adc6420WlNaaoUkvfgNxl44rpYYg)

Export Xen s/w perfctrs to DOM0 via new 'xenperf' utility.
author kaf24@scramble.cl.cam.ac.uk
date Wed Dec 01 13:25:22 2004 +0000 (2004-12-01)
parents
children f2e12f9f7cc8
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 <xc.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;
27 if ( argc > 1 )
28 {
29 char *p = argv[1];
30 if ( (*p++ == '-') && (*p == 'r') )
31 reset = 1;
32 else
33 {
34 printf("%s: [-r]\n", argv[0]);
35 printf("no args: print xen performance counters\n");
36 printf(" -r : reset xen performance counters\n");
37 return 0;
38 }
39 }
41 if ( (xc_handle = xc_interface_open()) == -1 )
42 {
43 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
44 errno, strerror(errno));
45 return 1;
46 }
48 if ( reset )
49 {
50 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_RESET,
51 NULL) < 0 )
52 {
53 fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
54 errno, strerror(errno));
55 return 1;
56 }
58 return 0;
59 }
62 if ( (num = xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_QUERY,
63 NULL)) < 0 )
64 {
65 fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
66 errno, strerror(errno));
67 return 1;
68 }
70 pcd = malloc(sizeof(*pcd) * num);
72 if ( mlock(pcd, sizeof(*pcd) * num) != 0 )
73 {
74 fprintf(stderr, "Could not mlock descriptor buffer: %d (%s)\n",
75 errno, strerror(errno));
76 exit(-1);
77 }
79 if ( xc_perfc_control(xc_handle, DOM0_PERFCCONTROL_OP_QUERY, pcd) <= 0 )
80 {
81 fprintf(stderr, "Error getting perf counter description: %d (%s)\n",
82 errno, strerror(errno));
83 return 1;
84 }
86 munlock(pcd, sizeof(*pcd) * num);
88 for ( i = 0; i < num; i++ )
89 {
90 printf ("%-35s ", pcd[i].name);
92 sum = 0;
93 for ( j = 0; j < pcd[i].nr_vals; j++ )
94 sum += pcd[i].vals[j];
95 printf ("T=%10u ", (unsigned int)sum);
97 for ( j = 0; j < pcd[i].nr_vals; j++ )
98 printf(" %10u", (unsigned int)pcd[i].vals[j]);
100 printf("\n");
101 }
103 return 0;
104 }