kerneltest/e32utils/analyse/tracer.cpp
changeset 9 96e5fb8b040d
equal deleted inserted replaced
-1:000000000000 9:96e5fb8b040d
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "analyse.h"
       
    17 #include "tracer.h"
       
    18 #include "codespace.h"
       
    19 #include "output.h"
       
    20 #include <algorithm>
       
    21 
       
    22 #ifdef __MSVCDOTNET__
       
    23 #include <ostream>
       
    24 #include <iomanip>
       
    25 #else //!__MSVCDOTNET__
       
    26 #include <ostream.h>
       
    27 #include <iomanip.h>
       
    28 #endif //__MSVCDOTNET__
       
    29 
       
    30 Tracer::Tracer(MappedCodeSpace* aCodeSpace)
       
    31 	:iCodeSpace(aCodeSpace)
       
    32 	{
       
    33 	cout << "Thread trace\n\n";
       
    34 	cout << " Sample  TID  PC\n";
       
    35 	cout << setfill(' ');
       
    36 	}
       
    37 
       
    38 void Tracer::Sample(unsigned aNumber, const Thread& aThread, PC aPc)
       
    39 	{
       
    40 	if (aThread.iIndex >= iThreads.size())
       
    41 		iThreads.push_back(&aThread);
       
    42 	
       
    43 	cout << dec << setw(7) << aNumber << ' ' << setw(3) << aThread.iIndex << "   " << hex;
       
    44 	if (iCodeSpace != 0)
       
    45 		{
       
    46 		std::pair<const char*,PC> pc(iCodeSpace->Lookup(aPc));
       
    47 		if (pc.first != 0)
       
    48 			{
       
    49 			cout << pc.first << " + " << pc.second << '\n';
       
    50 			return;
       
    51 			}
       
    52 		}
       
    53 	cout << setw(8) << aPc << '\n';
       
    54 	}
       
    55 
       
    56 struct PrintThread
       
    57 	{
       
    58 	void operator ()(const Thread* aThread)
       
    59 		{
       
    60 		cout << dec << setw(2) << aThread->iIndex << "  " << *aThread << '\n';
       
    61 		}
       
    62 	};
       
    63 
       
    64 void Tracer::Complete(unsigned, unsigned)
       
    65 	{
       
    66 	cout << "\n\nThreads:\n";
       
    67 	std::for_each(iThreads.begin(), iThreads.end(), PrintThread());
       
    68 	}