Example #1
0
static void
interp_mem_get_stats (mem_heap_stats_t *out_heap_stats_p,
                      mem_pools_stats_t *out_pool_stats_p,
                      bool reset_peak_before,
                      bool reset_peak_after)
{
  if (likely (!interp_mem_stats_enabled))
  {
    return;
  }

  /* Requesting to free as much memory as we currently can */
  ecma_try_to_give_back_some_memory (MEM_TRY_GIVE_MEMORY_BACK_SEVERITY_CRITICAL);

  if (reset_peak_before)
  {
    mem_heap_stats_reset_peak ();
    mem_pools_stats_reset_peak ();
  }

  mem_heap_get_stats (out_heap_stats_p);
  mem_pools_get_stats (out_pool_stats_p);

  if (reset_peak_after)
  {
    mem_heap_stats_reset_peak ();
    mem_pools_stats_reset_peak ();
  }
}
Example #2
0
int
main (int __attr_unused___ argc,
      char __attr_unused___ **argv)
{
  TEST_INIT ();

  mem_init ();

  for (uint32_t i = 0; i < test_iters; i++)
  {
    const size_t subiters = ((size_t) rand () % test_max_sub_iters) + 1;

    for (size_t j = 0; j < subiters; j++)
    {
      ptrs[j] = mem_pools_alloc ();
      // JERRY_ASSERT (ptrs[j] != NULL);

      if (ptrs[j] != NULL)
      {
        memset (ptrs[j], 0, MEM_POOL_CHUNK_SIZE);
      }
    }

    // mem_heap_print (false);

    for (size_t j = 0; j < subiters; j++)
    {
      if (ptrs[j] != NULL)
      {
        for (size_t k = 0; k < MEM_POOL_CHUNK_SIZE; k++)
        {
          JERRY_ASSERT (((uint8_t*) ptrs[j])[k] == 0);
        }

        mem_pools_free (ptrs[j]);
      }
    }
  }

#ifdef MEM_STATS
  mem_pools_stats_t stats;
  mem_pools_get_stats (&stats);

  printf ("Pools stats:\n");
  printf (" Chunk size: %u\n"
          "  Pools: %lu\n"
          "  Allocated chunks: %lu\n"
          "  Free chunks: %lu\n"
          "  Peak pools: %lu\n"
          "  Peak allocated chunks: %lu\n\n",
          MEM_POOL_CHUNK_SIZE,
          stats.pools_count,
          stats.allocated_chunks,
          stats.free_chunks,
          stats.peak_pools_count,
          stats.peak_allocated_chunks);
#endif /* MEM_STATS */

  return 0;
} /* main */
Example #3
0
/**
 * Print memory usage statistics
 */
void
mem_stats_print (void)
{
  mem_heap_stats_print ();

  mem_pools_stats_t stats;
  mem_pools_get_stats (&stats);

  printf ("Pools stats:\n");
  printf ("  Chunk size: %zu\n"
          "  Pools: %zu\n"
          "  Allocated chunks: %zu\n"
          "  Free chunks: %zu\n"
          "  Peak pools: %zu\n"
          "  Peak allocated chunks: %zu\n\n",
          MEM_POOL_CHUNK_SIZE,
          stats.pools_count,
          stats.allocated_chunks,
          stats.free_chunks,
          stats.peak_pools_count,
          stats.peak_allocated_chunks);
} /* mem_stats_print */