debuggers.hg

annotate tools/misc/xenlockprof.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
keir@20350 1 /* -*- Mode:C; c-basic-offset:4; tab-width:4 -*-
keir@20350 2 ****************************************************************************
keir@20350 3 * (C) 2009 - Juergen Gross - Fujitsu Technology Solutions
keir@20350 4 ****************************************************************************
keir@20350 5 *
keir@20350 6 * File: xenlockprof.c
keir@20350 7 * Author: Juergen Gross (juergen.gross@ts.fujitsu.com)
keir@20350 8 * Date: Oct 2009
keir@20350 9 *
keir@20350 10 * Description:
keir@20350 11 */
keir@20350 12
keir@20350 13 #include <xenctrl.h>
keir@20350 14 #include <stdio.h>
keir@20350 15 #include <stdlib.h>
keir@20350 16 #include <sys/mman.h>
keir@20350 17 #include <errno.h>
keir@20350 18 #include <string.h>
keir@20354 19 #include <inttypes.h>
keir@20350 20
keir@20350 21 int main(int argc, char *argv[])
keir@20350 22 {
keir@21529 23 xc_interface *xc_handle;
keir@20350 24 uint32_t i, j, n;
keir@20350 25 uint64_t time;
keir@20350 26 double l, b, sl, sb;
keir@20350 27 char name[60];
ian@22338 28 DECLARE_HYPERCALL_BUFFER(xc_lockprof_data_t, data);
keir@20350 29
keir@20354 30 if ( (argc > 2) || ((argc == 2) && (strcmp(argv[1], "-r") != 0)) )
keir@20350 31 {
keir@20350 32 printf("%s: [-r]\n", argv[0]);
keir@20350 33 printf("no args: print lock profile data\n");
keir@20350 34 printf(" -r : reset profile data\n");
keir@20350 35 return 1;
keir@20350 36 }
keir@20350 37
keir@21529 38 if ( (xc_handle = xc_interface_open(0,0,0)) == 0 )
keir@20350 39 {
keir@20350 40 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
keir@20350 41 errno, strerror(errno));
keir@20350 42 return 1;
keir@20350 43 }
keir@20350 44
keir@20354 45 if ( argc > 1 )
keir@20350 46 {
ian@22305 47 if ( xc_lockprof_reset(xc_handle) != 0 )
keir@20350 48 {
keir@20350 49 fprintf(stderr, "Error reseting profile data: %d (%s)\n",
keir@20350 50 errno, strerror(errno));
keir@20350 51 return 1;
keir@20350 52 }
keir@20354 53 return 0;
keir@20350 54 }
keir@20350 55
keir@20350 56 n = 0;
ian@22305 57 if ( xc_lockprof_query_number(xc_handle, &n) != 0 )
keir@20350 58 {
keir@20350 59 fprintf(stderr, "Error getting number of profile records: %d (%s)\n",
keir@20350 60 errno, strerror(errno));
keir@20350 61 return 1;
keir@20350 62 }
keir@20350 63
keir@20350 64 n += 32; /* just to be sure */
ian@22338 65 data = xc_hypercall_buffer_alloc(xc_handle, data, sizeof(*data) * n);
ian@22338 66 if ( data == NULL )
keir@20350 67 {
ian@22338 68 fprintf(stderr, "Could not allocate buffers: %d (%s)\n",
keir@20350 69 errno, strerror(errno));
keir@20350 70 return 1;
keir@20350 71 }
keir@20350 72
keir@20350 73 i = n;
ian@22338 74 if ( xc_lockprof_query(xc_handle, &i, &time, HYPERCALL_BUFFER(data)) != 0 )
keir@20350 75 {
keir@20350 76 fprintf(stderr, "Error getting profile records: %d (%s)\n",
keir@20350 77 errno, strerror(errno));
keir@20350 78 return 1;
keir@20350 79 }
keir@20350 80
keir@20354 81 if ( i > n )
keir@20350 82 {
keir@20350 83 printf("data incomplete, %d records are missing!\n\n", i - n);
keir@20350 84 i = n;
keir@20350 85 }
keir@20354 86
keir@20350 87 sl = 0;
keir@20350 88 sb = 0;
keir@20354 89 for ( j = 0; j < i; j++ )
keir@20350 90 {
keir@20354 91 switch ( data[j].type )
keir@20350 92 {
keir@20350 93 case LOCKPROF_TYPE_GLOBAL:
keir@20350 94 sprintf(name, "global lock %s", data[j].name);
keir@20350 95 break;
keir@20350 96 case LOCKPROF_TYPE_PERDOM:
keir@20350 97 sprintf(name, "domain %d lock %s", data[j].idx, data[j].name);
keir@20350 98 break;
keir@20350 99 default:
keir@20350 100 sprintf(name, "unknown type(%d) %d lock %s", data[j].type,
keir@20354 101 data[j].idx, data[j].name);
keir@20350 102 break;
keir@20350 103 }
keir@20350 104 l = (double)(data[j].lock_time) / 1E+09;
keir@20350 105 b = (double)(data[j].block_time) / 1E+09;
keir@20350 106 sl += l;
keir@20350 107 sb += b;
keir@20354 108 printf("%-50s: lock:%12"PRId64"(%20.9fs), "
keir@20354 109 "block:%12"PRId64"(%20.9fs)\n",
keir@20354 110 name, data[j].lock_cnt, l, data[j].block_cnt, b);
keir@20350 111 }
keir@20350 112 l = (double)time / 1E+09;
keir@20350 113 printf("total profiling time: %20.9fs\n", l);
keir@20350 114 printf("total locked time: %20.9fs\n", sl);
keir@20350 115 printf("total blocked time: %20.9fs\n", sb);
keir@20350 116
ian@22338 117 xc_hypercall_buffer_free(xc_handle, data);
ian@22338 118
keir@20350 119 return 0;
keir@20350 120 }