debuggers.hg

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