debuggers.hg

view tools/misc/xen-tmem-list-parse.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 43f708d7a64e
children 3ffdb094c2c0
line source
1 /*
2 * Parse output from tmem-list and reformat to human-readable
3 *
4 * NOTE: NEVER delete a parse call as this file documents backwards
5 * compatibility for older versions of tmem-list and we don't want to
6 * accidentally reuse an old tag
7 *
8 * Copyright (c) 2009, Dan Magenheimer, Oracle Corp.
9 */
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
15 #define BUFSIZE 4096
16 #define PAGE_SIZE 4096
18 unsigned long long parse(char *s,char *match)
19 {
20 char *s1 = strstr(s,match);
21 unsigned long long ret;
23 if ( s1 == NULL )
24 return 0LL;
25 s1 += 2;
26 if ( *s1++ != ':' )
27 return 0LL;
28 sscanf(s1,"%llu",&ret);
29 return ret;
30 }
32 unsigned long long parse_hex(char *s,char *match)
33 {
34 char *s1 = strstr(s,match);
35 unsigned long long ret;
37 if ( s1 == NULL )
38 return 0LL;
39 s1 += 2;
40 if ( *s1++ != ':' )
41 return 0LL;
42 sscanf(s1,"%llx",&ret);
43 return ret;
44 }
46 unsigned long long parse2(char *s,char *match1, char *match2)
47 {
48 char match[3];
49 match[0] = *match1;
50 match[1] = *match2;
51 match[2] = '\0';
52 return parse(s,match);
53 }
55 void parse_string(char *s,char *match, char *buf, int len)
56 {
57 char *s1 = strstr(s,match);
58 int i;
60 if ( s1 == NULL )
61 return;
62 s1 += 2;
63 if ( *s1++ != ':' )
64 return;
65 for ( i = 0; i < len; i++ )
66 *buf++ = *s1++;
67 }
69 void parse_sharers(char *s, char *match, char *buf, int len)
70 {
71 char *s1 = strstr(s,match);
72 char *b = buf;
74 if ( s1 == NULL )
75 return;
76 while ( s1 )
77 {
78 s1 += 2;
79 if (*s1++ != ':')
80 return;
81 while (*s1 >= '0' && *s1 <= '9')
82 *b++ = *s1++;
83 *b++ = ',';
84 s1 = strstr(s1,match);
85 }
86 if ( b != buf )
87 *--b = '\0';
88 }
90 void parse_global(char *s)
91 {
92 unsigned long long total_ops = parse(s,"Tt");
93 unsigned long long errored_ops = parse(s,"Te");
94 unsigned long long failed_copies = parse(s,"Cf");
95 unsigned long long alloc_failed = parse(s,"Af");
96 unsigned long long alloc_page_failed = parse(s,"Pf");
97 unsigned long long avail_pages = parse(s,"Ta");
98 unsigned long long low_on_memory = parse(s,"Lm");
99 unsigned long long evicted_pgs = parse(s,"Et");
100 unsigned long long evict_attempts = parse(s,"Ea");
101 unsigned long long relinq_pgs = parse(s,"Rt");
102 unsigned long long relinq_attempts = parse(s,"Ra");
103 unsigned long long max_evicts_per_relinq = parse(s,"Rx");
104 unsigned long long total_flush_pool = parse(s,"Fp");
105 unsigned long long global_eph_count = parse(s,"Ec");
106 unsigned long long global_eph_max = parse(s,"Em");
107 unsigned long long obj_count = parse(s,"Oc");
108 unsigned long long obj_max = parse(s,"Om");
109 unsigned long long rtree_node_count = parse(s,"Nc");
110 unsigned long long rtree_node_max = parse(s,"Nm");
111 unsigned long long pgp_count = parse(s,"Pc");
112 unsigned long long pgp_max = parse(s,"Pm");
114 printf("total tmem ops=%llu (errors=%llu) -- tmem pages avail=%llu\n",
115 total_ops, errored_ops, avail_pages);
116 printf("datastructs: objs=%llu (max=%llu) pgps=%llu (max=%llu) "
117 "nodes=%llu (max=%llu)\n",
118 obj_count, obj_max, pgp_count, pgp_max,
119 rtree_node_count, rtree_node_max);
120 printf("misc: failed_copies=%llu alloc_failed=%llu alloc_page_failed=%llu "
121 "low_mem=%llu evicted=%llu/%llu relinq=%llu/%llu, "
122 "max_evicts_per_relinq=%llu, flush_pools=%llu, "
123 "eph_count=%llu, eph_max=%llu\n",
124 failed_copies, alloc_failed, alloc_page_failed, low_on_memory,
125 evicted_pgs, evict_attempts, relinq_pgs, relinq_attempts,
126 max_evicts_per_relinq, total_flush_pool,
127 global_eph_count, global_eph_max);
128 }
130 #define PARSE_CYC_COUNTER(s,x,prefix) unsigned long long \
131 x##_count = parse2(s,prefix,"n"), \
132 x##_sum_cycles = parse2(s,prefix,"t"), \
133 x##_max_cycles = parse2(s,prefix,"x"), \
134 x##_min_cycles = parse2(s,prefix,"m")
135 #define PRINTF_CYC_COUNTER(x,text) \
136 if (x##_count) printf(text" avg=%llu, max=%llu, " \
137 "min=%llu, samples=%llu\n", \
138 x##_sum_cycles ? (x##_sum_cycles/x##_count) : 0, \
139 x##_max_cycles, x##_min_cycles, x##_count)
141 void parse_time_stats(char *s)
142 {
143 PARSE_CYC_COUNTER(s,succ_get,"G");
144 PARSE_CYC_COUNTER(s,succ_put,"P");
145 PARSE_CYC_COUNTER(s,non_succ_get,"g");
146 PARSE_CYC_COUNTER(s,non_succ_put,"p");
147 PARSE_CYC_COUNTER(s,flush,"F");
148 PARSE_CYC_COUNTER(s,flush_obj,"O");
149 PARSE_CYC_COUNTER(s,pg_copy,"C");
150 PARSE_CYC_COUNTER(s,compress,"c");
151 PARSE_CYC_COUNTER(s,decompress,"d");
153 PRINTF_CYC_COUNTER(succ_get,"succ get cycles:");
154 PRINTF_CYC_COUNTER(succ_put,"succ put cycles:");
155 PRINTF_CYC_COUNTER(non_succ_get,"failed get cycles:");
156 PRINTF_CYC_COUNTER(non_succ_put,"failed put cycles:");
157 PRINTF_CYC_COUNTER(flush,"flush cycles:");
158 PRINTF_CYC_COUNTER(flush_obj,"flush_obj cycles:");
159 PRINTF_CYC_COUNTER(pg_copy,"page copy cycles:");
160 PRINTF_CYC_COUNTER(compress,"compression cycles:");
161 PRINTF_CYC_COUNTER(decompress,"decompression cycles:");
162 }
164 void parse_client(char *s)
165 {
166 unsigned long cli_id = parse(s,"CI");
167 unsigned long weight = parse(s,"ww");
168 unsigned long cap = parse(s,"ca");
169 unsigned long compress = parse(s,"co");
170 unsigned long frozen = parse(s,"fr");
171 unsigned long long eph_count = parse(s,"Ec");
172 unsigned long long max_eph_count = parse(s,"Em");
173 unsigned long long compressed_pages = parse(s,"cp");
174 unsigned long long compressed_sum_size = parse(s,"cb");
175 unsigned long long compress_poor = parse(s,"cn");
176 unsigned long long compress_nomem = parse(s,"cm");
177 unsigned long long total_cycles = parse(s,"Tc");
178 unsigned long long succ_eph_gets = parse(s,"Ge");
179 unsigned long long succ_pers_puts = parse(s,"Pp");
180 unsigned long long succ_pers_gets = parse(s,"Gp");
182 printf("domid%lu: weight=%lu,cap=%lu,compress=%d,frozen=%d,"
183 "total_cycles=%llu,succ_eph_gets=%llu,"
184 "succ_pers_puts=%llu,succ_pers_gets=%llu,"
185 "eph_count=%llu,max_eph=%llu,"
186 "compression ratio=%lu%% (samples=%llu,poor=%llu,nomem=%llu)\n",
187 cli_id, weight, cap, compress?1:0, frozen?1:0,
188 total_cycles, succ_eph_gets, succ_pers_puts, succ_pers_gets,
189 eph_count, max_eph_count,
190 compressed_pages ? (long)((compressed_sum_size*100LL) /
191 (compressed_pages*PAGE_SIZE)) : 0,
192 compressed_pages, compress_poor, compress_nomem);
194 }
196 void parse_pool(char *s)
197 {
198 char pool_type[3];
199 unsigned long cli_id = parse(s,"CI");
200 unsigned long pool_id = parse(s,"PI");
201 unsigned long long pgp_count = parse(s,"Pc");
202 unsigned long long max_pgp_count = parse(s,"Pm");
203 unsigned long long obj_count = parse(s,"Oc");
204 unsigned long long max_obj_count = parse(s,"Om");
205 unsigned long long objnode_count = parse(s,"Nc");
206 unsigned long long max_objnode_count = parse(s,"Nm");
207 unsigned long long good_puts = parse(s,"ps");
208 unsigned long long puts = parse(s,"pt");
209 unsigned long long no_mem_puts = parse(s,"px");
210 unsigned long long dup_puts_flushed = parse(s,"pd");
211 unsigned long long dup_puts_replaced = parse(s,"pr");
212 unsigned long long found_gets = parse(s,"gs");
213 unsigned long long gets = parse(s,"gt");
214 unsigned long long flushs_found = parse(s,"fs");
215 unsigned long long flushs = parse(s,"ft");
216 unsigned long long flush_objs_found = parse(s,"os");
217 unsigned long long flush_objs = parse(s,"ot");
219 parse_string(s,"PT",pool_type,2);
220 if (pool_type[1] == 'S')
221 return; /* no need to repeat print data for shared pools */
222 printf("domid%lu,id%lu[%s]:pgp=%llu(max=%llu) obj=%llu(%llu) "
223 "objnode=%llu(%llu) puts=%llu/%llu/%llu(dup=%llu/%llu) "
224 "gets=%llu/%llu(%llu%%) "
225 "flush=%llu/%llu flobj=%llu/%llu\n",
226 cli_id, pool_id, pool_type,
227 pgp_count, max_pgp_count, obj_count, max_obj_count,
228 objnode_count, max_objnode_count,
229 good_puts, puts, no_mem_puts,
230 dup_puts_flushed, dup_puts_replaced,
231 found_gets, gets,
232 gets ? (found_gets*100LL)/gets : 0,
233 flushs_found, flushs, flush_objs_found, flush_objs);
235 }
237 void parse_shared_pool(char *s)
238 {
239 char pool_type[3];
240 char buf[BUFSIZE];
241 unsigned long pool_id = parse(s,"PI");
242 unsigned long long uid0 = parse_hex(s,"U0");
243 unsigned long long uid1 = parse_hex(s,"U1");
244 unsigned long long pgp_count = parse(s,"Pc");
245 unsigned long long max_pgp_count = parse(s,"Pm");
246 unsigned long long obj_count = parse(s,"Oc");
247 unsigned long long max_obj_count = parse(s,"Om");
248 unsigned long long objnode_count = parse(s,"Nc");
249 unsigned long long max_objnode_count = parse(s,"Nm");
250 unsigned long long good_puts = parse(s,"ps");
251 unsigned long long puts = parse(s,"pt");
252 unsigned long long no_mem_puts = parse(s,"px");
253 unsigned long long dup_puts_flushed = parse(s,"pd");
254 unsigned long long dup_puts_replaced = parse(s,"pr");
255 unsigned long long found_gets = parse(s,"gs");
256 unsigned long long gets = parse(s,"gt");
257 unsigned long long flushs_found = parse(s,"fs");
258 unsigned long long flushs = parse(s,"ft");
259 unsigned long long flush_objs_found = parse(s,"os");
260 unsigned long long flush_objs = parse(s,"ot");
262 parse_string(s,"PT",pool_type,2);
263 parse_sharers(s,"SC",buf,BUFSIZE);
264 printf("poolid=%lu[%s] uuid=%llx.%llx, shared-by:%s: "
265 "pgp=%llu(max=%llu) obj=%llu(%llu) "
266 "objnode=%llu(%llu) puts=%llu/%llu/%llu(dup=%llu/%llu) "
267 "gets=%llu/%llu(%llu%%) "
268 "flush=%llu/%llu flobj=%llu/%llu\n",
269 pool_id, pool_type, uid0, uid1, buf,
270 pgp_count, max_pgp_count, obj_count, max_obj_count,
271 objnode_count, max_objnode_count,
272 good_puts, puts, no_mem_puts,
273 dup_puts_flushed, dup_puts_replaced,
274 found_gets, gets,
275 gets ? (found_gets*100LL)/gets : 0,
276 flushs_found, flushs, flush_objs_found, flush_objs);
277 }
279 int main(int ac, char **av)
280 {
281 char *p, c;
282 char buf[BUFSIZE];
284 while ( (p = fgets(buf,BUFSIZE,stdin)) != NULL )
285 {
286 c = *p++;
287 if ( *p++ != '=' )
288 continue;
289 switch ( c )
290 {
291 case 'G':
292 parse_global(p);
293 break;
294 case 'T':
295 parse_time_stats(p);
296 break;
297 case 'C':
298 parse_client(p);
299 break;
300 case 'P':
301 parse_pool(p);
302 break;
303 case 'S':
304 parse_shared_pool(p);
305 break;
306 default:
307 continue;
308 }
309 }
310 return 0;
311 }