2 If the Variable services have PcdVariableCollectStatistics set to TRUE then
3 this utility will print out the statistics information. You can use console
4 redirection to capture the data.
6 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/UefiLib.h>
19 #include <Library/UefiApplicationEntryPoint.h>
20 #include <Library/BaseMemoryLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/MemoryAllocationLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
27 #include <Guid/AuthenticatedVariableFormat.h>
28 #include <Guid/SmmVariableCommon.h>
29 #include <Protocol/SmmCommunication.h>
30 #include <Protocol/SmmVariable.h>
32 #define EFI_VARIABLE_GUID \
33 { 0xddcf3616, 0x3275, 0x4164, { 0x98, 0xb6, 0xfe, 0x85, 0x70, 0x7f, 0xfe, 0x7d } }
35 EFI_GUID mEfiVariableGuid
= EFI_VARIABLE_GUID
;
36 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
40 This function get the variable statistics data from SMM variable driver.
42 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will
43 be passed into an SMM environment. In output, a pointer
44 to a collection of data that comes from an SMM environment.
45 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.
47 @retval EFI_SUCCESS Get the statistics data information.
48 @retval EFI_NOT_FOUND Not found.
49 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
54 GetVariableStatisticsData (
55 IN OUT EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
,
56 IN OUT UINTN
*SmmCommunicateSize
60 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
62 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
63 SmmCommunicateHeader
->MessageLength
= *SmmCommunicateSize
- OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
65 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) &SmmCommunicateHeader
->Data
[0];
66 SmmVariableFunctionHeader
->Function
= SMM_VARIABLE_FUNCTION_GET_STATISTICS
;
68 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, SmmCommunicateHeader
, SmmCommunicateSize
);
69 ASSERT_EFI_ERROR (Status
);
71 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
78 This function get and print the variable statistics data from SMM variable driver.
80 @retval EFI_SUCCESS Print the statistics information successfully.
81 @retval EFI_NOT_FOUND Not found the statistics information.
90 VARIABLE_INFO_ENTRY
*VariableInfo
;
91 EFI_SMM_COMMUNICATE_HEADER
*CommBuffer
;
94 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
95 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
98 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**) &Smmvariable
);
99 if (EFI_ERROR (Status
)) {
103 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
104 if (EFI_ERROR (Status
)) {
108 CommSize
= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
109 RealCommSize
= CommSize
;
110 CommBuffer
= AllocateZeroPool (CommSize
);
111 ASSERT (CommBuffer
!= NULL
);
113 Print (L
"Non-Volatile SMM Variables:\n");
115 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
116 if (Status
== EFI_BUFFER_TOO_SMALL
) {
117 FreePool (CommBuffer
);
118 CommBuffer
= AllocateZeroPool (CommSize
);
119 ASSERT (CommBuffer
!= NULL
);
120 RealCommSize
= CommSize
;
121 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
124 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
128 if (CommSize
< RealCommSize
) {
129 CommSize
= RealCommSize
;
132 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
133 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
135 if (!VariableInfo
->Volatile
) {
137 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
138 &VariableInfo
->VendorGuid
,
139 VariableInfo
->ReadCount
,
140 VariableInfo
->CacheCount
,
141 VariableInfo
->WriteCount
,
142 VariableInfo
->DeleteCount
,
143 (CHAR16
*)(VariableInfo
+ 1)
148 Print (L
"Volatile SMM Variables:\n");
149 ZeroMem (CommBuffer
, CommSize
);
151 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
152 if (Status
== EFI_BUFFER_TOO_SMALL
) {
153 FreePool (CommBuffer
);
154 CommBuffer
= AllocateZeroPool (CommSize
);
155 ASSERT (CommBuffer
!= NULL
);
156 RealCommSize
= CommSize
;
157 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
160 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
164 if (CommSize
< RealCommSize
) {
165 CommSize
= RealCommSize
;
168 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
169 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
171 if (VariableInfo
->Volatile
) {
173 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
174 &VariableInfo
->VendorGuid
,
175 VariableInfo
->ReadCount
,
176 VariableInfo
->CacheCount
,
177 VariableInfo
->WriteCount
,
178 VariableInfo
->DeleteCount
,
179 (CHAR16
*)(VariableInfo
+ 1)
184 FreePool (CommBuffer
);
189 The user Entry Point for Application. The user code starts with this function
190 as the real entry point for the image goes into a library that calls this
193 @param[in] ImageHandle The firmware allocated handle for the EFI image.
194 @param[in] SystemTable A pointer to the EFI System Table.
196 @retval EFI_SUCCESS The entry point is executed successfully.
197 @retval other Some error occurs when executing this entry point.
203 IN EFI_HANDLE ImageHandle
,
204 IN EFI_SYSTEM_TABLE
*SystemTable
208 VARIABLE_INFO_ENTRY
*VariableInfo
;
209 VARIABLE_INFO_ENTRY
*Entry
;
211 Status
= EfiGetSystemConfigurationTable (&mEfiVariableGuid
, (VOID
**)&Entry
);
212 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
213 Status
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**)&Entry
);
216 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
217 Status
= PrintInfoFromSmm ();
218 if (!EFI_ERROR (Status
)) {
223 if (!EFI_ERROR (Status
) && (Entry
!= NULL
)) {
224 Print (L
"Non-Volatile EFI Variables:\n");
225 VariableInfo
= Entry
;
227 if (!VariableInfo
->Volatile
) {
229 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
230 &VariableInfo
->VendorGuid
,
231 VariableInfo
->ReadCount
,
232 VariableInfo
->CacheCount
,
233 VariableInfo
->WriteCount
,
234 VariableInfo
->DeleteCount
,
239 VariableInfo
= VariableInfo
->Next
;
240 } while (VariableInfo
!= NULL
);
242 Print (L
"Volatile EFI Variables:\n");
243 VariableInfo
= Entry
;
245 if (VariableInfo
->Volatile
) {
247 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
248 &VariableInfo
->VendorGuid
,
249 VariableInfo
->ReadCount
,
250 VariableInfo
->CacheCount
,
251 VariableInfo
->WriteCount
,
252 VariableInfo
->DeleteCount
,
256 VariableInfo
= VariableInfo
->Next
;
257 } while (VariableInfo
!= NULL
);
260 Print (L
"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");
261 Print (L
"If you want to see this info, please:\n");
262 Print (L
" 1. Set PcdVariableCollectStatistics as TRUE\n");
263 Print (L
" 2. Rebuild Variable Dxe driver\n");
264 Print (L
" 3. Run \"VariableInfo\" cmd again\n");