age = GNUNET_TIME_absolute_get_duration (lastCall);
if ( (agedCPULoad == -1)
- || (age.rel_value > 500) )
+ || (age.rel_value_us > 500000) )
{
/* use smoothing, but do NOT update lastRet at frequencies higher
than 500ms; this makes the smoothing (mostly) independent from
static unsigned int
mem_get_usage ()
{
- unsigned long currentMemUsage;
+ double percentage;
meminfo ();
- currentMemUsage = kb_main_total - kb_main_free;
- return (unsigned int) ((currentMemUsage / kb_main_total) * 100);
+ percentage = ( ((double) kb_main_used) / ((double) kb_main_total) * 100.0 );
+ return (unsigned int) percentage;
}
+#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)
{
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))
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_us / 1000LL / 1000LL,
+ ld_cpu, ld_disk, mem_usage, nproc);
if (0 < nbs)
{
GNUNET_BIO_write (bw, str, nbs);
- GNUNET_free (str);
}
else
GNUNET_break (0);
-
+ GNUNET_free (str);
+
reschedule:
sample_load_task_id =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,