[ 
https://issues.apache.org/jira/browse/DISPATCH-1415?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17036276#comment-17036276
 ] 

ASF GitHub Bot commented on DISPATCH-1415:
------------------------------------------

kgiusti commented on 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]


> qdstat does not show process memory usage
> -----------------------------------------
>
>                 Key: DISPATCH-1415
>                 URL: https://issues.apache.org/jira/browse/DISPATCH-1415
>             Project: Qpid Dispatch
>          Issue Type: Improvement
>          Components: Management Agent
>    Affects Versions: 1.8.0
>            Reporter: Charles E. Rolke
>            Assignee: Ken Giusti
>            Priority: Major
>              Labels: troubleshooting
>
> *qdstat -m* shows managed memory usage but it does not show qdrouterd process 
> memory usage. An improvement would be to display process memory usage 
> somewhere via qdstat.
> Often a memory leak (DISPATCH-1407) will be in objects not held in managed 
> memory. In these cases memory usage may grow unbounded but not be visible by 
> qdstat.
> A new line or three could be added to qdstat -g or a new switch could be 
> added to qdstat. Good values to show are the standard columns from top: VIRT, 
> RES, and SHR.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to