debuggers.hg

view tools/misc/xenlockprof.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 9e24f7f9d7a8
children 3ffdb094c2c0
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 static int lock_pages(void *addr, size_t len)
22 {
23 int e = 0;
24 #ifndef __sun__
25 e = mlock(addr, len);
26 #endif
27 return (e);
28 }
30 static void unlock_pages(void *addr, size_t len)
31 {
32 #ifndef __sun__
33 munlock(addr, len);
34 #endif
35 }
37 int main(int argc, char *argv[])
38 {
39 int xc_handle;
40 uint32_t i, j, n;
41 uint64_t time;
42 double l, b, sl, sb;
43 char name[60];
44 xc_lockprof_data_t *data;
46 if ( (argc > 2) || ((argc == 2) && (strcmp(argv[1], "-r") != 0)) )
47 {
48 printf("%s: [-r]\n", argv[0]);
49 printf("no args: print lock profile data\n");
50 printf(" -r : reset profile data\n");
51 return 1;
52 }
54 if ( (xc_handle = xc_interface_open()) == -1 )
55 {
56 fprintf(stderr, "Error opening xc interface: %d (%s)\n",
57 errno, strerror(errno));
58 return 1;
59 }
61 if ( argc > 1 )
62 {
63 if ( xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_reset, NULL,
64 NULL, NULL) != 0 )
65 {
66 fprintf(stderr, "Error reseting profile data: %d (%s)\n",
67 errno, strerror(errno));
68 return 1;
69 }
70 return 0;
71 }
73 n = 0;
74 if ( xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_query, &n,
75 NULL, NULL) != 0 )
76 {
77 fprintf(stderr, "Error getting number of profile records: %d (%s)\n",
78 errno, strerror(errno));
79 return 1;
80 }
82 n += 32; /* just to be sure */
83 data = malloc(sizeof(*data) * n);
84 if ( (data == NULL) || (lock_pages(data, sizeof(*data) * n) != 0) )
85 {
86 fprintf(stderr, "Could not alloc or lock buffers: %d (%s)\n",
87 errno, strerror(errno));
88 return 1;
89 }
91 i = n;
92 if ( xc_lockprof_control(xc_handle, XEN_SYSCTL_LOCKPROF_query, &i,
93 &time, data) != 0 )
94 {
95 fprintf(stderr, "Error getting profile records: %d (%s)\n",
96 errno, strerror(errno));
97 return 1;
98 }
100 unlock_pages(data, sizeof(*data) * n);
102 if ( i > n )
103 {
104 printf("data incomplete, %d records are missing!\n\n", i - n);
105 i = n;
106 }
108 sl = 0;
109 sb = 0;
110 for ( j = 0; j < i; j++ )
111 {
112 switch ( data[j].type )
113 {
114 case LOCKPROF_TYPE_GLOBAL:
115 sprintf(name, "global lock %s", data[j].name);
116 break;
117 case LOCKPROF_TYPE_PERDOM:
118 sprintf(name, "domain %d lock %s", data[j].idx, data[j].name);
119 break;
120 default:
121 sprintf(name, "unknown type(%d) %d lock %s", data[j].type,
122 data[j].idx, data[j].name);
123 break;
124 }
125 l = (double)(data[j].lock_time) / 1E+09;
126 b = (double)(data[j].block_time) / 1E+09;
127 sl += l;
128 sb += b;
129 printf("%-50s: lock:%12"PRId64"(%20.9fs), "
130 "block:%12"PRId64"(%20.9fs)\n",
131 name, data[j].lock_cnt, l, data[j].block_cnt, b);
132 }
133 l = (double)time / 1E+09;
134 printf("total profiling time: %20.9fs\n", l);
135 printf("total locked time: %20.9fs\n", sl);
136 printf("total blocked time: %20.9fs\n", sb);
138 return 0;
139 }