aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-service-arm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/gnunet-service-arm.c')
-rw-r--r--src/arm/gnunet-service-arm.c115
1 files changed, 110 insertions, 5 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index a411546d7..b8cda5945 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -29,6 +29,19 @@
29#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
30#include "arm.h" 30#include "arm.h"
31 31
32#if HAVE_WAIT4
33/**
34 * Name of the file for writing resource utilization summaries to.
35 */
36static char *wait_filename;
37
38/**
39 * Handle for the file for writing resource summaries.
40 */
41static FILE *wait_file;
42#endif
43
44
32/** 45/**
33 * How many messages do we queue up at most for optional 46 * How many messages do we queue up at most for optional
34 * notifications to a client? (this can cause notifications 47 * notifications to a client? (this can cause notifications
@@ -81,7 +94,7 @@ struct ServiceListeningInfo
81 /** 94 /**
82 * Task doing the accepting. 95 * Task doing the accepting.
83 */ 96 */
84 struct GNUNET_SCHEDULER_Task * accept_task; 97 struct GNUNET_SCHEDULER_Task *accept_task;
85 98
86}; 99};
87 100
@@ -1193,12 +1206,76 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1193 free_service (pos); 1206 free_service (pos);
1194 continue; 1207 continue;
1195 } 1208 }
1209#if HAVE_WAIT4
1210 if (NULL != wait_file)
1211 {
1212 /* need to use 'wait4()' to obtain and log performance data */
1213 struct rusage ru;
1214 int status;
1215 pid_t pid;
1216
1217 pid = GNUNET_OS_process_get_pid (pos->proc);
1218 ret = wait4 (pid,
1219 &status,
1220 WNOHANG,
1221 &ru);
1222 if (ret <= 0)
1223 continue; /* no process done */
1224 if (WIFEXITED (status))
1225 {
1226 statusType = GNUNET_OS_PROCESS_EXITED;
1227 statusCode = WEXITSTATUS (status);
1228 }
1229 else if (WIFSIGNALED (status))
1230 {
1231 statusType = GNUNET_OS_PROCESS_SIGNALED;
1232 statusCode = WTERMSIG (status);
1233 }
1234 else if (WIFSTOPPED (status))
1235 {
1236 statusType = GNUNET_OS_PROCESS_SIGNALED;
1237 statusCode = WSTOPSIG (status);
1238 }
1239#ifdef WIFCONTINUED
1240 else if (WIFCONTINUED (status))
1241 {
1242 statusType = GNUNET_OS_PROCESS_RUNNING;
1243 statusCode = 0;
1244 }
1245#endif
1246 else
1247 {
1248 statusType = GNUNET_OS_PROCESS_UNKNOWN;
1249 statusCode = 0;
1250 }
1251 if ( (GNUNET_OS_PROCESS_EXITED == statusType) ||
1252 (GNUNET_OS_PROCESS_SIGNALED == statusType) )
1253 {
1254 fprintf (wait_file,
1255 "%s(%u) %llu.%llu %llu.%llu %llu %llu %llu %llu %llu\n",
1256 pos->binary,
1257 (unsigned int) pid,
1258 (unsigned long long) ru.ru_utime.tv_sec,
1259 (unsigned long long) ru.ru_utime.tv_usec,
1260 (unsigned long long) ru.ru_stime.tv_sec,
1261 (unsigned long long) ru.ru_stime.tv_usec,
1262 (unsigned long long) ru.ru_maxrss,
1263 (unsigned long long) ru.ru_inblock,
1264 (unsigned long long) ru.ru_oublock,
1265 (unsigned long long) ru.ru_nvcsw,
1266 (unsigned long long) ru.ru_nivcsw);
1267 }
1268 }
1269 else /* continue with #else */
1270#else
1196 if ((GNUNET_SYSERR == 1271 if ((GNUNET_SYSERR ==
1197 (ret = 1272 (ret =
1198 GNUNET_OS_process_status (pos->proc, &statusType, &statusCode))) 1273 GNUNET_OS_process_status (pos->proc, &statusType, &statusCode))) ||
1199 || ((ret == GNUNET_NO) || (statusType == GNUNET_OS_PROCESS_STOPPED) 1274 ((ret == GNUNET_NO) ||
1200 || (statusType == GNUNET_OS_PROCESS_RUNNING))) 1275 (statusType == GNUNET_OS_PROCESS_STOPPED) ||
1276 (statusType == GNUNET_OS_PROCESS_RUNNING) ) )
1201 continue; 1277 continue;
1278#endif
1202 if (statusType == GNUNET_OS_PROCESS_EXITED) 1279 if (statusType == GNUNET_OS_PROCESS_EXITED)
1203 { 1280 {
1204 statstr = _( /* process termination method */ "exit"); 1281 statstr = _( /* process termination method */ "exit");
@@ -1501,7 +1578,23 @@ run (void *cls, struct GNUNET_SERVER_Handle *serv,
1501 GNUNET_DISK_pipe_handle (sigpipe, 1578 GNUNET_DISK_pipe_handle (sigpipe,
1502 GNUNET_DISK_PIPE_END_READ), 1579 GNUNET_DISK_PIPE_END_READ),
1503 &maint_child_death, NULL); 1580 &maint_child_death, NULL);
1504 1581#if HAVE_WAIT4
1582 if (GNUNET_OK ==
1583 GNUNET_CONFIGURATION_get_value_filename (cfg,
1584 "ARM",
1585 "RESOURCE_DIAGNOSTICS",
1586 &wait_filename))
1587 {
1588 wait_file = fopen (wait_filename,
1589 "w");
1590 if (NULL == wait_file)
1591 {
1592 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
1593 "fopen",
1594 wait_filename);
1595 }
1596 }
1597#endif
1505 if (GNUNET_OK != 1598 if (GNUNET_OK !=
1506 GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_PREFIX", 1599 GNUNET_CONFIGURATION_get_value_string (cfg, "ARM", "GLOBAL_PREFIX",
1507 &prefix_command)) 1600 &prefix_command))
@@ -1560,6 +1653,18 @@ main (int argc, char *const *argv)
1560 (GNUNET_OK == 1653 (GNUNET_OK ==
1561 GNUNET_SERVICE_run (argc, argv, "arm", 1654 GNUNET_SERVICE_run (argc, argv, "arm",
1562 GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, &run, NULL)) ? 0 : 1; 1655 GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, &run, NULL)) ? 0 : 1;
1656#if HAVE_WAIT4
1657 if (NULL != wait_file)
1658 {
1659 fclose (wait_file);
1660 wait_file = NULL;
1661 }
1662 if (NULL != wait_filename)
1663 {
1664 GNUNET_free (wait_filename);
1665 wait_filename = NULL;
1666 }
1667#endif
1563 GNUNET_SIGNAL_handler_uninstall (shc_chld); 1668 GNUNET_SIGNAL_handler_uninstall (shc_chld);
1564 shc_chld = NULL; 1669 shc_chld = NULL;
1565 GNUNET_DISK_pipe_close (sigpipe); 1670 GNUNET_DISK_pipe_close (sigpipe);