ia64/xen-unstable

view tools/misc/xenperf.c @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
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 }