Changeset c15085d


Ignore:
Timestamp:
Jul 3, 2020, 4:50:21 PM (4 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
aebf5b0
Parents:
276f105
Message:

tracing memory allocation of resolver passes

Location:
src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r276f105 rc15085d  
    2828        /* setup the scope for passes that want to run code at exit */ \
    2929        __attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (pass, 0) ); \
     30        /* begin tracing memory allocation if requested by this pass */ \
     31        __pass::beginTrace( pass, 0 ); \
    3032        /* call the implementation of the previsit of this pass */ \
    3133        __pass::previsit( pass, node, 0 );
     
    4244        auto __return = __pass::postvisit( pass, node, 0 ); \
    4345        assertf(__return, "post visit should never return null"); \
     46        /* end tracing memory allocation if requested by this pass */ \
     47        __pass::endTrace( pass, 0 ); \
    4448        return __return;
    4549
  • src/AST/Pass.proto.hpp

    r276f105 rc15085d  
    1616#pragma once
    1717// IWYU pragma: private, include "Pass.hpp"
     18
     19#include "Common/Stats/Heap.h"
    1820
    1921namespace ast {
     
    244246        #undef FIELD_PTR
    245247
     248        template< typename pass_t >
     249        static inline auto beginTrace(pass_t & pass, int) -> decltype( pass_t::traceId, void() ) {
     250                Stats::Heap::stacktrace_push(pass_t::traceId);
     251        }
     252
     253        template< typename pass_t >
     254        static inline auto endTrace(pass_t & pass, int) -> decltype( pass_t::traceId, void() ) {
     255                Stats::Heap::stacktrace_pop();
     256        }
     257
     258        template< typename pass_t >
     259        static void beginTrace(pass_t &, long) {}
     260
     261        template< typename pass_t >
     262        static void endTrace(pass_t &, long) {}
     263
    246264        // Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
    247265        // All passes which have such functions are assumed desire this behaviour
  • src/AST/TypeSubstitution.cpp

    r276f105 rc15085d  
    1818
    1919namespace ast {
     20
     21
     22size_t TypeSubstitution::Substituter::traceId = Stats::Heap::new_stacktrace_id("TypeSubstitution");
    2023
    2124TypeSubstitution::TypeSubstitution() {
  • src/AST/TypeSubstitution.hpp

    r276f105 rc15085d  
    160160// definitition must happen after PassVisitor is included so that WithGuards can be used
    161161struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
     162                static size_t traceId;
    162163
    163164                Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
  • src/Common/Stats/Heap.cc

    r276f105 rc15085d  
    5353                const size_t passes_size = sizeof(passes) / sizeof(passes[0]);
    5454                size_t       passes_cnt = 1;
     55
     56                StatBlock    stacktrace_stats[100];
     57                size_t       stacktrace_stats_count = 0;
     58                bool         stacktrace_stats_enabled = true;
     59
     60                size_t       trace[1000];
     61                const size_t stacktrace_max_depth = sizeof(trace) / sizeof(size_t);
     62                size_t       stacktrace_depth;
     63
     64                size_t new_stacktrace_id(const char * const name) {
     65                        stacktrace_stats[stacktrace_stats_count].name = name;
     66                        return stacktrace_stats_count++;
     67                }
     68
     69                void stacktrace_push(size_t id) {
     70                        ++stacktrace_depth;
     71                        assertf(stacktrace_depth < stacktrace_max_depth, "Stack trace too deep: increase size of array in Heap.cc");
     72                        trace[stacktrace_depth] = id;
     73                }
     74
     75                void stacktrace_pop() {
     76                        assertf(stacktrace_depth > 0, "Invalid stack tracing operation: trace is empty");
     77                        --stacktrace_depth;
     78                }
    5579
    5680                void newPass( const char * const name ) {
     
    116140                        for(size_t i = 0; i < passes_cnt; i++) {
    117141                                print(passes[i], nc, total_mallocs, total_frees, overall_peak);
     142                        }
     143
     144                        print('-', nct);
     145                        std::cerr << std::setw(nc) << "Trace";
     146                        std::cerr << " |       Malloc Count |         Free Count |        Peak Allocs |" << std::endl;
     147
     148                        print('-', nct);
     149                        for (size_t i = 0; i < stacktrace_stats_count; i++) {
     150                                print(stacktrace_stats[i], nc, total_mallocs, total_frees, overall_peak);
    118151                        }
    119152                        print('-', nct);
     
    188221                                                = std::max(passes[passes_cnt - 1].peak_allocs, passes[passes_cnt - 1].n_allocs);
    189222                                }
     223
     224                                if ( stacktrace_stats_enabled && stacktrace_depth > 0) {
     225                                        stacktrace_stats[trace[stacktrace_depth]].mallocs++;
     226                                }
    190227                                return __malloc( size );
    191228                        }
     
    196233                                        passes[passes_cnt - 1].frees++;
    197234                                        passes[passes_cnt - 1].n_allocs--;
     235                                }
     236                                if ( stacktrace_stats_enabled && stacktrace_depth > 0) {
     237                                        stacktrace_stats[trace[stacktrace_depth]].frees++;
    198238                                }
    199239                                return __free( ptr );
     
    208248                                                = std::max(passes[passes_cnt - 1].peak_allocs, passes[passes_cnt - 1].n_allocs);
    209249                                }
     250                                if ( stacktrace_stats_enabled && stacktrace_depth > 0) {
     251                                        stacktrace_stats[trace[stacktrace_depth]].mallocs++;
     252                                }
    210253                                return __calloc( nelem, size );
    211254                        }
     
    218261                                        passes[passes_cnt - 1].frees++;
    219262                                } // if
     263                                if ( stacktrace_stats_enabled && stacktrace_depth > 0) {
     264                                        stacktrace_stats[trace[stacktrace_depth]].mallocs++;
     265                                        stacktrace_stats[trace[stacktrace_depth]].frees++;
     266                                }
    220267                                return s;
    221268                        }
  • src/Common/Stats/Heap.h

    r276f105 rc15085d  
    2020                void newPass( const char * const name );
    2121                void print();
     22
     23                size_t new_stacktrace_id(const char * const name);
     24                void stacktrace_push(size_t id);
     25                void stacktrace_pop();
    2226        }
    2327}
  • src/ResolvExpr/CandidateFinder.cpp

    r276f105 rc15085d  
    596596                const ast::SymbolTable & symtab;
    597597        public:
     598                static size_t traceId;
    598599                CandidateFinder & selfFinder;
    599600                CandidateList & candidates;
     
    15071508        };
    15081509
     1510        size_t Finder::traceId = Stats::Heap::new_stacktrace_id("Finder");
    15091511        /// Prunes a list of candidates down to those that have the minimum conversion cost for a given
    15101512        /// return type. Skips ambiguous candidates.
  • src/ResolvExpr/CommonType.cc

    r276f105 rc15085d  
    666666                const ast::OpenVarSet & open;
    667667        public:
     668                static size_t traceId;
    668669                ast::ptr< ast::Type > result;
    669670
     
    893894        };
    894895
     896        size_t CommonType_new::traceId = Stats::Heap::new_stacktrace_id("CommonType_new");
    895897        namespace {
    896898                ast::ptr< ast::Type > handleReference(
  • src/ResolvExpr/ConversionCost.cc

    r276f105 rc15085d  
    795795        }
    796796}
    797 
     797size_t ConversionCost_new::traceId = Stats::Heap::new_stacktrace_id("ConversionCost");
    798798
    799799} // namespace ResolvExpr
  • src/ResolvExpr/ConversionCost.h

    r276f105 rc15085d  
    8888        CostCalculation costCalc;
    8989public:
     90        static size_t traceId;
    9091        Cost cost;
    9192
  • src/ResolvExpr/Resolver.cc

    r276f105 rc15085d  
    12361236
    12371237        public:
     1238                static size_t traceId;
    12381239                Resolver_new() = default;
    12391240                Resolver_new( const ast::SymbolTable & syms ) { symtab = syms; }
     
    12661267                const ast::ConstructorInit * previsit( const ast::ConstructorInit * );
    12671268        };
     1269        size_t Resolver_new::traceId = Stats::Heap::new_stacktrace_id("Resolver");
    12681270
    12691271        void resolve( std::list< ast::ptr< ast::Decl > >& translationUnit ) {
  • src/ResolvExpr/Unify.cc

    r276f105 rc15085d  
    702702                const ast::SymbolTable & symtab;
    703703        public:
     704                static size_t traceId;
    704705                bool result;
    705706
     
    11351136        };
    11361137
     1138        size_t Unify_new::traceId = Stats::Heap::new_stacktrace_id("Unify_new");
    11371139        bool unify(
    11381140                        const ast::ptr<ast::Type> & type1, const ast::ptr<ast::Type> & type2,
Note: See TracChangeset for help on using the changeset viewer.