Browse code

- more mem info: used and real_used (real_used includes the malloc overheads) - extensive debuggin command for sf_malloc and ll_malloc: core.sfmalloc (enabled only if ser compiled with -DLL_MALLOC or -DSF_MALLOC).

Andrei Pelinescu-Onciul authored on 12/06/2007 18:21:42
Showing 1 changed files
... ...
@@ -288,10 +288,11 @@ static void core_shmmem(rpc_t* rpc, void* c)
288 288
 
289 289
 	shm_info(&mi);
290 290
 	rpc->add(c, "{", &handle);
291
-	rpc->struct_add(handle, "ddddd",
291
+	rpc->struct_add(handle, "dddddd",
292 292
 		"total", (unsigned int)mi.total_size,
293 293
 		"free", (unsigned int)mi.free,
294
-		"used", (unsigned int)mi.real_used,
294
+		"used", (unsigned int)mi.used,
295
+		"real_used",(unsigned int)mi.real_used,
295 296
 		"max_used", (unsigned int)mi.max_used,
296 297
 		"fragments", (unsigned int)mi.total_frags
297 298
 	);
... ...
@@ -303,6 +304,121 @@ static const char* core_shmmem_doc[] = {
303 304
 };
304 305
 
305 306
 
307
+#if defined(SF_MALLOC) || defined(LL_MALLOC)
308
+static void core_sfmalloc(rpc_t* rpc, void* c)
309
+{
310
+	void *handle;
311
+	int i,r;
312
+	unsigned long frags, main_s_frags, main_b_frags, pool_frags;
313
+	unsigned long misses;
314
+	unsigned long max_misses;
315
+	unsigned long max_frags;
316
+	unsigned long max_mem;
317
+	int max_frags_pool, max_frags_hash;
318
+	int max_misses_pool, max_misses_hash;
319
+	int max_mem_pool, max_mem_hash;
320
+	unsigned long mem;
321
+
322
+	if (rpc->scan(c, "d", &r) >= 1) {
323
+		if (r>=(int)SF_HASH_POOL_SIZE){
324
+			rpc->fault(c, 500, "invalid hash number %d (max %d)",
325
+								r, (unsigned int)SF_HASH_POOL_SIZE-1);
326
+			return;
327
+		}else if (r<0) goto all;
328
+		rpc->add(c, "{", &handle);
329
+		rpc->struct_add(handle, "dd",
330
+				"hash  ", r,
331
+				"size  ", r*SF_ROUNDTO);
332
+		for (i=0; i<SFM_POOLS_NO; i++){
333
+			rpc->struct_add(handle, "dddd",
334
+				"pool  ", i,
335
+				"frags ", (unsigned int)shm_block->pool[i].pool_hash[r].no,
336
+				"misses", (unsigned int)shm_block->pool[i].pool_hash[r].misses,
337
+				"mem   ",   (unsigned int)shm_block->pool[i].pool_hash[r].no *
338
+							r*SF_ROUNDTO
339
+			);
340
+		}
341
+	}
342
+	return;
343
+all:
344
+	max_frags=max_misses=max_mem=0;
345
+	max_frags_pool=max_frags_hash=0;
346
+	max_misses_pool=max_misses_hash=0;
347
+	max_mem_pool=max_mem_hash=0;
348
+	pool_frags=0;
349
+	for (i=0; i<SFM_POOLS_NO; i++){
350
+		frags=0;
351
+		misses=0;
352
+		mem=0;
353
+		for (r=0; r<SF_HASH_POOL_SIZE; r++){
354
+			frags+=shm_block->pool[i].pool_hash[r].no;
355
+			misses+=shm_block->pool[i].pool_hash[r].misses;
356
+			mem+=shm_block->pool[i].pool_hash[r].no*r*SF_ROUNDTO;
357
+			if (shm_block->pool[i].pool_hash[r].no>max_frags){
358
+				max_frags=shm_block->pool[i].pool_hash[r].no;
359
+				max_frags_pool=i;
360
+				max_frags_hash=r;
361
+			}
362
+			if (shm_block->pool[i].pool_hash[r].misses>max_misses){
363
+				max_misses=shm_block->pool[i].pool_hash[r].misses;
364
+				max_misses_pool=i;
365
+				max_misses_hash=r;
366
+			}
367
+			if (shm_block->pool[i].pool_hash[r].no*r*SF_ROUNDTO>max_mem){
368
+				max_mem=shm_block->pool[i].pool_hash[r].no*r*SF_ROUNDTO;
369
+				max_mem_pool=i;
370
+				max_mem_hash=r;
371
+			}
372
+		}
373
+		rpc->add(c, "{", &handle);
374
+		rpc->struct_add(handle, "ddddddd",
375
+			"pool  ", i,
376
+			"frags ", (unsigned int)frags,
377
+			"t. misses", (unsigned int)misses,
378
+			"mem   ", (unsigned int)mem,
379
+			"bitmap", (unsigned int)shm_block->pool[i].bitmap,
380
+			"missed", (unsigned int)shm_block->pool[i].missed,
381
+			"hits",   (unsigned int)shm_block->pool[i].hits
382
+		);
383
+		pool_frags+=frags;
384
+	}
385
+	main_s_frags=0;
386
+	for (r=0; r<SF_HASH_POOL_SIZE; r++){
387
+		main_s_frags+=shm_block->free_hash[r].no;
388
+	}
389
+	main_b_frags=0;
390
+	for (; r<SF_HASH_SIZE; r++){
391
+		main_b_frags+=shm_block->free_hash[r].no;
392
+	}
393
+	rpc->add(c, "{", &handle);
394
+	rpc->struct_add(handle, "dddddddddddddd",
395
+		"max_frags      ", (unsigned int)max_frags,
396
+		"max_frags_pool ", max_frags_pool,
397
+		"max_frags_hash", max_frags_hash,
398
+		"max_misses     ", (unsigned int)max_misses,
399
+		"max_misses_pool", max_misses_pool,
400
+		"max_misses_hash", max_misses_hash,
401
+		"max_mem        ", (unsigned int)max_mem,
402
+		"max_mem_pool   ", max_mem_pool,
403
+		"max_mem_hash   ", max_mem_hash,
404
+		"in_pools_frags ", (unsigned int)pool_frags,
405
+		"main_s_frags   ", (unsigned int)main_s_frags,
406
+		"main_b_frags   ", (unsigned int)main_b_frags,
407
+		"main_frags     ", (unsigned int)(main_b_frags+main_s_frags),
408
+		"main_bitmap    ", (unsigned int)shm_block->bitmap
409
+	);
410
+}
411
+
412
+
413
+
414
+static const char* core_sfmalloc_doc[] = {
415
+	"Returns sfmalloc debugging  info.",  /* Documentation string */
416
+	0                                     /* Method signature(s) */
417
+};
418
+#endif
419
+
420
+
421
+
306 422
 static const char* core_tcpinfo_doc[] = {
307 423
 	"Returns tcp related info.",    /* Documentation string */
308 424
 	0                               /* Method signature(s) */
... ...
@@ -345,6 +461,9 @@ rpc_export_t core_rpc_methods[] = {
345 461
 	{"core.arg",               core_arg,               core_arg_doc,               RET_ARRAY},
346 462
 	{"core.kill",              core_kill,              core_kill_doc,              0        },
347 463
 	{"core.shmmem",            core_shmmem,            core_shmmem_doc,            0	},
464
+#if defined(SF_MALLOC) || defined(LL_MALLOC)
465
+	{"core.sfmalloc",          core_sfmalloc,          core_sfmalloc_doc,   0},
466
+#endif
348 467
 	{"core.tcp_info",          core_tcpinfo,           core_tcpinfo_doc,          0	},
349 468
 #ifdef USE_DNS_CACHE
350 469
 	{"dns.mem_info",          dns_cache_mem_info,     dns_cache_mem_info_doc,     0	},