aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_cpustatus.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-05-17 15:50:00 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-05-17 15:50:00 +0000
commita3b91939536499844d78cc357332e144b831f39a (patch)
treed8a5292c50208169a5a5c08d10142ea67634840a /src/testbed/gnunet-service-testbed_cpustatus.c
parenta0f79a7add4699aee795549de95c1178efa2d360 (diff)
downloadgnunet-a3b91939536499844d78cc357332e144b831f39a.tar.gz
gnunet-a3b91939536499844d78cc357332e144b831f39a.zip
- include logging of memory statistics on Linux
Diffstat (limited to 'src/testbed/gnunet-service-testbed_cpustatus.c')
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c
index cb23800f4..5ae912923 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -30,6 +30,7 @@
30 30
31#include "platform.h" 31#include "platform.h"
32#include "gnunet_util_lib.h" 32#include "gnunet_util_lib.h"
33#include "gnunet-service-testbed_meminfo.h"
33 34
34#if SOLARIS 35#if SOLARIS
35#if HAVE_KSTAT_H 36#if HAVE_KSTAT_H
@@ -120,7 +121,7 @@ initMachCpuStats ()
120#endif 121#endif
121 122
122/** 123/**
123 * Update the currentCPU and currentIO load values. 124 * Update the currentCPU and currentIO load (and on Linux, memory) values.
124 * 125 *
125 * Before its first invocation the method initStatusCalls() must be called. 126 * Before its first invocation the method initStatusCalls() must be called.
126 * If there is an error the method returns -1. 127 * If there is an error the method returns -1.
@@ -596,6 +597,21 @@ disk_get_load ()
596 return (int) agedIOLoad; 597 return (int) agedIOLoad;
597} 598}
598 599
600/**
601 * Get the percentage of memory used
602 *
603 * @return the percentage of memory used
604 */
605static unsigned int
606mem_get_usage ()
607{
608 unsigned long currentMemUsage;
609
610 meminfo ();
611 currentMemUsage = kb_main_total - kb_main_free;
612 return (unsigned int) ((currentMemUsage / kb_main_total) * 100);
613}
614
599 615
600static void 616static void
601sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 617sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -605,6 +621,7 @@ sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
605 int nbs; 621 int nbs;
606 int ld_cpu; 622 int ld_cpu;
607 int ld_disk; 623 int ld_disk;
624 unsigned int mem_usage;
608 625
609 sample_load_task_id = GNUNET_SCHEDULER_NO_TASK; 626 sample_load_task_id = GNUNET_SCHEDULER_NO_TASK;
610 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 627 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
@@ -613,9 +630,10 @@ sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
613 ld_disk = disk_get_load (); 630 ld_disk = disk_get_load ();
614 if ( (-1 == ld_cpu) || (-1 == ld_disk) ) 631 if ( (-1 == ld_cpu) || (-1 == ld_disk) )
615 goto reschedule; 632 goto reschedule;
633 mem_usage = mem_get_usage ();
616 now = GNUNET_TIME_absolute_get (); 634 now = GNUNET_TIME_absolute_get ();
617 nbs = GNUNET_asprintf (&str, "%llu %d %d\n", now.abs_value / 1000, 635 nbs = GNUNET_asprintf (&str, "%llu %d %d %u\n", now.abs_value / 1000,
618 ld_cpu, ld_disk); 636 ld_cpu, ld_disk, mem_usage);
619 if (0 < nbs) 637 if (0 < nbs)
620 { 638 {
621 GNUNET_BIO_write (bw, str, nbs); 639 GNUNET_BIO_write (bw, str, nbs);