[sr-dev] git:kamailio_3.0: core rpc: core.shmmem can take an optional size parameter

Daniel-Constantin Mierla miconda at gmail.com
Mon Nov 16 08:39:05 CET 2009


Module: sip-router
Branch: kamailio_3.0
Commit: 306ef4698b53fcb616ef53baa7dead895771e46d
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=306ef4698b53fcb616ef53baa7dead895771e46d

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Nov 12 17:24:27 2009 +0100

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
(cherry picked from commit 02eec212e4eaf999de4162287232c172760ca9d4)

---

 core_cmd.c |   47 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/core_cmd.c b/core_cmd.c
index bc2bd13..ca06bf4 100644
--- a/core_cmd.c
+++ b/core_cmd.c
@@ -435,21 +435,54 @@ static void core_shmmem(rpc_t* rpc, void* c)
 {
 	struct mem_info mi;
 	void *handle;
-
+	char* param;
+	long rs;
+
+	rs=0;
+	/* look for optional size/divisor parameter */
+	if (rpc->scan(c, "*s", &param)>0){
+		switch(*param){
+			case 'b':
+			case 'B':
+				rs=0;
+				break;
+			case 'k':
+			case 'K':
+				rs=10; /* K -> 1024 */
+				break;
+			case 'm':
+			case 'M':
+				rs=20; /* M -> 1048576 */
+				break;
+			case 'g':
+			case 'G':
+				rs=30; /* G -> 1024M */
+				break;
+			default:
+				rpc->fault(c, 500, "bad param, (use b|k|m|g)");
+				return;
+		}
+		if (param[1] && ((param[1]!='b' && param[1]!='B') || param[2])){
+				rpc->fault(c, 500, "bad param, (use b|k|m|g)");
+				return;
+		}
+	}
 	shm_info(&mi);
 	rpc->add(c, "{", &handle);
 	rpc->struct_add(handle, "dddddd",
-		"total", (unsigned int)mi.total_size,
-		"free", (unsigned int)mi.free,
-		"used", (unsigned int)mi.used,
-		"real_used",(unsigned int)mi.real_used,
-		"max_used", (unsigned int)mi.max_used,
+		"total", (unsigned int)(mi.total_size>>rs),
+		"free", (unsigned int)(mi.free>>rs),
+		"used", (unsigned int)(mi.used>>rs),
+		"real_used",(unsigned int)(mi.real_used>>rs),
+		"max_used", (unsigned int)(mi.max_used>>rs),
 		"fragments", (unsigned int)mi.total_frags
 	);
 }
 
 static const char* core_shmmem_doc[] = {
-	"Returns shared memory info.",  /* Documentation string */
+	"Returns shared memory info. It has an optional parameter that specifies"
+	" the measuring unit: b - bytes (default), k or kb, m or mb, g or gb. "
+	"Note: when using something different from bytes, the value is truncated.",
 	0                               /* Method signature(s) */
 };
 




More information about the sr-dev mailing list