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