Statistics.cpp

Go to the documentation of this file.
00001 //===-- Statistics.cpp ----------------------------------------------------===//
00002 //
00003 //                     The KLEE Symbolic Virtual Machine
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "klee/Statistics.h"
00011 
00012 #include <vector>
00013 
00014 using namespace klee;
00015 
00016 StatisticManager::StatisticManager()
00017   : enabled(true),
00018     globalStats(0),
00019     indexedStats(0),
00020     contextStats(0),
00021     index(0) {
00022 }
00023 
00024 StatisticManager::~StatisticManager() {
00025   if (globalStats) delete[] globalStats;
00026   if (indexedStats) delete[] indexedStats;
00027 }
00028 
00029 void StatisticManager::useIndexedStats(unsigned totalIndices) {  
00030   if (indexedStats) delete[] indexedStats;
00031   indexedStats = new uint64_t[totalIndices * stats.size()];
00032   memset(indexedStats, 0, sizeof(*indexedStats) * totalIndices * stats.size());
00033 }
00034 
00035 void StatisticManager::registerStatistic(Statistic &s) {
00036   if (globalStats) delete[] globalStats;
00037   s.id = stats.size();
00038   stats.push_back(&s);
00039   globalStats = new uint64_t[stats.size()];
00040   memset(globalStats, 0, sizeof(*globalStats)*stats.size());
00041 }
00042 
00043 int StatisticManager::getStatisticID(const std::string &name) const {
00044   for (unsigned i=0; i<stats.size(); i++)
00045     if (stats[i]->getName() == name)
00046       return i;
00047   return -1;
00048 }
00049 
00050 Statistic *StatisticManager::getStatisticByName(const std::string &name) const {
00051   for (unsigned i=0; i<stats.size(); i++)
00052     if (stats[i]->getName() == name)
00053       return stats[i];
00054   return 0;
00055 }
00056 
00057 StatisticManager *klee::theStatisticManager = 0;
00058 
00059 static StatisticManager &getStatisticManager() {
00060   static StatisticManager sm;
00061   theStatisticManager = &sm;
00062   return sm;
00063 }
00064 
00065 /* *** */
00066 
00067 Statistic::Statistic(const std::string &_name, 
00068                      const std::string &_shortName) 
00069   : name(_name), 
00070     shortName(_shortName) {
00071   getStatisticManager().registerStatistic(*this);
00072 }
00073 
00074 Statistic::~Statistic() {
00075 }
00076 
00077 Statistic &Statistic::operator +=(const uint64_t addend) {
00078   theStatisticManager->incrementStatistic(*this, addend);
00079   return *this;
00080 }
00081 
00082 uint64_t Statistic::getValue() const {
00083   return theStatisticManager->getValue(*this);
00084 }

Generated on Fri Jun 5 03:31:31 2009 for klee by  doxygen 1.5.8