diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-24 12:15:40 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-24 12:15:40 +0000 |
commit | e3fa646c6ee35efefafa9c19d1550530f46eb62d (patch) | |
tree | 35b657e1f2e8b39851713d376c1c2745ad5704c8 | |
parent | 5a65154a79a7b6a459a0ab1cfee3395ab61d12f0 (diff) | |
download | gnunet-e3fa646c6ee35efefafa9c19d1550530f46eb62d.tar.gz gnunet-e3fa646c6ee35efefafa9c19d1550530f46eb62d.zip |
- log number of processes in the system
-rw-r--r-- | src/testbed/gnunet-service-testbed_cpustatus.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c index 5ae912923..a7bd0c5a9 100644 --- a/src/testbed/gnunet-service-testbed_cpustatus.c +++ b/src/testbed/gnunet-service-testbed_cpustatus.c | |||
@@ -613,6 +613,35 @@ mem_get_usage () | |||
613 | } | 613 | } |
614 | 614 | ||
615 | 615 | ||
616 | #ifdef LINUX | ||
617 | #include <dirent.h> | ||
618 | /** | ||
619 | * Returns the number of processes | ||
620 | * | ||
621 | * @return the number of processes | ||
622 | */ | ||
623 | static unsigned int | ||
624 | get_nproc () | ||
625 | { | ||
626 | DIR *dir; | ||
627 | struct dirent *ent; | ||
628 | unsigned int nproc; | ||
629 | |||
630 | dir = opendir ("/proc"); | ||
631 | if (NULL == dir) | ||
632 | return 0; | ||
633 | nproc = 0; | ||
634 | while (NULL != (ent = readdir (dir))) | ||
635 | { | ||
636 | if((*ent->d_name > '0') && (*ent->d_name <= '9')) | ||
637 | nproc++; | ||
638 | } | ||
639 | closedir (dir); | ||
640 | return nproc; | ||
641 | } | ||
642 | #endif | ||
643 | |||
644 | |||
616 | static void | 645 | static void |
617 | sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 646 | sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
618 | { | 647 | { |
@@ -622,6 +651,7 @@ sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
622 | int ld_cpu; | 651 | int ld_cpu; |
623 | int ld_disk; | 652 | int ld_disk; |
624 | unsigned int mem_usage; | 653 | unsigned int mem_usage; |
654 | unsigned int nproc; | ||
625 | 655 | ||
626 | sample_load_task_id = GNUNET_SCHEDULER_NO_TASK; | 656 | sample_load_task_id = GNUNET_SCHEDULER_NO_TASK; |
627 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 657 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
@@ -631,9 +661,14 @@ sample_load_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
631 | if ( (-1 == ld_cpu) || (-1 == ld_disk) ) | 661 | if ( (-1 == ld_cpu) || (-1 == ld_disk) ) |
632 | goto reschedule; | 662 | goto reschedule; |
633 | mem_usage = mem_get_usage (); | 663 | mem_usage = mem_get_usage (); |
664 | #ifdef LINUX | ||
665 | nproc = get_nproc (); | ||
666 | #else | ||
667 | nproc = 0; | ||
668 | #endif | ||
634 | now = GNUNET_TIME_absolute_get (); | 669 | now = GNUNET_TIME_absolute_get (); |
635 | nbs = GNUNET_asprintf (&str, "%llu %d %d %u\n", now.abs_value / 1000, | 670 | nbs = GNUNET_asprintf (&str, "%llu %d %d %u %u\n", now.abs_value / 1000, |
636 | ld_cpu, ld_disk, mem_usage); | 671 | ld_cpu, ld_disk, mem_usage, nproc); |
637 | if (0 < nbs) | 672 | if (0 < nbs) |
638 | { | 673 | { |
639 | GNUNET_BIO_write (bw, str, nbs); | 674 | GNUNET_BIO_write (bw, str, nbs); |