Browse code

core rpc: core.shmmem can take an optional size parameter

core.shmmem can take now an optional size parameter, which can
have one of the following values: b - bytes, k or kb - kilobytes,
m or mb - megabytes, g or gb - gigabytes. By default (no
parameter) the values displayed are in bytes. Note that when using
something different from bytes the value are truncated (no
floating point).
The new parameter can be used as workaround on 64 bits systems
when sr is started with more then 2Gb of memory (due to the RPC
interface limitation to int32 in this case the values displayed
would be negative or 0).
E.g:
sercmd> core.shmmem k

Andrei Pelinescu-Onciul authored on 12/11/2009 16:24:27
Showing 1 changed files
... ...
@@ -435,21 +435,54 @@ static void core_shmmem(rpc_t* rpc, void* c)
435 435
 {
436 436
 	struct mem_info mi;
437 437
 	void *handle;
438
-
438
+	char* param;
439
+	long rs;
440
+
441
+	rs=0;
442
+	/* look for optional size/divisor parameter */
443
+	if (rpc->scan(c, "*s", &param)>0){
444
+		switch(*param){
445
+			case 'b':
446
+			case 'B':
447
+				rs=0;
448
+				break;
449
+			case 'k':
450
+			case 'K':
451
+				rs=10; /* K -> 1024 */
452
+				break;
453
+			case 'm':
454
+			case 'M':
455
+				rs=20; /* M -> 1048576 */
456
+				break;
457
+			case 'g':
458
+			case 'G':
459
+				rs=30; /* G -> 1024M */
460
+				break;
461
+			default:
462
+				rpc->fault(c, 500, "bad param, (use b|k|m|g)");
463
+				return;
464
+		}
465
+		if (param[1] && ((param[1]!='b' && param[1]!='B') || param[2])){
466
+				rpc->fault(c, 500, "bad param, (use b|k|m|g)");
467
+				return;
468
+		}
469
+	}
439 470
 	shm_info(&mi);
440 471
 	rpc->add(c, "{", &handle);
441 472
 	rpc->struct_add(handle, "dddddd",
442
-		"total", (unsigned int)mi.total_size,
443
-		"free", (unsigned int)mi.free,
444
-		"used", (unsigned int)mi.used,
445
-		"real_used",(unsigned int)mi.real_used,
446
-		"max_used", (unsigned int)mi.max_used,
473
+		"total", (unsigned int)(mi.total_size>>rs),
474
+		"free", (unsigned int)(mi.free>>rs),
475
+		"used", (unsigned int)(mi.used>>rs),
476
+		"real_used",(unsigned int)(mi.real_used>>rs),
477
+		"max_used", (unsigned int)(mi.max_used>>rs),
447 478
 		"fragments", (unsigned int)mi.total_frags
448 479
 	);
449 480
 }
450 481
 
451 482
 static const char* core_shmmem_doc[] = {
452
-	"Returns shared memory info.",  /* Documentation string */
483
+	"Returns shared memory info. It has an optional parameter that specifies"
484
+	" the measuring unit: b - bytes (default), k or kb, m or mb, g or gb. "
485
+	"Note: when using something different from bytes, the value is truncated.",
453 486
 	0                               /* Method signature(s) */
454 487
 };
455 488