#include "stack_profile.h" #include #include using namespace std; StackProfiler::StackProfiler(size_t cacheSize, size_t _cacheLineSize, int _associativity) : cacheLineSize(_cacheLineSize), associativity(_associativity) { cacheWrapSize = cacheSize / associativity; cacheSets = (cacheSize / cacheLineSize) / associativity; setProfiles.reserve(cacheSets); cout << "Created stack profiler with wrap size " << cacheWrapSize << " and " << cacheSets << " sets" << endl; for (unsigned i = 0; i < cacheSets; i++) { setProfiles.push_back(StackProfile(associativity)); } }; void StackProfiler::followPointers(void * start, bool count) { uintptr_t * b = (uintptr_t *) start; while (b != NULL) { access((uintptr_t) b, count); b = (uintptr_t *) *b; } } void StackProfiler::printCounts() { int i = 0; for (std::vector::iterator it = setProfiles.begin(); it != setProfiles.end(); it++, i++) { cout << i << ": "; it->printCounts(); } } void StackProfiler::printCountsR(std::ostream & o) { // print column names: set c1 c2 ... cX // X = associativity + 1 (accesses that miss) o << "set"; for (int i = 1; i <= associativity + 1; i++) { o << "\tc" << i; } o << endl; int i = 1; for (std::vector::iterator it = setProfiles.begin(); it != setProfiles.end(); it++, i++) { o << i; it->printCountsR(o); o << endl; } } void StackProfiler::test() { cout << "testing stack profiler" << endl; StackProfile & sp = setProfiles[0]; cout << sp.access(1, false) << endl; cout << sp.access(2, false) << endl; cout << sp.access(3, false) << endl; cout << sp.access(4, false) << endl; cout << sp.access(1, true) << endl; cout << sp.access(2, true) << endl; cout << sp.access(3, true) << endl; cout << sp.access(4, true) << endl; for (int i = 0; i <= associativity; i++) { cout << i << ": " << sp.counts[i] << endl; } exit(0); };