os/kernelhwsrv/kerneltest/e32utils/analyse/activity.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "analyse.h"
sl@0
    17
#include "activity.h"
sl@0
    18
#include "output.h"
sl@0
    19
sl@0
    20
#ifdef __MSVCDOTNET__
sl@0
    21
#include <ostream>
sl@0
    22
#include <iomanip>
sl@0
    23
#else //!__MSVCDOTNET__
sl@0
    24
#include <ostream.h>
sl@0
    25
#include <iomanip.h>
sl@0
    26
#endif //__MSVCDOTNET__
sl@0
    27
sl@0
    28
#include <algorithm>
sl@0
    29
sl@0
    30
sl@0
    31
// class Activity::Bucket
sl@0
    32
sl@0
    33
inline Activity::Bucket::Bucket(unsigned aPeriod,int aThread)
sl@0
    34
	:iPeriod(aPeriod),iThread(aThread)
sl@0
    35
	{}
sl@0
    36
sl@0
    37
bool Activity::Bucket::operator<(const Bucket& aRhs) const
sl@0
    38
	{
sl@0
    39
	if (iPeriod != aRhs.iPeriod)
sl@0
    40
		return iPeriod < aRhs.iPeriod;
sl@0
    41
	return iThread < aRhs.iThread;
sl@0
    42
	}
sl@0
    43
sl@0
    44
// class Activity::ThreadData
sl@0
    45
sl@0
    46
inline Activity::ThreadData::ThreadData(const Thread& aThread)
sl@0
    47
	:iThread(&aThread), iTotal(0)
sl@0
    48
	{}
sl@0
    49
sl@0
    50
inline Activity::ThreadData::ThreadData(unsigned aCutoff)
sl@0
    51
	:iTotal(aCutoff)
sl@0
    52
	{}
sl@0
    53
sl@0
    54
inline bool Activity::ThreadData::operator<(const ThreadData& aRhs) const
sl@0
    55
	{
sl@0
    56
	return iTotal < aRhs.iTotal;
sl@0
    57
	}
sl@0
    58
sl@0
    59
sl@0
    60
// class Activity
sl@0
    61
sl@0
    62
sl@0
    63
Activity::Activity(int aBucketSize, unsigned aBeginSample, double aCutOff)
sl@0
    64
	:iBucketSize(aBucketSize), iBeginSample(aBeginSample), iCutOff(aCutOff)
sl@0
    65
	{
sl@0
    66
	cout << "Execution activity\n\n";
sl@0
    67
	}
sl@0
    68
sl@0
    69
void Activity::Sample(unsigned aNumber, const Thread& aThread, PC)
sl@0
    70
	{
sl@0
    71
	if (aThread.iIndex == iThreads.size())
sl@0
    72
		iThreads.push_back(ThreadData(aThread));
sl@0
    73
sl@0
    74
	++iThreads[aThread.iIndex].iTotal;
sl@0
    75
	++iData[Bucket((aNumber - iBeginSample) / iBucketSize, aThread.iIndex)];
sl@0
    76
	} 
sl@0
    77
sl@0
    78
void Activity::Complete(unsigned aTotal, unsigned aActive)
sl@0
    79
	{
sl@0
    80
	cout.setf(ios::fixed, ios::floatfield);
sl@0
    81
	cout << setfill(' ');
sl@0
    82
	cout.precision(2);
sl@0
    83
	const char* emptySeparator;
sl@0
    84
	const char* separator;
sl@0
    85
//
sl@0
    86
	const unsigned ixCount = iThreads.size();
sl@0
    87
	int* remap = new int[ixCount];
sl@0
    88
	std::fill(remap, remap + ixCount, -1);
sl@0
    89
sl@0
    90
	std::sort(iThreads.begin(), iThreads.end());
sl@0
    91
	Threads::iterator cutoff = std::lower_bound(iThreads.begin(), iThreads.end(), ThreadData(iCutOff * aTotal * 0.01));
sl@0
    92
	iThreads.erase(iThreads.begin(), cutoff);
sl@0
    93
sl@0
    94
	const unsigned disCount = iThreads.size();
sl@0
    95
	for (int ix = 0; ix < disCount; ++ix)
sl@0
    96
		remap[iThreads[ix].iThread->iIndex] = ix;
sl@0
    97
sl@0
    98
sl@0
    99
	if (Analyse::Format() != Analyse::EExcel)
sl@0
   100
		{
sl@0
   101
		cout << "ID  Thread name\n";
sl@0
   102
		int ix;
sl@0
   103
		for (ix = 0; ix < disCount; ++ix)
sl@0
   104
			cout << char('A' + ix) << "  " << *iThreads[ix].iThread << '\n';
sl@0
   105
sl@0
   106
		cout << "\nsample  ";
sl@0
   107
		for (ix = 0; ix < disCount; ++ix)
sl@0
   108
			cout << setw(4) << char('A' + ix) << "    ";
sl@0
   109
		cout << "\n\n";
sl@0
   110
		separator = " ";
sl@0
   111
		emptySeparator = "        ";
sl@0
   112
		}
sl@0
   113
	else
sl@0
   114
		{
sl@0
   115
		cout << "sample";
sl@0
   116
		for (int ix = 0; ix < disCount; ++ix)
sl@0
   117
			cout << '\t' << *iThreads[ix].iThread;
sl@0
   118
		cout << '\n';
sl@0
   119
		separator = emptySeparator = "\t";
sl@0
   120
		}
sl@0
   121
sl@0
   122
	unsigned* totals = new unsigned[disCount];
sl@0
   123
	std::fill(totals, totals + disCount, 0);
sl@0
   124
	unsigned period = 0;
sl@0
   125
	bool values = false;
sl@0
   126
	for (Data::iterator p = iData.begin(), e = iData.end(); p != e; ++p)
sl@0
   127
		{
sl@0
   128
		while (period != p->first.iPeriod)
sl@0
   129
			{
sl@0
   130
			cout << setw(7) << (period * iBucketSize) + iBeginSample;
sl@0
   131
			if (values)
sl@0
   132
				{
sl@0
   133
				for (int ix = 0; ix < disCount; ++ix)
sl@0
   134
					cout <<	separator << Result(totals[ix], iBucketSize);
sl@0
   135
				std::fill(totals, totals + disCount, 0);
sl@0
   136
				values = false;
sl@0
   137
				}
sl@0
   138
			cout << '\n';
sl@0
   139
			++period;
sl@0
   140
			}
sl@0
   141
		int ix = remap[p->first.iThread];
sl@0
   142
		if (ix >= 0)
sl@0
   143
			{
sl@0
   144
			totals[ix] = p->second;
sl@0
   145
			values = true;
sl@0
   146
			}
sl@0
   147
		}
sl@0
   148
	if (values)
sl@0
   149
		{
sl@0
   150
		cout << setw(7) << (period * iBucketSize) + iBeginSample;
sl@0
   151
		for (int ix = 0; ix < disCount; ++ix)
sl@0
   152
			cout <<	separator << Result(totals[ix], iBucketSize);
sl@0
   153
		cout << '\n';
sl@0
   154
		}
sl@0
   155
sl@0
   156
	delete [] remap;
sl@0
   157
	delete [] totals;
sl@0
   158
	}