debuggers.hg

annotate tools/misc/xenperf.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents a1b39d2b9001
children
rev   line source
kaf24@3269 1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
kaf24@3269 2 ****************************************************************************
kaf24@3269 3 * (C) 2004 - Rolf Neugebauer - Intel Research Cambridge
kaf24@3269 4 ****************************************************************************
kaf24@3269 5 *
kaf24@3269 6 * File: xenperf.c
kaf24@3269 7 * Author: Rolf Neugebauer (rolf.neugebauer@intel.com)
kaf24@3269 8 * Date: Nov 2004
kaf24@3269 9 *
kaf24@3269 10 * Description:
kaf24@3269 11 */
kaf24@3269 12
cl349@6426 13 #include <xenctrl.h>
kaf24@3269 14 #include <stdio.h>
kaf24@3269 15 #include <stdlib.h>
kaf24@3269 16 #include <sys/mman.h>
kaf24@3269 17 #include <errno.h>
kaf24@3269 18 #include <string.h>
kaf24@3269 19
kfraser@12439 20 #define X(name) [__HYPERVISOR_##name] = #name
kfraser@12439 21 const char *hypercall_name_table[64] =
kfraser@12439 22 {
kfraser@12439 23 X(set_trap_table),
kfraser@12439 24 X(mmu_update),
kfraser@12439 25 X(set_gdt),
kfraser@12439 26 X(stack_switch),
kfraser@12439 27 X(set_callbacks),
kfraser@12439 28 X(fpu_taskswitch),
kfraser@12439 29 X(sched_op_compat),
kfraser@12439 30 X(platform_op),
kfraser@12439 31 X(set_debugreg),
kfraser@12439 32 X(get_debugreg),
kfraser@12439 33 X(update_descriptor),
kfraser@12439 34 X(memory_op),
kfraser@12439 35 X(multicall),
kfraser@12439 36 X(update_va_mapping),
kfraser@12439 37 X(set_timer_op),
kfraser@12439 38 X(event_channel_op_compat),
kfraser@12439 39 X(xen_version),
kfraser@12439 40 X(console_io),
kfraser@12439 41 X(physdev_op_compat),
kfraser@12439 42 X(grant_table_op),
kfraser@12439 43 X(vm_assist),
kfraser@12439 44 X(update_va_mapping_otherdomain),
kfraser@12439 45 X(iret),
kfraser@12439 46 X(vcpu_op),
kfraser@12439 47 X(set_segment_base),
kfraser@12439 48 X(mmuext_op),
kfraser@15848 49 X(xsm_op),
kfraser@12439 50 X(nmi_op),
kfraser@12439 51 X(sched_op),
kfraser@12439 52 X(callback_op),
kfraser@12439 53 X(xenoprof_op),
kfraser@12439 54 X(event_channel_op),
kfraser@12439 55 X(physdev_op),
kfraser@12439 56 X(hvm_op),
kfraser@12439 57 X(sysctl),
kfraser@12439 58 X(domctl),
kfraser@12439 59 X(kexec_op),
kfraser@12439 60 X(arch_0),
kfraser@12439 61 X(arch_1),
kfraser@12439 62 X(arch_2),
kfraser@12439 63 X(arch_3),
kfraser@12439 64 X(arch_4),
kfraser@12439 65 X(arch_5),
kfraser@12439 66 X(arch_6),
kfraser@12439 67 X(arch_7),
kfraser@12439 68 };
kfraser@12439 69 #undef X
kfraser@12439 70
kaf24@3269 71 int main(int argc, char *argv[])
kaf24@3269 72 {
keir@21529 73 int i, j;
keir@21529 74 xc_interface *xc_handle;
ian@22338 75 DECLARE_HYPERCALL_BUFFER(xc_perfc_desc_t, pcd);
ian@22338 76 DECLARE_HYPERCALL_BUFFER(xc_perfc_val_t, pcv);
kfraser@12439 77 xc_perfc_val_t *val;
kfraser@12439 78 int num_desc, num_val;
kfraser@12439 79 unsigned int sum, reset = 0, full = 0, pretty = 0;
kfraser@12439 80 char hypercall_name[36];
kaf24@3269 81
kaf24@3269 82 if ( argc > 1 )
kaf24@3269 83 {
kaf24@3269 84 char *p = argv[1];
kaf24@4245 85 if ( p[0] == '-' )
kaf24@4245 86 {
kaf24@4245 87 switch ( p[1] )
kaf24@4245 88 {
kaf24@4245 89 case 'f':
kaf24@4245 90 full = 1;
kaf24@4245 91 break;
kfraser@12439 92 case 'p':
kfraser@12439 93 full = 1;
kfraser@12439 94 pretty = 1;
kfraser@12439 95 break;
kaf24@4245 96 case 'r':
kaf24@4245 97 reset = 1;
kaf24@4245 98 break;
kaf24@4245 99 default:
kaf24@4245 100 goto error;
kaf24@4245 101 }
kaf24@4245 102 }
kaf24@3269 103 else
kaf24@3269 104 {
kaf24@4245 105 error:
kaf24@3269 106 printf("%s: [-r]\n", argv[0]);
kaf24@4245 107 printf("no args: print digested counters\n");
kaf24@4245 108 printf(" -f : print full arrays/histograms\n");
kfraser@12439 109 printf(" -p : print full arrays/histograms in pretty format\n");
kaf24@4245 110 printf(" -r : reset counters\n");
kaf24@3269 111 return 0;
kaf24@3269 112 }
kaf24@3269 113 }
kaf24@3269 114
keir@21529 115 if ( (xc_handle = xc_interface_open(0,0,0)) == 0 )
kaf24@3269 116 {
kaf24@3269 117 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
kaf24@3269 118 errno, strerror(errno));
kaf24@3269 119 return 1;
kaf24@3269 120 }
kaf24@3269 121
kaf24@3269 122 if ( reset )
kaf24@3269 123 {
ian@22304 124 if ( xc_perfc_reset(xc_handle) != 0 )
kaf24@3269 125 {
kaf24@3269 126 fprintf(stderr, "Error reseting performance counters: %d (%s)\n",
kaf24@3269 127 errno, strerror(errno));
kaf24@3269 128 return 1;
kaf24@3269 129 }
kaf24@3269 130
kaf24@3269 131 return 0;
kaf24@3269 132 }
kaf24@3269 133
ian@22304 134 if ( xc_perfc_query_number(xc_handle, &num_desc, &num_val) != 0 )
kfraser@12439 135 {
kfraser@12439 136 fprintf(stderr, "Error getting number of perf counters: %d (%s)\n",
kfraser@12439 137 errno, strerror(errno));
kfraser@12439 138 return 1;
kfraser@12439 139 }
kaf24@3269 140
ian@22338 141 pcd = xc_hypercall_buffer_alloc(xc_handle, pcd, sizeof(*pcd) * num_desc);
ian@22338 142 pcv = xc_hypercall_buffer_alloc(xc_handle, pcv, sizeof(*pcv) * num_val);
kaf24@10991 143
ian@22338 144 if ( pcd == NULL || pcv == NULL)
kaf24@3269 145 {
ian@22338 146 fprintf(stderr, "Could not allocate buffers: %d (%s)\n",
kaf24@10991 147 errno, strerror(errno));
kaf24@10991 148 exit(-1);
kaf24@10991 149 }
kaf24@10991 150
ian@22338 151 if ( xc_perfc_query(xc_handle, HYPERCALL_BUFFER(pcd), HYPERCALL_BUFFER(pcv)) != 0 )
kaf24@10991 152 {
kaf24@10991 153 fprintf(stderr, "Error getting perf counter: %d (%s)\n",
kaf24@3269 154 errno, strerror(errno));
kaf24@3269 155 return 1;
kaf24@3269 156 }
kaf24@3269 157
kfraser@12439 158 val = pcv;
kaf24@10991 159 for ( i = 0; i < num_desc; i++ )
kaf24@3269 160 {
kaf24@3269 161 printf ("%-35s ", pcd[i].name);
kaf24@3269 162
kaf24@3269 163 sum = 0;
kaf24@3269 164 for ( j = 0; j < pcd[i].nr_vals; j++ )
kaf24@10991 165 sum += val[j];
kaf24@3269 166 printf ("T=%10u ", (unsigned int)sum);
kaf24@3269 167
kaf24@4245 168 if ( full || (pcd[i].nr_vals <= 4) )
kfraser@12439 169 {
kfraser@12439 170 if ( pretty && (strcmp(pcd[i].name, "hypercalls") == 0) )
kfraser@12439 171 {
kfraser@12439 172 printf("\n");
kfraser@12439 173 for( j = 0; j < pcd[i].nr_vals; j++ )
kfraser@12439 174 {
kfraser@12439 175 if ( val[j] == 0 )
kfraser@12439 176 continue;
kfraser@12439 177 if ( (j < 64) && hypercall_name_table[j] )
kfraser@12439 178 strncpy(hypercall_name, hypercall_name_table[j],
kfraser@12439 179 sizeof(hypercall_name));
kfraser@12439 180 else
keir@17870 181 snprintf(hypercall_name, sizeof(hypercall_name), "[%d]", j);
kfraser@12439 182 hypercall_name[sizeof(hypercall_name)-1]='\0';
kfraser@12439 183 printf("%-35s ", hypercall_name);
kfraser@12439 184 printf("%12u\n", (unsigned int)val[j]);
kfraser@12439 185 }
kfraser@12439 186 }
kfraser@12439 187 else
kfraser@12439 188 {
kfraser@12439 189 for ( j = 0; j < pcd[i].nr_vals; j++ )
kfraser@12439 190 printf(" %10u", (unsigned int)val[j]);
kfraser@12439 191 printf("\n");
kfraser@12439 192 }
kfraser@12439 193 }
kfraser@12439 194 else
kfraser@12439 195 {
kfraser@12439 196 printf("\n");
kfraser@12439 197 }
kaf24@3269 198
kfraser@12439 199 val += pcd[i].nr_vals;
kaf24@3269 200 }
kaf24@3269 201
ian@22338 202 xc_hypercall_buffer_free(xc_handle, pcd);
ian@22338 203 xc_hypercall_buffer_free(xc_handle, pcv);
kaf24@3269 204 return 0;
kaf24@3269 205 }