Changeset a96691d


Ignore:
Timestamp:
May 4, 2018, 12:11:25 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
1752d0e
Parents:
ecaeac6e
Message:

Better formatting for heap stats

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Heap.cc

    recaeac6e ra96691d  
    4646                }
    4747
     48                void print(size_t value, size_t total) {
     49                        std::cerr << std::setw(12) << value;
     50                        std::cerr << "(" << std::setw(3);
     51                        std::cerr << (value == 0 ? 0 : value * 100 / total);
     52                        std::cerr << "%) | ";
     53                }
     54
     55                void print(const StatBlock& stat, size_t nc, size_t total_mallocs, size_t total_frees) {
     56                        std::cerr << std::setw(nc) << stat.name;
     57                        std::cerr << " | ";
     58
     59                        print(stat.mallocs, total_mallocs);
     60                        print(stat.frees  , total_frees  );
     61                        std::cerr << "\n";
     62                }
     63
     64                void print(char c, size_t nc) {
     65                        for(size_t i = 0; i < nc; i++) {
     66                                std::cerr << c;
     67                        }
     68                        std::cerr << '\n';
     69                }
     70
    4871                void printStats() {
    4972                        size_t nc = 0;
     73                        size_t total_mallocs = 0;
     74                        size_t total_frees   = 0;
    5075                        for(size_t i = 0; i < passes_cnt; i++) {
    5176                                nc = std::max(nc, std::strlen(passes[i].name));
     77                                total_mallocs += passes[i].mallocs;
     78                                total_frees   += passes[i].frees;
    5279                        }
     80                        size_t nct = nc + 44;
    5381
    5482                        const char * const title = "Heap Usage Statistic";
    55                         for(size_t i = 0; i < (nc + 30); i++) std::cerr << '='; std::cerr << '\n';
    56                         for(size_t i = 0; i < (nc + 30 - std::strlen(title)) / 2; i++) std::cerr << ' ';
     83                        print('=', nct);
     84                        for(size_t i = 0; i < (nct - std::strlen(title)) / 2; i++) std::cerr << ' ';
    5785                        std::cerr << title << std::endl;
    58                         for(size_t i = 0; i < (nc + 30); i++) std::cerr << '-'; std::cerr << '\n';
     86                        print('-', nct);
    5987                        std::cerr << std::setw(nc) << "Pass";
    60                         std::cerr << " | Malloc Count |   Free Count" << std::endl;
    61                         for(size_t i = 0; i < (nc + 30); i++) std::cerr << '-'; std::cerr << '\n';
     88                        std::cerr << " |       Malloc Count |         Free Count |" << std::endl;
     89
     90                        print('-', nct);
    6291                        for(size_t i = 0; i < passes_cnt; i++) {
    63                                 std::cerr << std::setw(nc) << passes[i].name    << " | ";
    64                                 std::cerr << std::setw(12) << passes[i].mallocs << " | ";
    65                                 std::cerr << std::setw(12) << passes[i].frees   << "\n";
     92                                print(passes[i], nc, total_mallocs, total_frees);
    6693                        }
     94                        print('-', nct);
     95                        print({"Sum", total_mallocs, total_frees}, nc, total_mallocs, total_frees);
     96
    6797                }
    6898        #endif
Note: See TracChangeset for help on using the changeset viewer.