You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/24 21:06:16 UTC

[GitHub] [arrow] westonpace commented on a change in pull request #12702: ARROW-15062: [C++] Add memory information to current spans

westonpace commented on a change in pull request #12702:
URL: https://github.com/apache/arrow/pull/12702#discussion_r834730496



##########
File path: cpp/src/arrow/util/tracing_internal.cc
##########
@@ -184,6 +188,41 @@ opentelemetry::trace::Tracer* GetTracer() {
   return tracer.get();
 }
 
+int parseLine(char* line){
+  // This assumes that a digit will be found and the line ends in " Kb".
+  int i = strlen(line);
+  const char* p = line;
+  while (*p <'0' || *p > '9') p++;
+  line[i-3] = '\0';
+  i = atoi(p);
+  return i;
+}
+
+size_t GetMemoryUsedByProcess() { //Note: this value is in KB!
+  FILE* file = fopen("/proc/self/status", "r");
+  size_t result = -1;
+  char line[128];
+
+  while (fgets(line, 128, file) != NULL){
+    if (strncmp(line, "VmRSS:", 6) == 0){
+      result = parseLine(line);
+      break;
+    }
+  }
+  fclose(file);
+  return result*1000;
+}
+
+size_t GetMemoryUsed() {
+  size_t total_memory_size;
+  size_t used_memory_size;
+  struct sysinfo si;
+  sysinfo(&si);

Review comment:
       There was a portable implementation as part of a PR here: https://github.com/apache/arrow/pull/11426/files#diff-5d7d9a549780da2ec4baba08a43db3e1d524b70d6e8ae4f29cc8bfe831357f9cR178-R199 
   
   We didn't end up pursuing the PR but you might be able to borrow some from that particular function.
   
   That being said, I wonder if it would be more valuable to report `default_memory_pool()->bytes_allocated()`.  `sysinfo` is going to give us statistics on the entire server and `freeram` is sometimes misleading (e.g. if there are a lot of dirty pages then `freeram` could be high while at the same time we might be thrashing swap).




-- 
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.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org