print_stats.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. #include <dmmlib/print_stats.h>
  18. #include "dmm_config.h"
  19. #include <stdio.h>
  20. size_t get_allocated_space(heap_t *heap) {
  21. return heap->dmm_stats.mem_allocated;
  22. }
  23. size_t get_used_space(heap_t *heap) {
  24. return heap->dmm_stats.mem_used;
  25. }
  26. #ifdef REQUEST_SIZE_INFO
  27. size_t get_requested_space(heap_t *heap) {
  28. return heap->dmm_stats.mem_requested;
  29. }
  30. #endif /* REQUEST_SIZE_INFO */
  31. void print_stats(allocator_t *allocator) {
  32. int i;
  33. for(i = 0; i < NUM_HEAPS; i++) {
  34. printf("dmmlib - Heap %d statistics:\n", i);
  35. printf("dmmlib - Total malloc() calls: %d\n",
  36. (int) allocator->heaps[i].dmm_stats.num_malloc);
  37. printf("dmmlib - Total free() calls: %d\n",
  38. (int) allocator->heaps[i].dmm_stats.num_free);
  39. #ifdef REQUEST_SIZE_INFO
  40. printf("dmmlib - Memory currently requested: %zu\n",
  41. get_requested_space(&allocator->heaps[i]));
  42. #endif /* REQUEST_SIZE_INFO */
  43. printf("dmmlib - Memory currently used: %zu\n",
  44. get_used_space(&allocator->heaps[i]));
  45. printf("dmmlib - Memory currently allocated: %zu\n",
  46. get_allocated_space(&allocator->heaps[i]));
  47. }
  48. }