os/kernelhwsrv/kerneltest/e32utils/analyse/activity.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32utils/analyse/activity.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,158 @@
     1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "analyse.h"
    1.20 +#include "activity.h"
    1.21 +#include "output.h"
    1.22 +
    1.23 +#ifdef __MSVCDOTNET__
    1.24 +#include <ostream>
    1.25 +#include <iomanip>
    1.26 +#else //!__MSVCDOTNET__
    1.27 +#include <ostream.h>
    1.28 +#include <iomanip.h>
    1.29 +#endif //__MSVCDOTNET__
    1.30 +
    1.31 +#include <algorithm>
    1.32 +
    1.33 +
    1.34 +// class Activity::Bucket
    1.35 +
    1.36 +inline Activity::Bucket::Bucket(unsigned aPeriod,int aThread)
    1.37 +	:iPeriod(aPeriod),iThread(aThread)
    1.38 +	{}
    1.39 +
    1.40 +bool Activity::Bucket::operator<(const Bucket& aRhs) const
    1.41 +	{
    1.42 +	if (iPeriod != aRhs.iPeriod)
    1.43 +		return iPeriod < aRhs.iPeriod;
    1.44 +	return iThread < aRhs.iThread;
    1.45 +	}
    1.46 +
    1.47 +// class Activity::ThreadData
    1.48 +
    1.49 +inline Activity::ThreadData::ThreadData(const Thread& aThread)
    1.50 +	:iThread(&aThread), iTotal(0)
    1.51 +	{}
    1.52 +
    1.53 +inline Activity::ThreadData::ThreadData(unsigned aCutoff)
    1.54 +	:iTotal(aCutoff)
    1.55 +	{}
    1.56 +
    1.57 +inline bool Activity::ThreadData::operator<(const ThreadData& aRhs) const
    1.58 +	{
    1.59 +	return iTotal < aRhs.iTotal;
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +// class Activity
    1.64 +
    1.65 +
    1.66 +Activity::Activity(int aBucketSize, unsigned aBeginSample, double aCutOff)
    1.67 +	:iBucketSize(aBucketSize), iBeginSample(aBeginSample), iCutOff(aCutOff)
    1.68 +	{
    1.69 +	cout << "Execution activity\n\n";
    1.70 +	}
    1.71 +
    1.72 +void Activity::Sample(unsigned aNumber, const Thread& aThread, PC)
    1.73 +	{
    1.74 +	if (aThread.iIndex == iThreads.size())
    1.75 +		iThreads.push_back(ThreadData(aThread));
    1.76 +
    1.77 +	++iThreads[aThread.iIndex].iTotal;
    1.78 +	++iData[Bucket((aNumber - iBeginSample) / iBucketSize, aThread.iIndex)];
    1.79 +	} 
    1.80 +
    1.81 +void Activity::Complete(unsigned aTotal, unsigned aActive)
    1.82 +	{
    1.83 +	cout.setf(ios::fixed, ios::floatfield);
    1.84 +	cout << setfill(' ');
    1.85 +	cout.precision(2);
    1.86 +	const char* emptySeparator;
    1.87 +	const char* separator;
    1.88 +//
    1.89 +	const unsigned ixCount = iThreads.size();
    1.90 +	int* remap = new int[ixCount];
    1.91 +	std::fill(remap, remap + ixCount, -1);
    1.92 +
    1.93 +	std::sort(iThreads.begin(), iThreads.end());
    1.94 +	Threads::iterator cutoff = std::lower_bound(iThreads.begin(), iThreads.end(), ThreadData(iCutOff * aTotal * 0.01));
    1.95 +	iThreads.erase(iThreads.begin(), cutoff);
    1.96 +
    1.97 +	const unsigned disCount = iThreads.size();
    1.98 +	for (int ix = 0; ix < disCount; ++ix)
    1.99 +		remap[iThreads[ix].iThread->iIndex] = ix;
   1.100 +
   1.101 +
   1.102 +	if (Analyse::Format() != Analyse::EExcel)
   1.103 +		{
   1.104 +		cout << "ID  Thread name\n";
   1.105 +		int ix;
   1.106 +		for (ix = 0; ix < disCount; ++ix)
   1.107 +			cout << char('A' + ix) << "  " << *iThreads[ix].iThread << '\n';
   1.108 +
   1.109 +		cout << "\nsample  ";
   1.110 +		for (ix = 0; ix < disCount; ++ix)
   1.111 +			cout << setw(4) << char('A' + ix) << "    ";
   1.112 +		cout << "\n\n";
   1.113 +		separator = " ";
   1.114 +		emptySeparator = "        ";
   1.115 +		}
   1.116 +	else
   1.117 +		{
   1.118 +		cout << "sample";
   1.119 +		for (int ix = 0; ix < disCount; ++ix)
   1.120 +			cout << '\t' << *iThreads[ix].iThread;
   1.121 +		cout << '\n';
   1.122 +		separator = emptySeparator = "\t";
   1.123 +		}
   1.124 +
   1.125 +	unsigned* totals = new unsigned[disCount];
   1.126 +	std::fill(totals, totals + disCount, 0);
   1.127 +	unsigned period = 0;
   1.128 +	bool values = false;
   1.129 +	for (Data::iterator p = iData.begin(), e = iData.end(); p != e; ++p)
   1.130 +		{
   1.131 +		while (period != p->first.iPeriod)
   1.132 +			{
   1.133 +			cout << setw(7) << (period * iBucketSize) + iBeginSample;
   1.134 +			if (values)
   1.135 +				{
   1.136 +				for (int ix = 0; ix < disCount; ++ix)
   1.137 +					cout <<	separator << Result(totals[ix], iBucketSize);
   1.138 +				std::fill(totals, totals + disCount, 0);
   1.139 +				values = false;
   1.140 +				}
   1.141 +			cout << '\n';
   1.142 +			++period;
   1.143 +			}
   1.144 +		int ix = remap[p->first.iThread];
   1.145 +		if (ix >= 0)
   1.146 +			{
   1.147 +			totals[ix] = p->second;
   1.148 +			values = true;
   1.149 +			}
   1.150 +		}
   1.151 +	if (values)
   1.152 +		{
   1.153 +		cout << setw(7) << (period * iBucketSize) + iBeginSample;
   1.154 +		for (int ix = 0; ix < disCount; ++ix)
   1.155 +			cout <<	separator << Result(totals[ix], iBucketSize);
   1.156 +		cout << '\n';
   1.157 +		}
   1.158 +
   1.159 +	delete [] remap;
   1.160 +	delete [] totals;
   1.161 +	}