gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r27288 - gnunet/src/testbed


From: gnunet
Subject: [GNUnet-SVN] r27288 - gnunet/src/testbed
Date: Fri, 24 May 2013 14:15:40 +0200

Author: harsha
Date: 2013-05-24 14:15:40 +0200 (Fri, 24 May 2013)
New Revision: 27288

Modified:
   gnunet/src/testbed/gnunet-service-testbed_cpustatus.c
Log:
- log number of processes in the system


Modified: gnunet/src/testbed/gnunet-service-testbed_cpustatus.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed_cpustatus.c       2013-05-24 
12:15:16 UTC (rev 27287)
+++ gnunet/src/testbed/gnunet-service-testbed_cpustatus.c       2013-05-24 
12:15:40 UTC (rev 27288)
@@ -613,6 +613,35 @@
 }
 
 
+#ifdef LINUX
+#include <dirent.h>
+/**
+ * Returns the number of processes
+ *
+ * @return the number of processes
+ */
+static unsigned int
+get_nproc ()
+{
+  DIR *dir;
+  struct dirent *ent;
+  unsigned int nproc;
+
+  dir = opendir ("/proc");
+  if (NULL == dir)
+    return 0;
+  nproc = 0;
+  while (NULL != (ent = readdir (dir)))
+  {
+    if((*ent->d_name > '0') && (*ent->d_name <= '9')) 
+      nproc++;
+  }
+  closedir (dir);
+  return nproc;
+}
+#endif
+
+
 static void
 sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -622,6 +651,7 @@
   int ld_cpu;
   int ld_disk;
   unsigned int mem_usage;
+  unsigned int nproc;
 
   sample_load_task_id = GNUNET_SCHEDULER_NO_TASK;
   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
@@ -631,9 +661,14 @@
   if ( (-1 == ld_cpu) || (-1 == ld_disk) )
     goto reschedule;
   mem_usage = mem_get_usage ();
+#ifdef LINUX
+  nproc = get_nproc ();
+#else
+  nproc = 0;
+#endif
   now = GNUNET_TIME_absolute_get ();
-  nbs = GNUNET_asprintf (&str, "%llu %d %d %u\n", now.abs_value / 1000,
-                         ld_cpu, ld_disk, mem_usage);
+  nbs = GNUNET_asprintf (&str, "%llu %d %d %u %u\n", now.abs_value / 1000,
+                         ld_cpu, ld_disk, mem_usage, nproc);
   if (0 < nbs) 
   {
     GNUNET_BIO_write (bw, str, nbs);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]