libraries/qr3/src/threadListboxdata.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // threadListboxdata.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 #include "KernLbxModel.h"
       
    13 #include "Utils.h"
       
    14 #include <fshell/clogger.h>
       
    15 #include <fshell/memoryaccess.h>
       
    16 #include <fshell/qr3dll.h>
       
    17 #include "QResources3.hrh"
       
    18 #include <fshell/heaputils.h>
       
    19 
       
    20 CThreadsListBoxData::CThreadsListBoxData(CKernListBoxModel* aModel)
       
    21 	: CKernListBoxData(aModel)
       
    22 	{
       
    23 	}
       
    24 
       
    25 void CThreadsListBoxData::DoFormatL(TObjectKernelInfo* aInfo, RBuf& name, RBuf& more, TInt& itemId)
       
    26 	{
       
    27 	TThreadKernelInfo& info = *(TThreadKernelInfo*)aInfo;
       
    28 	name.Copy(info.iFullName);
       
    29 	PrettyName(iType, name);
       
    30 
       
    31 	TUint tid = info.iThreadId;
       
    32 	TExitType exitType = EExitPending;
       
    33 	RThread thread;
       
    34 	if (Model().MemAccess().RThreadForceOpen(thread, tid) == KErrNone)
       
    35 		{
       
    36 		exitType = thread.ExitType();
       
    37 		}
       
    38 	if (exitType == EExitPending)
       
    39 		{
       
    40 		more.Format(_L("Tid %i"), tid);
       
    41 		}
       
    42 	else
       
    43 		{
       
    44 		TExitCategoryName cat = thread.ExitCategory();
       
    45 		more.Format(_L("Tid %i %S %i"), tid, &cat, thread.ExitReason());
       
    46 		}
       
    47 	thread.Close();
       
    48 	itemId = tid;
       
    49 	}
       
    50 
       
    51 void CThreadsListBoxData::DumpToCloggerL(RClogger& clogger, TInt i, TInt /*count*/)
       
    52 	{
       
    53 	_LIT8(KThreadDesc,"Thread;FullName;Tid;Priority;(PriorityHumanReadable);ParentPid;StackSize;(StackSizeHumanReadable);HeapSize;(HeapSizeHumanReadable);MinHeapSize;(MinHumanReadable);UnusedPages;LostBytes;(LostBytesHumanReadable);ExitStatus;ExitCategory;ExitReason;KernObjAddr");
       
    54 	_LIT8(KThreadFmt,"Thread;%S;%i;%i;(%S);%i;%i;(%S);%i;(%S);%i;(%S);%i;%i;(%S);%S;%S;%i;%x");
       
    55 	//                                                    ^ HeapSizeHumanReadable
       
    56 	if (i == 0) clogger.Log(KThreadDesc);
       
    57 	TThreadKernelInfo& info = *(TThreadKernelInfo*)iInfo;
       
    58 
       
    59 	TBuf<16> priority16 = ToString((TThreadPriority)info.iThreadPriority);
       
    60 	TPtr8 priority = priority16.Collapse();
       
    61 	
       
    62 	LtkUtils::RProxyAllocatorHelper allocHelper;
       
    63 	User::LeaveIfError(allocHelper.Open(Model().MemAccess(), info.iThreadId));
       
    64 	TBuf8<16> heapSize, minHeap, lostBytes, stackSize;
       
    65 	HR(heapSize, allocHelper.CommittedSize());
       
    66 	HR(stackSize, info.iUserStackSize);
       
    67 	HR(minHeap, allocHelper.MinCommittedSize());
       
    68 	TInt lostBytesCount = allocHelper.CommittedFreeSpace();
       
    69 	HR(lostBytes, lostBytesCount);
       
    70 	TInt parentPid = 0; //TODO
       
    71 	TPtrC exitStatus;
       
    72 	TInt exitReason = 0;
       
    73 	TExitCategoryName exitCategory;
       
    74 	RThread handle;
       
    75 	if (Model().MemAccess().RThreadForceOpen(handle, info.iThreadId) == KErrNone)
       
    76 		{
       
    77 		exitStatus.Set(ToString(handle.ExitType()));
       
    78 		exitCategory = handle.ExitCategory();
       
    79 		exitReason = handle.ExitReason();
       
    80 		handle.Close();
       
    81 		}
       
    82 	TBuf8<16> exitStatus8;
       
    83 	exitStatus8.Copy(exitStatus);
       
    84 	TPtrC8 exitCategory8 = exitCategory.Collapse();
       
    85 	clogger.Log(KThreadFmt, &info.iFullName, info.iThreadId, info.iThreadPriority, &priority, parentPid, info.iUserStackSize, &stackSize, allocHelper.CommittedSize(), &heapSize, allocHelper.MinCommittedSize(), &minHeap, allocHelper.CountUnusedPages(), lostBytesCount, &lostBytes, &exitStatus8, &exitCategory8, exitReason, info.iAddressOfKernelObject);
       
    86 	allocHelper.Close();
       
    87 	}
       
    88 
       
    89 void CThreadsListBoxData::DoInfoForDialogL(RBuf& aTitle, RBuf& inf, TDes* aTemp)
       
    90 	{
       
    91 	TThreadKernelInfo& info = *(TThreadKernelInfo*)iInfo;
       
    92 	RThread thread;
       
    93 	RProcess process;
       
    94 	TInt err = Model().MemAccess().RThreadForceOpen(thread, info.iThreadId);
       
    95 	if (!err)
       
    96 		{
       
    97 		err = thread.Process(process);
       
    98 		}
       
    99 	TUint processId = err;
       
   100 	if (!err)
       
   101 		{
       
   102 		processId = (TUint)process.Id();
       
   103 		}
       
   104 	CleanupClosePushL(thread);
       
   105 	CleanupClosePushL(process);
       
   106 
       
   107 	_LIT(KInfo, "Thread info");
       
   108 	aTitle.Copy(KInfo);
       
   109 	inf.Copy(iInfo->iFullName);
       
   110 	inf.Append(Klflf);
       
   111 	
       
   112 	_LIT(KThread, "Tid: %d Pid: %d Kern Priority: %d\nPriority: %d (%S)\nProc Priority: %d (%S)");
       
   113 	_LIT(KCritical, "\n%S");
       
   114 	_LIT(KCreator, "\nCreator thread id: %d (%S)");
       
   115 	_LIT(KKern, "\nKernel object address: 0x%08x");
       
   116 	_LIT(KStack, "\n\nUser stack size: %S");
       
   117 	_LIT(KHeap, "\nAllocator: 0x%08x\nHeap size: %S (%d)\nMin/Max: %S/%S\nUnused: %S Usable: %S");
       
   118 	_LIT(KDied, "\n\nDied with: %S %S %i");
       
   119 
       
   120 	TThreadPriority threadPriority = (TThreadPriority)err;
       
   121 	TProcessPriority processPriority = (TProcessPriority)err;
       
   122 	TPtrC priority = _L("?");
       
   123 	TPtrC priorityP = _L("?");
       
   124 	if (!err)
       
   125 		{
       
   126 		threadPriority = thread.Priority();
       
   127 		priority.Set(ToString(threadPriority));
       
   128 		processPriority = process.Priority();
       
   129 		priorityP.Set(ToString(processPriority));
       
   130 		}
       
   131 	LtkUtils::RProxyAllocatorHelper allocHelper;
       
   132 	User::LeaveIfError(allocHelper.Open(Model().MemAccess(), info.iThreadId));
       
   133 	TBuf<16> heapSize, minHeap, maxHeap, unusedMem, reclaimableMem, stackSize;
       
   134 	HR(heapSize, allocHelper.CommittedSize());
       
   135 	HR(stackSize, info.iUserStackSize);
       
   136 	HR(minHeap, allocHelper.MinCommittedSize());
       
   137 	HR(maxHeap, allocHelper.MaxCommittedSize());
       
   138 	HR(unusedMem, allocHelper.CommittedFreeSpace());
       
   139 	HR(reclaimableMem, allocHelper.CountUnusedPages() * 4096);
       
   140 	inf.AppendFormat(KThread, info.iThreadId, processId, info.iThreadPriority, threadPriority, &priority, processPriority, &priorityP);
       
   141 
       
   142 	TUint creatorTid = Model().MemAccess().GetThreadCreatorId(info.iThreadId);
       
   143 	if (creatorTid != 0)
       
   144 		{
       
   145 		RThread creator;
       
   146 		TInt err = Model().MemAccess().RThreadForceOpen(creator, creatorTid);
       
   147 		*aTemp = _L("?");
       
   148 		if (err == KErrNone)
       
   149 			{
       
   150 			*aTemp = creator.FullName();
       
   151 			PrettyName(iType, *aTemp);
       
   152 			creator.Close();
       
   153 			}
       
   154 		inf.AppendFormat(KCreator, creatorTid, aTemp);
       
   155 		}
       
   156 
       
   157 	User::TCritical crit = User::ENotCritical;
       
   158 	if (!err)
       
   159 		{
       
   160 		crit = User::Critical(thread);
       
   161 		}
       
   162 	if (crit != User::ENotCritical)
       
   163 		{
       
   164 		TPtrC critical = ToString(crit);
       
   165 		inf.AppendFormat(KCritical, &critical);
       
   166 		}
       
   167 	inf.AppendFormat(KKern, info.iAddressOfKernelObject);
       
   168 
       
   169 	inf.AppendFormat(KStack, &stackSize);
       
   170 	inf.AppendFormat(KHeap, allocHelper.AllocatorAddress(), &heapSize, allocHelper.CommittedSize(), &minHeap, &maxHeap, &unusedMem, &reclaimableMem);
       
   171 	allocHelper.Close();
       
   172 	if (err == KErrNone && thread.ExitType() != EExitPending)
       
   173 		{
       
   174 		TPtrC exitStatus;
       
   175 		TInt exitReason = 0;
       
   176 		TExitCategoryName exitCategory;
       
   177 		exitStatus.Set(ToString(thread.ExitType()));
       
   178 		if (thread.ExitType() == EExitPanic)
       
   179 			{
       
   180 			exitCategory = thread.ExitCategory();
       
   181 			}
       
   182 		exitReason = thread.ExitReason();
       
   183 		inf.AppendFormat(KDied, &exitStatus, &exitCategory, exitReason);
       
   184 		}
       
   185 	CleanupStack::PopAndDestroy(2, &thread);
       
   186 	}
       
   187 
       
   188 TBool CThreadsListBoxData::SupportsCommand(TInt aCommand)
       
   189 	{
       
   190 	switch (aCommand)
       
   191 		{
       
   192 		case ECmdHandleInfo:
       
   193 		case ECmdKill:
       
   194 		case ECmdDumpHeap:
       
   195 		case ECmdSetCritical:
       
   196 		case ECmdSetPriority:
       
   197 		case ECmdPoll:
       
   198 			return ETrue;
       
   199 		default:
       
   200 			return EFalse;
       
   201 		}
       
   202 	}
       
   203 
       
   204