|
1 // ramdefrag.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 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 |
|
13 #include <fshell/ioutils.h> |
|
14 #include <fshell/memoryaccesscmd.h> |
|
15 |
|
16 using namespace IoUtils; |
|
17 |
|
18 class CCmdRamDefrag : public CMemoryAccessCommandBase |
|
19 { |
|
20 public: |
|
21 static CCommandBase* NewLC(); |
|
22 ~CCmdRamDefrag(); |
|
23 private: |
|
24 CCmdRamDefrag(); |
|
25 private: // From CCommandBase. |
|
26 virtual const TDesC& Name() const; |
|
27 virtual void DoRunL(); |
|
28 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
29 virtual void OptionsL(RCommandOptionList& aOptions); |
|
30 private: |
|
31 enum TCmd |
|
32 { |
|
33 EDefrag, |
|
34 EEmptyZone, |
|
35 EZoneInfo, |
|
36 }; |
|
37 TCmd iCmd; |
|
38 RArray<TUint> iZones; |
|
39 TInt iPriority; |
|
40 TBool iCsv; |
|
41 }; |
|
42 |
|
43 EXE_BOILER_PLATE(CCmdRamDefrag) |
|
44 |
|
45 CCommandBase* CCmdRamDefrag::NewLC() |
|
46 { |
|
47 CCmdRamDefrag* self = new(ELeave) CCmdRamDefrag(); |
|
48 CleanupStack::PushL(self); |
|
49 self->BaseConstructL(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 CCmdRamDefrag::~CCmdRamDefrag() |
|
54 { |
|
55 iZones.Close(); |
|
56 } |
|
57 |
|
58 CCmdRamDefrag::CCmdRamDefrag() |
|
59 : iPriority(-1) |
|
60 { |
|
61 } |
|
62 |
|
63 const TDesC& CCmdRamDefrag::Name() const |
|
64 { |
|
65 _LIT(KName, "ramdefrag"); |
|
66 return KName; |
|
67 } |
|
68 |
|
69 void CCmdRamDefrag::ArgumentsL(RCommandArgumentList& aArguments) |
|
70 { |
|
71 aArguments.AppendEnumL((TInt&)iCmd, _L("command")); |
|
72 aArguments.AppendUintL(iZones, _L("zone")); |
|
73 } |
|
74 |
|
75 void CCmdRamDefrag::OptionsL(RCommandOptionList& aOptions) |
|
76 { |
|
77 aOptions.AppendIntL(iPriority, _L("priority")); |
|
78 aOptions.AppendBoolL(iCsv, _L("csv")); |
|
79 } |
|
80 |
|
81 void CCmdRamDefrag::DoRunL() |
|
82 { |
|
83 LoadMemoryAccessL(); |
|
84 |
|
85 switch (iCmd) |
|
86 { |
|
87 case EDefrag: |
|
88 LeaveIfErr(iMemAccess.DefragRam(iPriority), _L("Couldn't defrag RAM.")); |
|
89 break; |
|
90 case EEmptyZone: |
|
91 { |
|
92 if (iZones.Count() == 0) LeaveIfErr(KErrArgument, _L("Must specify at least one zone to empty.")); |
|
93 for (TInt i = 0; i < iZones.Count(); i++) |
|
94 { |
|
95 TUint zone = iZones[i]; |
|
96 TInt err = iMemAccess.EmptyRamZone(zone, iPriority); |
|
97 if (err) PrintError(err, _L("Failed to empty RAM zone %u"), zone); |
|
98 } |
|
99 break; |
|
100 } |
|
101 case EZoneInfo: |
|
102 if (iZones.Count() == 0) LeaveIfErr(KErrArgument, _L("Must specify at least one zone.")); |
|
103 if (iCsv) Printf(_L("Zone,Discardable pages,Fixed pages,Free pages,Movable pages,Unknown pages\r\n")); |
|
104 |
|
105 for (TInt i = 0; i < iZones.Count(); i++) |
|
106 { |
|
107 TUint zone = iZones[i]; |
|
108 TRamZoneInfo info; |
|
109 TPckg<TRamZoneInfo> infoPkg(info); |
|
110 TInt err = iMemAccess.GetRamZoneInfo(zone, infoPkg); |
|
111 if (err) |
|
112 { |
|
113 PrintError(err, _L("Failed to get info for RAM zone %u"), zone); |
|
114 } |
|
115 else |
|
116 { |
|
117 if (iCsv) |
|
118 { |
|
119 Printf(_L("%u,%d,%d,%d,%d,%d\r\n"), zone, info.iDiscardablePages, info.iFixedPages, info.iFreePages, info.iMovablePages, info.iUnknownPages); |
|
120 } |
|
121 else |
|
122 { |
|
123 Printf(_L("Zone %u:\r\nDiscardable pages: %d\r\nFixed pages: %d\r\nFree pages: %d\r\nMovable pages: %d\r\nUnknown pages: %d\r\n\r\n"), zone, info.iDiscardablePages, info.iFixedPages, info.iFreePages, info.iMovablePages, info.iUnknownPages); |
|
124 } |
|
125 } |
|
126 } |
|
127 break; |
|
128 } |
|
129 } |