This page was last modified 08:33, 29 June 2007.
Monitoring RAM
From Forum Nokia Wiki
This simple control allows you to monitor available RAM in your mobile. To use it, just instantiate the control and set a timer to periodically invoke the plot function:
// The view owns the RAM control
void CSystemView::CmdStartTimers()
{
iRAMControl->Reset();
DrawDeferred();
const TInt KUpdateInterval = 1000000; // 1 sec
iUpdateTimer->Start(KUpdateInterval, KUpdateInterval, TCallBack(DoUpdateL, this));
}
TInt CSystemView::DoUpdateL(TAny* aPtr)
{
CSystemView* self = static_cast<CSystemView*>(aPtr);
self->iRAMControl->PlotL();
return 0;
}
The RAM monitor control class:
#include <coecntrl.h> // CCoeControl
class CRAMControl : public CCoeControl
{
public:
void ConstructL(const TRect& aRect, const CCoeControl* aParent);
~CRAMControl();
void Reset();
void PlotL();
private:
void Draw(const TRect& aRect) const;
void SizeChanged();
private:
CArrayFix<TInt>* iFreeRAMList;
TInt iFreeRAM;
TReal32 iTotalRAM;
CArrayFix<TPoint>* iPointList;
TRect iPaintRect;
HBufC* iFreeRAMText;
};
#include "RAMControl.h"
#include <YourApp.rsg> // Define r_text_free_ram, etc
#include <coemain.h> // CCoeEnv
#include <eikenv.h> // CEikonEnv
#include <hal.h>
void CRAMControl::ConstructL(const TRect& aRect, const CCoeControl* aParent)
{
if (aParent == 0)
CreateWindowL();
else
SetContainerWindowL(*aParent);
iFreeRAMList = new(ELeave) CArrayFixSeg<TInt>(5);
iPointList = new(ELeave) CArrayFixFlat<TPoint>(5);
iFreeRAMText = iCoeEnv->AllocReadResourceL(R_TEXT_FREE_RAM);
SetRect(aRect);
ActivateL();
}
CRAMControl::~CRAMControl()
{
delete iFreeRAMText;
delete iPointList;
delete iFreeRAMList;
}
void CRAMControl::Reset()
{
iFreeRAMList->Reset();
iTotalRAM = 0;
iPointList->Reset();
}
void CRAMControl::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.Clear(iPaintRect);
gc.SetClippingRect(iPaintRect);
gc.SetPenColor(KRgbRed);
gc.DrawPolyLine(iPointList);
gc.SetPenColor(KRgbBlack);
gc.DrawRect(iPaintRect);
const CFont* font = iEikonEnv->LegendFont();
gc.UseFont(font);
TInt freeRam = 0;
HAL::Get(HAL::EMemoryRAMFree, freeRam);
TBuf<64> freeRAMText;
freeRAMText.Format(*iFreeRAMText, freeRam >> 10);
gc.DrawText(freeRAMText, iPaintRect, iPaintRect.Height() -
font->DescentInPixels(), CGraphicsContext::ERight);
gc.DiscardFont();
}
void CRAMControl::SizeChanged()
{
iPaintRect = Rect();
iPaintRect.Shrink(5, 5);
}
void CRAMControl::PlotL()
{
HAL::Get(HAL::EMemoryRAMFree, iFreeRAM);
// In case there's a new maximum of free memory, resize graphic
TInt possibleMax = static_cast<TInt> (iFreeRAM * 1.2);
if (possibleMax > iTotalRAM)
iTotalRAM = possibleMax;
if (iFreeRAMList->Count() == iPaintRect.Width() - 2)
iFreeRAMList->Delete(0);
iFreeRAMList->AppendL(iFreeRAM);
iPointList->Reset();
for (TInt i = 0; i < iFreeRAMList->Count(); ++i)
{
TInt x = iPaintRect.iBr.iX - 1 - iFreeRAMList->Count() + i;
TInt y = iPaintRect.iBr.iY - 1 -
static_cast<TInt> (iPaintRect.Height() * (iFreeRAMList->At(i) / iTotalRAM));
iPointList->AppendL(TPoint(x, y));
}
DrawDeferred();
}
You can check TaskSpy source code to see how this works.
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Monitoring if apps are On or Off | gemilib | Mobile Java General | 2 | 2007-10-09 20:57 |
| Monitoring processor idle time | AnthonyAndrews | General Symbian C++ | 7 | 2007-09-05 08:09 |
| Access Data from file as fast as from ram? | Joe_Joechler | General Symbian C++ | 0 | 2006-09-21 10:01 |
| Why I can't free my allocated buffer? | cidhx | General Symbian C++ | 7 | 2004-01-08 08:50 |
| Windows Mobile For NOKIA Cell Phones | SKR | General Discussion | 48 | 2008-08-02 00:08 |
