First public contribution.
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
23 #else //!__MSVCDOTNET__
26 #endif //__MSVCDOTNET__
31 // class Activity::Bucket
33 inline Activity::Bucket::Bucket(unsigned aPeriod,int aThread)
34 :iPeriod(aPeriod),iThread(aThread)
37 bool Activity::Bucket::operator<(const Bucket& aRhs) const
39 if (iPeriod != aRhs.iPeriod)
40 return iPeriod < aRhs.iPeriod;
41 return iThread < aRhs.iThread;
44 // class Activity::ThreadData
46 inline Activity::ThreadData::ThreadData(const Thread& aThread)
47 :iThread(&aThread), iTotal(0)
50 inline Activity::ThreadData::ThreadData(unsigned aCutoff)
54 inline bool Activity::ThreadData::operator<(const ThreadData& aRhs) const
56 return iTotal < aRhs.iTotal;
63 Activity::Activity(int aBucketSize, unsigned aBeginSample, double aCutOff)
64 :iBucketSize(aBucketSize), iBeginSample(aBeginSample), iCutOff(aCutOff)
66 cout << "Execution activity\n\n";
69 void Activity::Sample(unsigned aNumber, const Thread& aThread, PC)
71 if (aThread.iIndex == iThreads.size())
72 iThreads.push_back(ThreadData(aThread));
74 ++iThreads[aThread.iIndex].iTotal;
75 ++iData[Bucket((aNumber - iBeginSample) / iBucketSize, aThread.iIndex)];
78 void Activity::Complete(unsigned aTotal, unsigned aActive)
80 cout.setf(ios::fixed, ios::floatfield);
83 const char* emptySeparator;
84 const char* separator;
86 const unsigned ixCount = iThreads.size();
87 int* remap = new int[ixCount];
88 std::fill(remap, remap + ixCount, -1);
90 std::sort(iThreads.begin(), iThreads.end());
91 Threads::iterator cutoff = std::lower_bound(iThreads.begin(), iThreads.end(), ThreadData(iCutOff * aTotal * 0.01));
92 iThreads.erase(iThreads.begin(), cutoff);
94 const unsigned disCount = iThreads.size();
95 for (int ix = 0; ix < disCount; ++ix)
96 remap[iThreads[ix].iThread->iIndex] = ix;
99 if (Analyse::Format() != Analyse::EExcel)
101 cout << "ID Thread name\n";
103 for (ix = 0; ix < disCount; ++ix)
104 cout << char('A' + ix) << " " << *iThreads[ix].iThread << '\n';
107 for (ix = 0; ix < disCount; ++ix)
108 cout << setw(4) << char('A' + ix) << " ";
111 emptySeparator = " ";
116 for (int ix = 0; ix < disCount; ++ix)
117 cout << '\t' << *iThreads[ix].iThread;
119 separator = emptySeparator = "\t";
122 unsigned* totals = new unsigned[disCount];
123 std::fill(totals, totals + disCount, 0);
126 for (Data::iterator p = iData.begin(), e = iData.end(); p != e; ++p)
128 while (period != p->first.iPeriod)
130 cout << setw(7) << (period * iBucketSize) + iBeginSample;
133 for (int ix = 0; ix < disCount; ++ix)
134 cout << separator << Result(totals[ix], iBucketSize);
135 std::fill(totals, totals + disCount, 0);
141 int ix = remap[p->first.iThread];
144 totals[ix] = p->second;
150 cout << setw(7) << (period * iBucketSize) + iBeginSample;
151 for (int ix = 0; ix < disCount; ++ix)
152 cout << separator << Result(totals[ix], iBucketSize);