statistics.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 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. /**
  18. * @file statistics.c
  19. * @author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * @date September 2012
  21. * @brief Statistics function implementation.
  22. */
  23. #include "statistics.h"
  24. #include "dmmlib/dmmlib.h"
  25. #include "trace.h"
  26. /** Updates a dmmstats_t variable
  27. *
  28. * @param dmm_stats Pointer to the dmmstats_t variable.
  29. * @param event The event type, could be MALLOC or FREE.
  30. * */
  31. #ifdef REQUEST_SIZE_INFO
  32. /**
  33. * @param mem_req Requested memory size info.
  34. */
  35. #endif /* REQUEST_SIZE_INFO */
  36. void update_stats
  37. ( dmmstats_t *dmm_stats
  38. , dmm_event_type event
  39. #ifdef REQUEST_SIZE_INFO
  40. , size_t mem_req
  41. #endif /* REQUEST_SIZE_INFO */
  42. )
  43. {
  44. if(event == MALLOC) {
  45. #ifdef REQUEST_SIZE_INFO
  46. dmm_stats->total_mem_requested += mem_req;
  47. #endif /* REQUEST_SIZE_INFO */
  48. dmm_stats->live_objects++;
  49. dmm_stats->num_malloc++;
  50. }
  51. if(event == FREE) {
  52. #ifdef REQUEST_SIZE_INFO
  53. dmm_stats->total_mem_requested -= mem_req;
  54. #endif /* REQUEST_SIZE_INFO */
  55. dmm_stats->live_objects--;
  56. dmm_stats->num_free++;
  57. }
  58. #if defined PARSE_ENV && defined WITH_STATS_TRACE
  59. if(__builtin_expect (systemallocator.initialized, true)) {
  60. #endif /* PARSE_ENV && WITH_STATS_TRACE */
  61. STATS_TRACE("dmmlib - ms all %zu\n", dmm_stats->total_mem_allocated);
  62. #ifdef REQUEST_SIZE_INFO
  63. STATS_TRACE("dmmlib - ms req %zu\n", dmm_stats->total_mem_requested);
  64. #endif /* REQUEST_SIZE_INFO */
  65. #if defined PARSE_ENV && defined WITH_STATS_TRACE
  66. }
  67. #endif /* PARSE_ENV && WITH_STATS_TRACE */
  68. }
  69. #ifdef REQUEST_SIZE_INFO
  70. /** Returns the total memory that is currently requested */
  71. size_t get_total_requested_memory(void) {
  72. return systemallocator.dmm_stats.total_mem_requested;
  73. }
  74. #endif /* REQUEST_SIZE_INFO */
  75. /** Returns the total memory that is currently allocated */
  76. size_t get_total_allocated_memory(void) {
  77. return systemallocator.dmm_stats.total_mem_allocated;
  78. }