Ignore:
Timestamp:
Mar 5, 2019, 1:14:52 PM (5 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
3c0d4cd
Parents:
4f97937
Message:

Improved printing, parent printing still incorrect

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Stats/Time.cc

    r4f97937 r79eaeb7  
    3131                        Base::TreeTop top;
    3232
     33                        typedef  std::chrono::time_point<std::chrono::high_resolution_clock> point_t;
     34                        std::chrono::duration<double> total;
     35                        std::chrono::duration<double> parent;
     36
     37                        point_t global_begin;
     38
     39                        template<typename T>
     40                        static inline std::ostream & operator<<(std::ostream & os, const std::chrono::duration<T> & dd) {
     41                                auto d = std::chrono::duration_cast<std::chrono::milliseconds>(dd);
     42                                auto minutes = std::chrono::duration_cast<std::chrono::minutes>(d);
     43                                auto seconds = std::chrono::duration_cast<std::chrono::seconds>(d % std::chrono::minutes(1));
     44                                auto millis  = std::chrono::duration_cast<std::chrono::milliseconds>(d % std::chrono::seconds(1));
     45
     46                                bool zmin = minutes == minutes.zero();
     47                                bool zsec = seconds == seconds.zero();
     48                                bool zmil = millis  == millis .zero();
     49
     50                                if(!zmin) {
     51                                        os << std::setw(4) << minutes.count() << "m";
     52                                } else {
     53                                        os << std::string(5, ' ');
     54                                }
     55
     56                                if(!zmin || !zsec) {
     57                                        if(!zmin) os << std::setfill('0');
     58                                        os << std::setw(2) << seconds.count() << "s";
     59                                } else {
     60                                        os << std::string(3, ' ');
     61                                }
     62                                os << std::setfill(' ');
     63
     64                                if(!zmin || !zsec || !zmil) {
     65                                        if(!zmin || !zsec) os << std::setfill('0');
     66                                        os << std::setw(3) << millis .count();
     67                                } else {
     68                                        os << std::string(4, ' ');
     69                                }
     70                                os << std::setfill(' ');
     71
     72                                return os;
     73                        }
     74
    3375                        class TimerNode : public Base::Tree<top> {
    3476                        public:
     
    4587                                        assert(finished);
    4688                                        std::chrono::duration<double> diff = end - begin;
    47                                         os << diff.count();
     89                                        os << diff << " | ";
     90                                        os << std::setw(7) << std::setprecision(0);
     91                                        os << size_t(100.0 * diff.count() / total.count()) << "% | ";
     92                                        os << std::setw(5) << std::setprecision(0);
     93                                        os << size_t(100.0 * diff.count() / total.count()) << "% ";
    4894                                }
    4995
     
    63109                                bool finished = false;
    64110
    65                                 typedef  std::chrono::time_point<std::chrono::high_resolution_clock> point_t;
    66111                                point_t begin;
    67112                                point_t end;
     
    69114
    70115                        std::stack<TimerNode *> nodes;
     116
     117                        void StartGlobal() {
     118                                global_begin = std::chrono::high_resolution_clock::now();
     119                        }
    71120
    72121                        void StartBlock(const char * const name) {
     
    88137                        void print() {
    89138                                if(!top.head) return;
     139                                auto global_end = std::chrono::high_resolution_clock::now();
     140                                total = global_end - global_begin;
     141                                parent = total;
     142
    90143                                size_t nc = 0;
    91144                                Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) {
     
    93146                                });
    94147
     148                                size_t nct = nc + 37;
     149                                std::cerr << std::string(nct, '=') << std::endl;
    95150                                const char * const title = "Timing Results";
    96                                 size_t nct = nc + 14;
    97                                 std::cerr << std::string(nct, '=') << std::endl;
    98151                                std::cerr << std::string((nct - std::strlen(title)) / 2, ' ');
    99152                                std::cerr << title << std::endl;
    100153                                std::cerr << std::string(nct, '-') << std::endl;
    101 
     154                                std::cerr << "Location";
     155                                std::cerr << std::string(nc - (std::strlen("Location")), ' ');
     156                                std::cerr << " | ";
     157                                std::cerr << "       Time | ";
     158                                std::cerr << "% parent | ";
     159                                std::cerr << "% total |" << std::endl;
     160                                std::cerr << std::string(nct, '-') << std::endl;
    102161
    103162                                Base::ForAll(top, 0, [&](Base::TreeImpl * node, size_t level) {
     
    106165                                        std::cerr << std::string(nc - ((level * 4) + std::strlen(node->name)), ' ');
    107166                                        std::cerr << " | ";
    108                                         std::cerr << std::setw(9);
    109167                                        node->print(std::cerr);
    110168                                        std::cerr << " |";
     
    113171
    114172                                std::cerr << std::string(nct, '-') << std::endl;
     173                                std::cerr << "Total " << total << std::endl;
     174                                std::cerr << std::string(nct, '-') << std::endl;
    115175                        }
    116176#               endif
Note: See TracChangeset for help on using the changeset viewer.