sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32utils\demandpaging\dptestcons.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: CConsoleBase* TheConsole; sl@0: sl@0: sl@0: void doHelp() sl@0: { sl@0: TheConsole->Printf(_L("Usage: dptestcons [-h] [-o] [-f] [-sMIN,MAX]\n")); sl@0: TheConsole->Printf(_L("\n")); sl@0: TheConsole->Printf(_L("-h Prints this help information\n")); sl@0: TheConsole->Printf(_L("-o Prints all DPTest information\n")); sl@0: TheConsole->Printf(_L("-f Flushes the Demand Paging cache\n")); sl@0: TheConsole->Printf(_L("-s Sets the Demand Paging cache size (MIN and MAX in bytes)\n")); sl@0: } sl@0: sl@0: void doDPTestInformation() sl@0: { sl@0: TheConsole->Printf(_L("DPTest information\n==================\n")); sl@0: TUint32 attribs = DPTest::Attributes(); sl@0: _LIT(KOn, "ON"); sl@0: _LIT(KOff, "OFF"); sl@0: TheConsole->Printf(_L("ROM Paging: %S\n"), (attribs&DPTest::ERomPaging) ? &KOn : &KOff); sl@0: TheConsole->Printf(_L("Code Paging: %S\n"), (attribs&DPTest::ECodePaging) ? &KOn : &KOff); sl@0: TheConsole->Printf(_L("Data Paging: %S\n"), (attribs&DPTest::EDataPaging) ? &KOn : &KOff); sl@0: TUint min; sl@0: TUint max; sl@0: TUint current; sl@0: TInt err = DPTest::CacheSize(min, max, current); sl@0: if (err == KErrNone) sl@0: { sl@0: TheConsole->Printf(_L("CacheSize: Min=%u, Max=%u, Current=%u\n"), min, max, current); sl@0: } sl@0: else sl@0: { sl@0: TheConsole->Printf(_L("CacheSize failed with err=%d\n"), err); sl@0: } sl@0: TPckgBuf eventPckg; sl@0: err = DPTest::EventInfo(eventPckg); sl@0: if (err == KErrNone) sl@0: { sl@0: TheConsole->Printf(_L("EventInfo: PageFaultCount=%Lu, PageInCount=%Lu\n"), eventPckg().iPageFaultCount, eventPckg().iPageInReadCount); sl@0: } sl@0: else sl@0: { sl@0: TheConsole->Printf(_L("EventInfo failed with err=%d\n"), err); sl@0: } sl@0: TheConsole->Printf(_L("==================\n")); sl@0: } sl@0: sl@0: void doFlushCache() sl@0: { sl@0: TInt err = DPTest::FlushCache(); sl@0: TheConsole->Printf(_L("FlushCache completed with err=%d\n"), err); sl@0: } sl@0: sl@0: void doSetCacheSize(const TDesC& aCacheSizes) sl@0: { sl@0: TLex lex(aCacheSizes); sl@0: TChar c = lex.Peek(); sl@0: while (c != 0 && c != ',') sl@0: { sl@0: lex.Inc(); sl@0: c = lex.Peek(); sl@0: } sl@0: TPtrC valDes = lex.MarkedToken(); sl@0: TUint min; sl@0: if (TLex(valDes).Val(min) != KErrNone) sl@0: { sl@0: TheConsole->Printf(_L("Bad minimum value provided for SetCacheSize: %S\n"), &valDes); sl@0: return; sl@0: } sl@0: if (c != 0) sl@0: { sl@0: lex.Inc(); sl@0: } sl@0: valDes.Set(lex.Remainder()); sl@0: TUint max; sl@0: if (TLex(valDes).Val(max) != KErrNone) sl@0: { sl@0: TheConsole->Printf(_L("Bad maximum value provided for SetCacheSize: %S\n"), &valDes); sl@0: return; sl@0: } sl@0: TInt err = DPTest::SetCacheSize(min, max); sl@0: TheConsole->Printf(_L("SetCacheSize (Min=%u, Max=%u) completed with err=%d\n"), min, max, err); sl@0: } sl@0: sl@0: void processCommands(RArray aArgArray) sl@0: { sl@0: const TInt count = aArgArray.Count(); sl@0: if (count == 0) sl@0: { sl@0: doHelp(); sl@0: return; sl@0: } sl@0: for (TInt ii=0; iiPrintf(_L("Unknown command: %S\n"), ¤t); sl@0: } sl@0: switch (current[1]) sl@0: { sl@0: case 'h': sl@0: doHelp(); sl@0: break; sl@0: case 'o': sl@0: doDPTestInformation(); sl@0: break; sl@0: case 'f': sl@0: doFlushCache(); sl@0: break; sl@0: case 's': sl@0: doSetCacheSize(current.Mid(2)); sl@0: break; sl@0: default: sl@0: TheConsole->Printf(_L("Unknown command: %S\n"), ¤t); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: // create console... sl@0: TFileName exeFile = RProcess().FileName(); sl@0: TRAPD(err, TheConsole = Console::NewL(exeFile,TSize(KConsFullScreen,KConsFullScreen))); sl@0: TheConsole->Printf(_L("---DPTESTCONS---\n")); sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: // get command-line... sl@0: RBuf clDes; sl@0: if (clDes.Create(User::CommandLineLength()+1) != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: User::CommandLine(clDes); sl@0: sl@0: // split up args... sl@0: RArray argArray; sl@0: TLex lex(clDes); sl@0: while (!lex.Eos()) sl@0: { sl@0: err = argArray.Append(lex.NextToken()); sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: } sl@0: processCommands(argArray); sl@0: sl@0: TheConsole->Printf(_L("Press any key to continue.\n")); sl@0: TheConsole->Getch(); sl@0: return 0; sl@0: }