kgiusti commented on a change in pull request #680: DISPATCH-1415, 
DISPATCH-1569: add process memory metric
URL: https://github.com/apache/qpid-dispatch/pull/680#discussion_r378899864
 
 

 ##########
 File path: src/dispatch.c
 ##########
 @@ -379,3 +379,50 @@ void qd_dispatch_router_unlock(qd_dispatch_t *qd) { 
sys_mutex_unlock(qd->router-
 qdr_core_t* qd_dispatch_router_core(qd_dispatch_t *qd) {
     return qd->router->router_core;
 }
+
+
+/* qd_router_memory_usage
+ *
+ * Return the amount of memory currently provisioned by the qdrouterd process.
+ * This includes data, stack, and code memory.  On systems supporting virtual
+ * memory this value may be larger than the physical RAM available on the
+ * platform.
+ *
+ * Return 0 if the memory usage cannot be determined.
+ */
+uint64_t qd_router_memory_usage()
+{
+    // @TODO(kgiusti): only works for linux (what? doesn't everyone run linux?)
+
+    // parse the VmSize value out of the /proc/[pid]/status file
+    const pid_t my_pid = getpid();
+    const char *status_template = "/proc/%ld/status";
+    char status_path[64];
+    if (snprintf(status_path, 64, status_template, (long int)my_pid) >= 64) {
 
 Review comment:
   Not necessarily - safe_snprintf ensures the return value reflects the # of 
bytes written to the buffer.  Here we want to detect overflow so are relying on 
a return code that is >= the buffer size.  So here the use of snprintf is about 
as safe as it can be (esp given that any valid value for the pid won't overflow 
the buffer in the first place).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to