ia64/xen-unstable

view tools/misc/xenperf.c @ 18059:4b882c41c9b9

tools: Make functions static which should not be exported.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jul 15 15:03:58 2008 +0100 (2008-07-15)
parents e5c9c8e6e726
children
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 */
13 #include <xenctrl.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <sys/mman.h>
17 #include <errno.h>
18 #include <string.h>
20 #define X(name) [__HYPERVISOR_##name] = #name
21 const char *hypercall_name_table[64] =
22 {
23 X(set_trap_table),
24 X(mmu_update),
25 X(set_gdt),
26 X(stack_switch),
27 X(set_callbacks),
28 X(fpu_taskswitch),
29 X(sched_op_compat),
30 X(platform_op),
31 X(set_debugreg),
32 X(get_debugreg),
33 X(update_descriptor),
34 X(memory_op),
35 X(multicall),
36 X(update_va_mapping),
37 X(set_timer_op),
38 X(event_channel_op_compat),
39 X(xen_version),
40 X(console_io),
41 X(physdev_op_compat),
42 X(grant_table_op),
43 X(vm_assist),
44 X(update_va_mapping_otherdomain),
45 X(iret),
46 X(vcpu_op),
47 X(set_segment_base),
48 X(mmuext_op),
49 X(xsm_op),
50 X(nmi_op),
51 X(sched_op),
52 X(callback_op),
53 X(xenoprof_op),
54 X(event_channel_op),
55 X(physdev_op),
56 X(hvm_op),
57 X(sysctl),
58 X(domctl),
59 X(kexec_op),
60 X(arch_0),
61 X(arch_1),
62 X(arch_2),
63 X(arch_3),
64 X(arch_4),
65 X(arch_5),
66 X(arch_6),
67 X(arch_7),
68 };
69 #undef X
71 static int lock_pages(void *addr, size_t len)
72 {
73 int e = 0;
74 #ifndef __sun__
75 e = mlock(addr, len);
76 #endif
77 return (e);
78 }
80 static void unlock_pages(void *addr, size_t len)
81 {
82 #ifndef __sun__
83 munlock(addr, len);
84 #endif
85 }
87 int main(int argc, char *argv[])
88 {
89 int i, j, xc_handle;
90 xc_perfc_desc_t *pcd;
91 xc_perfc_val_t *pcv;
92 xc_perfc_val_t *val;
93 int num_desc, num_val;
94 unsigned int sum, reset = 0, full = 0, pretty = 0;
95 char hypercall_name[36];
97 if ( argc > 1 )
98 {
99 char *p = argv[1];
100 if ( p[0] == '-' )
101 {
102 switch ( p[1] )
103 {
104 case 'f':
105 full = 1;
106 break;
107 case 'p':
108 full = 1;
109 pretty = 1;
110 break;
111 case 'r':
112 reset = 1;
113 break;
114 default:
115 goto error;
116 }
117 }
118 else
119 {
120 error:
121 printf("%s: [-r]\n", argv[0]);
122 printf("no args: print digested counters\n");
123 printf(" -f : print full arrays/histograms\n");
124 printf(" -p : print full arrays/histograms in pretty format\n");
125 printf(" -r : reset counters\n");
126 return 0;
127 }
128 }
130 if ( (xc_handle = xc_interface_open()) == -1 )
131 {
132 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
133 errno, strerror(errno));
134 return 1;
135 }
137 if ( reset )
138 {
139 if ( xc_perfc_control(xc_handle, XEN_SYSCTL_PERFCOP_reset,
140 NULL, NULL, NULL, NULL) != 0 )
141 {
142 fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
143 errno, strerror(errno));
144 return 1;
145 }
147 return 0;
148 }
150 if ( xc_perfc_control(xc_handle, XEN_SYSCTL_PERFCOP_query,
151 NULL, NULL, &num_desc, &num_val) != 0 )
152 {
153 fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
154 errno, strerror(errno));
155 return 1;
156 }
158 pcd = malloc(sizeof(*pcd) * num_desc);
159 pcv = malloc(sizeof(*pcv) * num_val);
161 if ( pcd == NULL
162 || lock_pages(pcd, sizeof(*pcd) * num_desc) != 0
163 || pcv == NULL
164 || lock_pages(pcv, sizeof(*pcv) * num_val) != 0)
165 {
166 fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n",
167 errno, strerror(errno));
168 exit(-1);
169 }
171 if ( xc_perfc_control(xc_handle, XEN_SYSCTL_PERFCOP_query,
172 pcd, pcv, NULL, NULL) != 0 )
173 {
174 fprintf(stderr, "Error getting perf counter: %d (%s)\n",
175 errno, strerror(errno));
176 return 1;
177 }
179 unlock_pages(pcd, sizeof(*pcd) * num_desc);
180 unlock_pages(pcv, sizeof(*pcv) * num_val);
182 val = pcv;
183 for ( i = 0; i < num_desc; i++ )
184 {
185 printf ("%-35s ", pcd[i].name);
187 sum = 0;
188 for ( j = 0; j < pcd[i].nr_vals; j++ )
189 sum += val[j];
190 printf ("T=%10u ", (unsigned int)sum);
192 if ( full || (pcd[i].nr_vals <= 4) )
193 {
194 if ( pretty && (strcmp(pcd[i].name, "hypercalls") == 0) )
195 {
196 printf("\n");
197 for( j = 0; j < pcd[i].nr_vals; j++ )
198 {
199 if ( val[j] == 0 )
200 continue;
201 if ( (j < 64) && hypercall_name_table[j] )
202 strncpy(hypercall_name, hypercall_name_table[j],
203 sizeof(hypercall_name));
204 else
205 snprintf(hypercall_name, sizeof(hypercall_name), "[%d]", j);
206 hypercall_name[sizeof(hypercall_name)-1]='\0';
207 printf("%-35s ", hypercall_name);
208 printf("%12u\n", (unsigned int)val[j]);
209 }
210 }
211 else
212 {
213 for ( j = 0; j < pcd[i].nr_vals; j++ )
214 printf(" %10u", (unsigned int)val[j]);
215 printf("\n");
216 }
217 }
218 else
219 {
220 printf("\n");
221 }
223 val += pcd[i].nr_vals;
224 }
226 return 0;
227 }