Browse code

corex: rpc command shm.stats

- convenience function to be coherent with pkg variants

Daniel-Constantin Mierla authored on 18/09/2020 11:16:39
Showing 1 changed files
... ...
@@ -54,8 +54,34 @@ static void corex_rpc_shm_info(rpc_t* rpc, void* ctx)
54 54
 	}
55 55
 }
56 56
 
57
+static const char* corex_rpc_shm_stats_doc[2] = {
58
+	"Return shared memory stats",
59
+	0
60
+};
61
+
62
+/*
63
+ * RPC command to return shm stats
64
+ */
65
+static void corex_rpc_shm_stats(rpc_t* rpc, void* c)
66
+{
67
+	struct mem_info mi;
68
+	void *th;
69
+
70
+	shm_info(&mi);
71
+	rpc->add(c, "{", &th);
72
+	rpc->struct_add(th, "uuuuuu",
73
+			"total", (unsigned int)(mi.total_size),
74
+			"free", (unsigned int)(mi.free),
75
+			"used", (unsigned int)(mi.used),
76
+			"real_used",(unsigned int)(mi.real_used),
77
+			"max_used", (unsigned int)(mi.max_used),
78
+			"fragments", (unsigned int)mi.total_frags
79
+		);
80
+}
81
+
57 82
 rpc_export_t corex_rpc_shm_cmds[] = {
58
-	{"shm.info", corex_rpc_shm_info, corex_rpc_shm_info_doc, 0},
83
+	{"shm.info",  corex_rpc_shm_info,  corex_rpc_shm_info_doc,  0},
84
+	{"shm.stats", corex_rpc_shm_stats, corex_rpc_shm_stats_doc, 0},
59 85
 	{0, 0, 0, 0}
60 86
 };
61 87