tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MozjemallocInfo.cpp (1823B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include <stdio.h>
      8 
      9 #include "mozmemory.h"
     10 
     11 /*
     12 * Print the configured size classes which we can then use to update
     13 * documentation.
     14 */
     15 int main() {
     16  jemalloc_stats_t stats;
     17 
     18  const size_t num_bins = jemalloc_stats_num_bins();
     19  const size_t MAX_NUM_BINS = 100;
     20  if (num_bins > MAX_NUM_BINS) {
     21    fprintf(stderr, "Exceeded maximum number of jemalloc stats bins");
     22    return 1;
     23  }
     24  jemalloc_bin_stats_t bin_stats[MAX_NUM_BINS] = {{0}};
     25  jemalloc_stats(&stats, bin_stats);
     26 
     27  printf("\n");
     28  printf("Parameters\n");
     29  printf("----------\n\n");
     30  printf("Page size:    %5zu\n", stats.page_size);
     31  printf("Chunk size:   %5zuKiB\n", stats.chunksize / 1024);
     32  printf("Quantum:      %5zu\n", stats.quantum);
     33  printf("Quantum max:  %5zu\n", stats.quantum_max);
     34  printf("Sub-page max: %5zu\n", stats.page_size / 2);
     35  printf("Large max:    %5zuKiB\n", stats.large_max / 1024);
     36 
     37  printf("\n");
     38  printf("Run layout for each bin size\n");
     39  printf("----------------------------\n\n");
     40  printf(" Size | Reg per run | Run size | Overhead\n");
     41  printf("------|-------------|----------|----------\n");
     42  for (unsigned i = 0; i < num_bins; i++) {
     43    auto& bin = bin_stats[i];
     44    if (bin.size) {
     45      printf("%5zu | %11zu | %5zuKiB | %7.2f%%\n", bin.size,
     46             bin.regions_per_run, bin.bytes_per_run / 1024,
     47             float(bin.bytes_per_run - (bin.regions_per_run * bin.size)) *
     48                 100.0f / float(bin.regions_per_run * bin.size));
     49    }
     50  }
     51 
     52  return EXIT_SUCCESS;
     53 }