diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-10-07 19:02:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-10-07 19:02:58 +0000 |
commit | 76cc98f7b32077470b413b6efce1b219906bf758 (patch) | |
tree | 206fb833e5dc4506f6d446ec3f946484469c8406 /src/statistics | |
parent | a60b958f984d08525b636a2c7eae564ebec54ae6 (diff) | |
download | gnunet-76cc98f7b32077470b413b6efce1b219906bf758.tar.gz gnunet-76cc98f7b32077470b413b6efce1b219906bf758.zip |
-add logic to measure heap size for all processes that use statistics, reduce statistics, topology, nse and resolver heap usage using the same trick we used for arm
Diffstat (limited to 'src/statistics')
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 15 | ||||
-rw-r--r-- | src/statistics/statistics_api.c | 54 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index efd834624..beb3d5135 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -849,4 +849,19 @@ main (int argc, char *const *argv) | |||
849 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, NULL)) ? 0 : 1; | 849 | GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, &run, NULL)) ? 0 : 1; |
850 | } | 850 | } |
851 | 851 | ||
852 | #ifdef LINUX | ||
853 | #include <malloc.h> | ||
854 | |||
855 | /** | ||
856 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | ||
857 | */ | ||
858 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () | ||
859 | { | ||
860 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | ||
861 | mallopt (M_TOP_PAD, 1 * 1024); | ||
862 | malloc_trim (0); | ||
863 | } | ||
864 | #endif | ||
865 | |||
866 | |||
852 | /* end of gnunet-service-statistics.c */ | 867 | /* end of gnunet-service-statistics.c */ |
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index e1b3698e6..79d9604c7 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c | |||
@@ -236,6 +236,16 @@ struct GNUNET_STATISTICS_Handle | |||
236 | struct GNUNET_TIME_Relative backoff; | 236 | struct GNUNET_TIME_Relative backoff; |
237 | 237 | ||
238 | /** | 238 | /** |
239 | * Maximum heap size observed so far (if available). | ||
240 | */ | ||
241 | uint64_t peak_heap_size; | ||
242 | |||
243 | /** | ||
244 | * Maximum resident set side observed so far (if available). | ||
245 | */ | ||
246 | uint64_t peak_rss; | ||
247 | |||
248 | /** | ||
239 | * Size of the 'watches' array. | 249 | * Size of the 'watches' array. |
240 | */ | 250 | */ |
241 | unsigned int watches_size; | 251 | unsigned int watches_size; |
@@ -255,6 +265,49 @@ struct GNUNET_STATISTICS_Handle | |||
255 | 265 | ||
256 | 266 | ||
257 | /** | 267 | /** |
268 | * Obtain statistics about this process's memory consumption and | ||
269 | * report those as well (if they changed). | ||
270 | */ | ||
271 | static void | ||
272 | update_memory_statistics (struct GNUNET_STATISTICS_Handle *h) | ||
273 | { | ||
274 | uint64_t current_heap_size = 0; | ||
275 | uint64_t current_rss = 0; | ||
276 | |||
277 | if (GNUNET_NO != h->do_destroy) | ||
278 | return; | ||
279 | #if HAVE_MALLINFO | ||
280 | { | ||
281 | struct mallinfo mi; | ||
282 | |||
283 | mi = mallinfo(); | ||
284 | current_heap_size = mi.uordblks + mi.fordblks; | ||
285 | } | ||
286 | #endif | ||
287 | #if HAVE_GETRUSAGE | ||
288 | { | ||
289 | struct rusage ru; | ||
290 | |||
291 | if (0 == getrusage (RUSAGE_SELF, &ru)) | ||
292 | { | ||
293 | current_rss = 1024LL * ru.ru_maxrss; | ||
294 | } | ||
295 | } | ||
296 | #endif | ||
297 | if (current_heap_size > h->peak_heap_size) | ||
298 | { | ||
299 | h->peak_heap_size = current_heap_size; | ||
300 | GNUNET_STATISTICS_set (h, "# peak heap size", current_heap_size, GNUNET_NO); | ||
301 | } | ||
302 | if (current_rss > h->peak_rss) | ||
303 | { | ||
304 | h->peak_rss = current_rss; | ||
305 | GNUNET_STATISTICS_set (h, "# peak resident set size", current_rss, GNUNET_NO); | ||
306 | } | ||
307 | } | ||
308 | |||
309 | |||
310 | /** | ||
258 | * Schedule the next action to be performed. | 311 | * Schedule the next action to be performed. |
259 | * | 312 | * |
260 | * @param h statistics handle to reconnect | 313 | * @param h statistics handle to reconnect |
@@ -820,6 +873,7 @@ transmit_set (struct GNUNET_STATISTICS_Handle *handle, size_t size, void *buf) | |||
820 | GNUNET_assert (NULL == handle->current->cont); | 873 | GNUNET_assert (NULL == handle->current->cont); |
821 | free_action_item (handle->current); | 874 | free_action_item (handle->current); |
822 | handle->current = NULL; | 875 | handle->current = NULL; |
876 | update_memory_statistics (handle); | ||
823 | return nsize; | 877 | return nsize; |
824 | } | 878 | } |
825 | 879 | ||