debuggers.hg

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