windowing/windowserver/nga/SERVER/debugbar.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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 "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 // Debug bar
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "debugbar.h"
       
    19 #include <bitstd.h>
       
    20 #include "screen.h"
       
    21 #include "wstop.h"
       
    22 #include <e32cmn.h>
       
    23 #include "walkwindowtree.h"	
       
    24 #include "rootwin.h"
       
    25 
       
    26 CDebugBar* CDebugBar::NewL(CScreen * aScreen, TTimeIntervalMicroSeconds32 aRefreshInterval)
       
    27 	{
       
    28 	CDebugBar* self = new(ELeave) CDebugBar(aScreen);
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL(aRefreshInterval);
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 CDebugBar::~CDebugBar()
       
    36 	{
       
    37 	delete iTimer;	
       
    38 	}
       
    39 	
       
    40 CDebugBar::CDebugBar(CScreen * aScreen) : iScreen(aScreen)
       
    41 	{
       
    42 	}
       
    43 	
       
    44 void CDebugBar::ConstructL(TTimeIntervalMicroSeconds32 aRefreshInterval)
       
    45 	{
       
    46 	iTimer = CPeriodic::NewL(EPriorityNormal);
       
    47 	iTimer->Start(TTimeIntervalMicroSeconds32(3000000),aRefreshInterval,TCallBack(RedrawDebugBarCallback, this));
       
    48 	}
       
    49 	
       
    50 TBool CDebugBar::RedrawDebugBarCallback(TAny * aAny)
       
    51 	{
       
    52 	CDebugBar* self = reinterpret_cast<CDebugBar *>(aAny);
       
    53 	self->iPolls++; //minus-out the events which cause this debug-bar to 'tick'
       
    54 	self->iScreen->ScheduleRender(0);
       
    55 	return ETrue;
       
    56 	}
       
    57 	
       
    58 void CDebugBar::DebugBarInfo(RArray<TPtrC>& aArray) const
       
    59 	{	
       
    60 	_LIT(KLine1Format, "KeyEvents %d; %Ld; WServ %.1f%%; Drawing %.1f%%; Reclaimed %.1f%%");
       
    61 	_LIT(KLine2Format, "RedrawStore size %d3B; updates %d/s, pixels %d/s"); 
       
    62 	CWsActiveScheduler* scheduler = CWsActiveScheduler::Static();
       
    63 	TInt updatesPerSecond;
       
    64 	TInt64 pixelsPerSecond;
       
    65 	scheduler->DrawStats(updatesPerSecond,pixelsPerSecond,2);
       
    66 
       
    67 	TInt64 wserv = scheduler->Total() - iLastTotal;
       
    68 	TInt64 nonwserv = scheduler->Idle() - iLastIdle;
       
    69 	TInt64 drawing = scheduler->Drawing() - iLastDrawing;
       
    70 	TInt64 reclaimed = scheduler->ReclaimedIdleTime() - iLastReclaimedIdleTime;
       
    71 	TReal wservPercent =  wserv+nonwserv? ((TReal)wserv / (TReal)(wserv + nonwserv)) * 100.0 : 0.0 ;
       
    72 	TReal drawingPercent = wserv? ((TReal)drawing / (TReal)wserv) * 100.0: 0 ;
       
    73 	TReal reclaimedPercent = wserv+nonwserv? ((TReal)reclaimed / (TReal)(wserv + nonwserv)) * 100.0: 100.0 ;
       
    74 		
       
    75 	TWalkWindowTreeRedrawStoreSize redrawStoreWalker;
       
    76 	iScreen->RootWindow()->WalkWindowTree(redrawStoreWalker, EWalkChildrenAndBehind);
       
    77 		
       
    78 	iTextLine0.Format(KLine1Format,iKeyEvents,scheduler->Requests()-iPolls,wservPercent,drawingPercent,reclaimedPercent);
       
    79 	iTextLine1.Format(KLine2Format,redrawStoreWalker.iTotalSize, updatesPerSecond, pixelsPerSecond);
       
    80 		
       
    81 	iLastTotal=scheduler->Total();
       
    82 	iLastIdle=scheduler->Idle();
       
    83 	iLastDrawing=scheduler->Drawing();
       
    84 	iLastReclaimedIdleTime=scheduler->ReclaimedIdleTime();	
       
    85 			
       
    86 	aArray.Reset();
       
    87 	TPtrC ptr(iTextLine0);
       
    88 	aArray.Append(ptr);
       
    89 	ptr.Set(iTextLine1);
       
    90 	aArray.Append(ptr);	
       
    91 	}
       
    92 
       
    93 void CDebugBar::OnKeyEvent()
       
    94 	{
       
    95 	iKeyEvents++;
       
    96 	iScreen->ScheduleRender(0);
       
    97 	}
       
    98 
       
    99