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 extern EFI_GUID gEfiVariableGuid
;
33 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
37 This function get the variable statistics data from SMM variable driver.
39 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will
40 be passed into an SMM environment. In output, a pointer
41 to a collection of data that comes from an SMM environment.
42 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.
44 @retval EFI_SUCCESS Get the statistics data information.
45 @retval EFI_NOT_FOUND Not found.
46 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
51 GetVariableStatisticsData (
52 IN OUT EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
,
53 IN OUT UINTN
*SmmCommunicateSize
57 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
59 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
60 SmmCommunicateHeader
->MessageLength
= *SmmCommunicateSize
- OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
62 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) &SmmCommunicateHeader
->Data
[0];
63 SmmVariableFunctionHeader
->Function
= SMM_VARIABLE_FUNCTION_GET_STATISTICS
;
65 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, SmmCommunicateHeader
, SmmCommunicateSize
);
66 ASSERT_EFI_ERROR (Status
);
68 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
75 This function get and print the variable statistics data from SMM variable driver.
77 @retval EFI_SUCCESS Print the statistics information successfully.
78 @retval EFI_NOT_FOUND Not found the statistics information.
87 VARIABLE_INFO_ENTRY
*VariableInfo
;
88 EFI_SMM_COMMUNICATE_HEADER
*CommBuffer
;
91 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
92 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
95 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**) &Smmvariable
);
96 if (EFI_ERROR (Status
)) {
100 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
101 if (EFI_ERROR (Status
)) {
105 CommSize
= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
106 RealCommSize
= CommSize
;
107 CommBuffer
= AllocateZeroPool (CommSize
);
108 ASSERT (CommBuffer
!= NULL
);
110 Print (L
"Non-Volatile SMM Variables:\n");
112 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
113 if (Status
== EFI_BUFFER_TOO_SMALL
) {
114 FreePool (CommBuffer
);
115 CommBuffer
= AllocateZeroPool (CommSize
);
116 ASSERT (CommBuffer
!= NULL
);
117 RealCommSize
= CommSize
;
118 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
121 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
125 if (CommSize
< RealCommSize
) {
126 CommSize
= RealCommSize
;
129 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
130 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
132 if (!VariableInfo
->Volatile
) {
134 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
135 &VariableInfo
->VendorGuid
,
136 VariableInfo
->ReadCount
,
137 VariableInfo
->CacheCount
,
138 VariableInfo
->WriteCount
,
139 VariableInfo
->DeleteCount
,
140 (CHAR16
*)(VariableInfo
+ 1)
145 Print (L
"Volatile SMM Variables:\n");
146 ZeroMem (CommBuffer
, CommSize
);
148 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
149 if (Status
== EFI_BUFFER_TOO_SMALL
) {
150 FreePool (CommBuffer
);
151 CommBuffer
= AllocateZeroPool (CommSize
);
152 ASSERT (CommBuffer
!= NULL
);
153 RealCommSize
= CommSize
;
154 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
157 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
161 if (CommSize
< RealCommSize
) {
162 CommSize
= RealCommSize
;
165 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
166 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
168 if (VariableInfo
->Volatile
) {
170 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
171 &VariableInfo
->VendorGuid
,
172 VariableInfo
->ReadCount
,
173 VariableInfo
->CacheCount
,
174 VariableInfo
->WriteCount
,
175 VariableInfo
->DeleteCount
,
176 (CHAR16
*)(VariableInfo
+ 1)
181 FreePool (CommBuffer
);
186 The user Entry Point for Application. The user code starts with this function
187 as the real entry point for the image goes into a library that calls this
190 @param[in] ImageHandle The firmware allocated handle for the EFI image.
191 @param[in] SystemTable A pointer to the EFI System Table.
193 @retval EFI_SUCCESS The entry point is executed successfully.
194 @retval other Some error occurs when executing this entry point.
200 IN EFI_HANDLE ImageHandle
,
201 IN EFI_SYSTEM_TABLE
*SystemTable
205 VARIABLE_INFO_ENTRY
*VariableInfo
;
206 VARIABLE_INFO_ENTRY
*Entry
;
208 Status
= EfiGetSystemConfigurationTable (&gEfiVariableGuid
, (VOID
**)&Entry
);
209 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
210 Status
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**)&Entry
);
213 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
214 Status
= PrintInfoFromSmm ();
215 if (!EFI_ERROR (Status
)) {
220 if (!EFI_ERROR (Status
) && (Entry
!= NULL
)) {
221 Print (L
"Non-Volatile EFI Variables:\n");
222 VariableInfo
= Entry
;
224 if (!VariableInfo
->Volatile
) {
226 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
227 &VariableInfo
->VendorGuid
,
228 VariableInfo
->ReadCount
,
229 VariableInfo
->CacheCount
,
230 VariableInfo
->WriteCount
,
231 VariableInfo
->DeleteCount
,
236 VariableInfo
= VariableInfo
->Next
;
237 } while (VariableInfo
!= NULL
);
239 Print (L
"Volatile EFI Variables:\n");
240 VariableInfo
= Entry
;
242 if (VariableInfo
->Volatile
) {
244 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
245 &VariableInfo
->VendorGuid
,
246 VariableInfo
->ReadCount
,
247 VariableInfo
->CacheCount
,
248 VariableInfo
->WriteCount
,
249 VariableInfo
->DeleteCount
,
253 VariableInfo
= VariableInfo
->Next
;
254 } while (VariableInfo
!= NULL
);
257 Print (L
"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");
258 Print (L
"If you want to see this info, please:\n");
259 Print (L
" 1. Set PcdVariableCollectStatistics as TRUE\n");
260 Print (L
" 2. Rebuild Variable Dxe driver\n");
261 Print (L
" 3. Run \"VariableInfo\" cmd again\n");