sl@0: // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "analyse.h" sl@0: #include "activity.h" sl@0: #include "output.h" sl@0: sl@0: #ifdef __MSVCDOTNET__ sl@0: #include sl@0: #include sl@0: #else //!__MSVCDOTNET__ sl@0: #include sl@0: #include sl@0: #endif //__MSVCDOTNET__ sl@0: sl@0: #include sl@0: sl@0: sl@0: // class Activity::Bucket sl@0: sl@0: inline Activity::Bucket::Bucket(unsigned aPeriod,int aThread) sl@0: :iPeriod(aPeriod),iThread(aThread) sl@0: {} sl@0: sl@0: bool Activity::Bucket::operator<(const Bucket& aRhs) const sl@0: { sl@0: if (iPeriod != aRhs.iPeriod) sl@0: return iPeriod < aRhs.iPeriod; sl@0: return iThread < aRhs.iThread; sl@0: } sl@0: sl@0: // class Activity::ThreadData sl@0: sl@0: inline Activity::ThreadData::ThreadData(const Thread& aThread) sl@0: :iThread(&aThread), iTotal(0) sl@0: {} sl@0: sl@0: inline Activity::ThreadData::ThreadData(unsigned aCutoff) sl@0: :iTotal(aCutoff) sl@0: {} sl@0: sl@0: inline bool Activity::ThreadData::operator<(const ThreadData& aRhs) const sl@0: { sl@0: return iTotal < aRhs.iTotal; sl@0: } sl@0: sl@0: sl@0: // class Activity sl@0: sl@0: sl@0: Activity::Activity(int aBucketSize, unsigned aBeginSample, double aCutOff) sl@0: :iBucketSize(aBucketSize), iBeginSample(aBeginSample), iCutOff(aCutOff) sl@0: { sl@0: cout << "Execution activity\n\n"; sl@0: } sl@0: sl@0: void Activity::Sample(unsigned aNumber, const Thread& aThread, PC) sl@0: { sl@0: if (aThread.iIndex == iThreads.size()) sl@0: iThreads.push_back(ThreadData(aThread)); sl@0: sl@0: ++iThreads[aThread.iIndex].iTotal; sl@0: ++iData[Bucket((aNumber - iBeginSample) / iBucketSize, aThread.iIndex)]; sl@0: } sl@0: sl@0: void Activity::Complete(unsigned aTotal, unsigned aActive) sl@0: { sl@0: cout.setf(ios::fixed, ios::floatfield); sl@0: cout << setfill(' '); sl@0: cout.precision(2); sl@0: const char* emptySeparator; sl@0: const char* separator; sl@0: // sl@0: const unsigned ixCount = iThreads.size(); sl@0: int* remap = new int[ixCount]; sl@0: std::fill(remap, remap + ixCount, -1); sl@0: sl@0: std::sort(iThreads.begin(), iThreads.end()); sl@0: Threads::iterator cutoff = std::lower_bound(iThreads.begin(), iThreads.end(), ThreadData(iCutOff * aTotal * 0.01)); sl@0: iThreads.erase(iThreads.begin(), cutoff); sl@0: sl@0: const unsigned disCount = iThreads.size(); sl@0: for (int ix = 0; ix < disCount; ++ix) sl@0: remap[iThreads[ix].iThread->iIndex] = ix; sl@0: sl@0: sl@0: if (Analyse::Format() != Analyse::EExcel) sl@0: { sl@0: cout << "ID Thread name\n"; sl@0: int ix; sl@0: for (ix = 0; ix < disCount; ++ix) sl@0: cout << char('A' + ix) << " " << *iThreads[ix].iThread << '\n'; sl@0: sl@0: cout << "\nsample "; sl@0: for (ix = 0; ix < disCount; ++ix) sl@0: cout << setw(4) << char('A' + ix) << " "; sl@0: cout << "\n\n"; sl@0: separator = " "; sl@0: emptySeparator = " "; sl@0: } sl@0: else sl@0: { sl@0: cout << "sample"; sl@0: for (int ix = 0; ix < disCount; ++ix) sl@0: cout << '\t' << *iThreads[ix].iThread; sl@0: cout << '\n'; sl@0: separator = emptySeparator = "\t"; sl@0: } sl@0: sl@0: unsigned* totals = new unsigned[disCount]; sl@0: std::fill(totals, totals + disCount, 0); sl@0: unsigned period = 0; sl@0: bool values = false; sl@0: for (Data::iterator p = iData.begin(), e = iData.end(); p != e; ++p) sl@0: { sl@0: while (period != p->first.iPeriod) sl@0: { sl@0: cout << setw(7) << (period * iBucketSize) + iBeginSample; sl@0: if (values) sl@0: { sl@0: for (int ix = 0; ix < disCount; ++ix) sl@0: cout << separator << Result(totals[ix], iBucketSize); sl@0: std::fill(totals, totals + disCount, 0); sl@0: values = false; sl@0: } sl@0: cout << '\n'; sl@0: ++period; sl@0: } sl@0: int ix = remap[p->first.iThread]; sl@0: if (ix >= 0) sl@0: { sl@0: totals[ix] = p->second; sl@0: values = true; sl@0: } sl@0: } sl@0: if (values) sl@0: { sl@0: cout << setw(7) << (period * iBucketSize) + iBeginSample; sl@0: for (int ix = 0; ix < disCount; ++ix) sl@0: cout << separator << Result(totals[ix], iBucketSize); sl@0: cout << '\n'; sl@0: } sl@0: sl@0: delete [] remap; sl@0: delete [] totals; sl@0: }