zcov: / include/klee/Statistics.h


Files: 1 Branches Taken: 77.8% 14 / 18
Generated: 2009-05-17 22:47 Branches Executed: 100.0% 18 / 18
Line Coverage: 96.6% 28 / 29


Programs: 7 Runs 3244


       1                 : //===- Statistics.h - --*- C++ -*-===//
       2                 : 
       3                 : #ifndef KLEE_STATISTICS_H
       4                 : #define KLEE_STATISTICS_H
       5                 : 
       6                 : #include "Statistic.h"
       7                 : 
       8                 : #include <vector>
       9                 : #include <string>
      10                 : #include <string.h>
      11                 : 
      12                 : namespace klee {
      13                 :   class Statistic;
      14                 :   class StatisticRecord {
      15                 :     friend class StatisticManager;
      16                 : 
      17                 :   private:
      18                 :     uint64_t *data;
      19                 : 
      20                 :   public:    
      21                 :     StatisticRecord();
      22                 :     StatisticRecord(const StatisticRecord &s);
                     2389: branch 0 taken
                     1954: branch 1 taken
                      542: branch 3 taken
                        0: branch 4 not taken
                      542: branch 6 taken
                        0: branch 7 not taken
                      435: branch 9 taken
                        0: branch 10 not taken
                      435: branch 12 taken
                        0: branch 13 not taken
      23             2389:     ~StatisticRecord() { delete[] data; }
      24                 :     
      25                 :     void zero();
      26                 : 
      27                 :     uint64_t getValue(const Statistic &s) const; 
      28                 :     void incrementValue(const Statistic &s, uint64_t addend) const;
      29                 :     StatisticRecord &operator =(const StatisticRecord &s);
      30                 :     StatisticRecord &operator +=(const StatisticRecord &sr);
      31                 :   };
      32                 : 
      33                 :   class StatisticManager {
      34                 :   private:
      35                 :     bool enabled;
      36                 :     std::vector<Statistic*> stats;
      37                 :     uint64_t *globalStats;
      38                 :     uint64_t *indexedStats;
      39                 :     StatisticRecord *contextStats;
      40                 :     unsigned index;
      41                 : 
      42                 :   public:
      43                 :     StatisticManager();
      44                 :     ~StatisticManager();
      45                 : 
      46                 :     void useIndexedStats(unsigned totalIndices);
      47                 : 
      48                 :     StatisticRecord *getContext();
      49                 :     void setContext(StatisticRecord *sr); /* null to reset */
      50                 : 
      51         10484786:     void setIndex(unsigned i) { index = i; }
      52           847846:     unsigned getIndex() { return index; }
      53            12550:     unsigned getNumStatistics() { return stats.size(); }
      54          2946580:     Statistic &getStatistic(unsigned i) { return *stats[i]; }
      55                 :     
      56                 :     void registerStatistic(Statistic &s);
      57                 :     void incrementStatistic(Statistic &s, uint64_t addend);
      58                 :     uint64_t getValue(const Statistic &s) const;
      59                 :     void incrementIndexedValue(const Statistic &s, unsigned index, 
      60                 :                                uint64_t addend) const;
      61                 :     uint64_t getIndexedValue(const Statistic &s, unsigned index) const;
      62                 :     void setIndexedValue(const Statistic &s, unsigned index, uint64_t value);
      63                 :     int getStatisticID(const std::string &name) const;
      64                 :     Statistic *getStatisticByName(const std::string &name) const;
      65                 :   };
      66                 : 
      67                 :   extern StatisticManager *theStatisticManager;
      68                 : 
      69                 :   inline void StatisticManager::incrementStatistic(Statistic &s, 
      70                 :                                                    uint64_t addend) {
      71                 :     if (enabled) {
      72         11505084:       globalStats[s.id] += addend;
                 11467687: branch 0 taken
                    37397: branch 1 taken
      73         11505084:       if (indexedStats) {
      74         22935374:         indexedStats[index*stats.size() + s.id] += addend;
                 11364010: branch 0 taken
                   103677: branch 1 taken
      75         11467687:         if (contextStats)
      76         11364010:           contextStats->data[s.id] += addend;
      77                 :       }
      78                 :     }
      79                 :   }
      80                 : 
      81                 :   inline StatisticRecord *StatisticManager::getContext() {
      82                 :     return contextStats;
      83                 :   }
      84                 :   inline void StatisticManager::setContext(StatisticRecord *sr) {
      85         10391933:     contextStats = sr;
      86                 :   }
      87                 : 
      88                 :   inline void StatisticRecord::zero() {
      89             3038:     ::memset(data, 0, sizeof(*data)*theStatisticManager->getNumStatistics());
      90                 :   }
      91                 : 
      92             1519:   inline StatisticRecord::StatisticRecord() 
      93             3038:     : data(new uint64_t[theStatisticManager->getNumStatistics()]) {
      94                 :     zero();
      95             1519:   }
      96                 : 
      97                 :   inline StatisticRecord::StatisticRecord(const StatisticRecord &s) 
      98             1740:     : data(new uint64_t[theStatisticManager->getNumStatistics()]) {
      99                 :     ::memcpy(data, s.data, 
     100             1740:              sizeof(*data)*theStatisticManager->getNumStatistics());
     101                 :   }
     102                 : 
     103                 :   inline StatisticRecord &StatisticRecord::operator=(const StatisticRecord &s) {
     104                 :     ::memcpy(data, s.data, 
     105              928:              sizeof(*data)*theStatisticManager->getNumStatistics());
     106              464:     return *this;
     107                 :   }
     108                 : 
     109                 :   inline void StatisticRecord::incrementValue(const Statistic &s, 
     110                 :                                               uint64_t addend) const {
     111               32:     data[s.id] += addend;
     112                 :   }
     113                 :   inline uint64_t StatisticRecord::getValue(const Statistic &s) const { 
     114             3960:     return data[s.id]; 
     115                 :   }
     116                 : 
     117                 :   inline StatisticRecord &
     118                 :   StatisticRecord::operator +=(const StatisticRecord &sr) {
     119             1856:     unsigned nStats = theStatisticManager->getNumStatistics();
                    12064: branch 0 taken
                      464: branch 1 taken
                    12064: branch 2 taken
                      464: branch 3 taken
     120            25056:     for (unsigned i=0; i<nStats; i++)
     121            24128:       data[i] += sr.data[i];
     122              928:     return *this;
     123                 :   }
     124                 : 
     125                 :   inline uint64_t StatisticManager::getValue(const Statistic &s) const {
     126         20102214:     return globalStats[s.id];
     127                 :   }
     128                 : 
     129                 :   inline void StatisticManager::incrementIndexedValue(const Statistic &s, 
     130                 :                                                       unsigned index,
     131                 :                                                       uint64_t addend) const {
     132               64:     indexedStats[index*stats.size() + s.id] += addend;
     133                 :   }
     134                 : 
     135                 :   inline uint64_t StatisticManager::getIndexedValue(const Statistic &s, 
     136                 :                                                     unsigned index) const {
     137         27107790:     return indexedStats[index*stats.size() + s.id];
     138                 :   }
     139                 : 
     140                 :   inline void StatisticManager::setIndexedValue(const Statistic &s, 
     141                 :                                                 unsigned index,
     142                 :                                                 uint64_t value) {
     143                0:     indexedStats[index*stats.size() + s.id] = value;
     144                 :   }
     145                 : }
     146                 : 
     147                 : #endif

Generated: 2009-05-17 22:47 by zcov