$OpenBSD: patch-base_process_process_metrics_openbsd_cc,v 1.8 2018/06/06 07:50:54 robert Exp $

Index: base/process/process_metrics_openbsd.cc
--- base/process/process_metrics_openbsd.cc.orig
+++ base/process/process_metrics_openbsd.cc
@@ -4,10 +4,21 @@
 
 #include "base/process/process_metrics.h"
 
+#include "base/files/file_util.h"
+#include "base/logging.h"
+#include "base/process/internal_linux.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_tokenizer.h"
+#include "base/strings/string_util.h"
+#include "base/sys_info.h"
+#include "base/threading/thread_restrictions.h"
+
 #include <stddef.h>
 #include <stdint.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
+#include <sys/vmmeter.h>
 
 #include "base/macros.h"
 #include "base/memory/ptr_util.h"
@@ -53,7 +64,6 @@ double ProcessMetrics::GetPlatformIndependentCPUUsage(
   }
 
   int64_t time_delta = (time - last_cpu_time_).InMicroseconds();
-  DCHECK_NE(time_delta, 0);
 
   if (time_delta == 0)
     return 0;
@@ -89,6 +99,70 @@ size_t GetSystemCommitCharge() {
   pagesize = getpagesize();
 
   return mem_total - (mem_free*pagesize) - (mem_inactive*pagesize);
+}
+
+int ProcessMetrics::GetOpenFdCount() const {
+  struct kinfo_proc *info;
+  size_t length;
+  int total_count = 0;
+
+  int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_,
+                sizeof(struct kinfo_proc), 0 };
+
+  if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0)
+    return -1;
+
+  info = (struct kinfo_proc *)malloc(length);
+
+  mib[5] = (length / sizeof(struct kinfo_proc));
+
+  if (sysctl(mib, arraysize(mib), info, &length, NULL, 0) < 0) {
+    total_count = -1;
+    goto out;
+  }
+  //total_count = info->p_fd->fd_openfd;
+  total_count = info->p_fd;
+
+out:
+  free(info);
+  return total_count;
+}
+
+int ProcessMetrics::GetOpenFdSoftLimit() const {
+  struct kinfo_proc *info;
+  size_t length;
+  int total_count = 0; 
+
+  int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process_,
+                sizeof(struct kinfo_proc), 0 };
+
+  if (sysctl(mib, arraysize(mib), NULL, &length, NULL, 0) < 0)
+    return -1;
+
+  info = (struct kinfo_proc *)malloc(length);
+
+  mib[5] = (length / sizeof(struct kinfo_proc));
+
+  if (sysctl(mib, arraysize(mib), info, &length, NULL, 0) < 0) {
+    total_count = -1;  
+    goto out;
+  }
+  //total_count = info->p_fd->fd_openfd;
+  total_count = info->p_limit;
+
+out:
+  free(info);
+  return total_count;  
+}
+
+uint64_t ProcessMetrics::GetVmSwapBytes() const {
+  NOTIMPLEMENTED();
+  return 0;
+}
+
+bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
+  NOTIMPLEMENTED();
+  return false;
 }
 
 }  // namespace base
