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) 2006 - 2015, 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>
21 #include <Library/BaseLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/DebugLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
26 #include <Guid/VariableFormat.h>
27 #include <Guid/SmmVariableCommon.h>
28 #include <Protocol/SmmCommunication.h>
29 #include <Protocol/SmmVariable.h>
31 EFI_SMM_COMMUNICATION_PROTOCOL
*mSmmCommunication
= NULL
;
34 This function get the variable statistics data from SMM variable driver.
36 @param[in, out] SmmCommunicateHeader In input, a pointer to a collection of data that will
37 be passed into an SMM environment. In output, a pointer
38 to a collection of data that comes from an SMM environment.
39 @param[in, out] SmmCommunicateSize The size of the SmmCommunicateHeader.
41 @retval EFI_SUCCESS Get the statistics data information.
42 @retval EFI_NOT_FOUND Not found.
43 @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result.
48 GetVariableStatisticsData (
49 IN OUT EFI_SMM_COMMUNICATE_HEADER
*SmmCommunicateHeader
,
50 IN OUT UINTN
*SmmCommunicateSize
54 SMM_VARIABLE_COMMUNICATE_HEADER
*SmmVariableFunctionHeader
;
56 CopyGuid (&SmmCommunicateHeader
->HeaderGuid
, &gEfiSmmVariableProtocolGuid
);
57 SmmCommunicateHeader
->MessageLength
= *SmmCommunicateSize
- OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER
, Data
);
59 SmmVariableFunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) &SmmCommunicateHeader
->Data
[0];
60 SmmVariableFunctionHeader
->Function
= SMM_VARIABLE_FUNCTION_GET_STATISTICS
;
62 Status
= mSmmCommunication
->Communicate (mSmmCommunication
, SmmCommunicateHeader
, SmmCommunicateSize
);
63 ASSERT_EFI_ERROR (Status
);
65 Status
= SmmVariableFunctionHeader
->ReturnStatus
;
71 This function get and print the variable statistics data from SMM variable driver.
73 @retval EFI_SUCCESS Print the statistics information successfully.
74 @retval EFI_NOT_FOUND Not found the statistics information.
83 VARIABLE_INFO_ENTRY
*VariableInfo
;
84 EFI_SMM_COMMUNICATE_HEADER
*CommBuffer
;
87 SMM_VARIABLE_COMMUNICATE_HEADER
*FunctionHeader
;
88 EFI_SMM_VARIABLE_PROTOCOL
*Smmvariable
;
90 Status
= gBS
->LocateProtocol (&gEfiSmmVariableProtocolGuid
, NULL
, (VOID
**) &Smmvariable
);
91 if (EFI_ERROR (Status
)) {
95 Status
= gBS
->LocateProtocol (&gEfiSmmCommunicationProtocolGuid
, NULL
, (VOID
**) &mSmmCommunication
);
96 if (EFI_ERROR (Status
)) {
100 CommSize
= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
;
101 RealCommSize
= CommSize
;
102 CommBuffer
= AllocateZeroPool (CommSize
);
103 ASSERT (CommBuffer
!= NULL
);
105 Print (L
"Non-Volatile SMM Variables:\n");
107 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
108 if (Status
== EFI_BUFFER_TOO_SMALL
) {
109 FreePool (CommBuffer
);
110 CommBuffer
= AllocateZeroPool (CommSize
);
111 ASSERT (CommBuffer
!= NULL
);
112 RealCommSize
= CommSize
;
113 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
116 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
120 if (CommSize
< RealCommSize
) {
121 CommSize
= RealCommSize
;
124 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
125 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
127 if (!VariableInfo
->Volatile
) {
129 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
130 &VariableInfo
->VendorGuid
,
131 VariableInfo
->ReadCount
,
132 VariableInfo
->CacheCount
,
133 VariableInfo
->WriteCount
,
134 VariableInfo
->DeleteCount
,
135 (CHAR16
*)(VariableInfo
+ 1)
140 Print (L
"Volatile SMM Variables:\n");
141 ZeroMem (CommBuffer
, CommSize
);
143 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
144 if (Status
== EFI_BUFFER_TOO_SMALL
) {
145 FreePool (CommBuffer
);
146 CommBuffer
= AllocateZeroPool (CommSize
);
147 ASSERT (CommBuffer
!= NULL
);
148 RealCommSize
= CommSize
;
149 Status
= GetVariableStatisticsData (CommBuffer
, &CommSize
);
152 if (EFI_ERROR (Status
) || (CommSize
<= SMM_COMMUNICATE_HEADER_SIZE
+ SMM_VARIABLE_COMMUNICATE_HEADER_SIZE
)) {
156 if (CommSize
< RealCommSize
) {
157 CommSize
= RealCommSize
;
160 FunctionHeader
= (SMM_VARIABLE_COMMUNICATE_HEADER
*) CommBuffer
->Data
;
161 VariableInfo
= (VARIABLE_INFO_ENTRY
*) FunctionHeader
->Data
;
163 if (VariableInfo
->Volatile
) {
165 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
166 &VariableInfo
->VendorGuid
,
167 VariableInfo
->ReadCount
,
168 VariableInfo
->CacheCount
,
169 VariableInfo
->WriteCount
,
170 VariableInfo
->DeleteCount
,
171 (CHAR16
*)(VariableInfo
+ 1)
176 FreePool (CommBuffer
);
181 The user Entry Point for Application. The user code starts with this function
182 as the real entry point for the image goes into a library that calls this
185 @param[in] ImageHandle The firmware allocated handle for the EFI image.
186 @param[in] SystemTable A pointer to the EFI System Table.
188 @retval EFI_SUCCESS The entry point is executed successfully.
189 @retval other Some error occurs when executing this entry point.
195 IN EFI_HANDLE ImageHandle
,
196 IN EFI_SYSTEM_TABLE
*SystemTable
200 VARIABLE_INFO_ENTRY
*VariableInfo
;
201 VARIABLE_INFO_ENTRY
*Entry
;
203 Status
= EfiGetSystemConfigurationTable (&gEfiVariableGuid
, (VOID
**)&Entry
);
204 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
205 Status
= EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableGuid
, (VOID
**)&Entry
);
208 if (EFI_ERROR (Status
) || (Entry
== NULL
)) {
209 Status
= PrintInfoFromSmm ();
210 if (!EFI_ERROR (Status
)) {
215 if (!EFI_ERROR (Status
) && (Entry
!= NULL
)) {
216 Print (L
"Non-Volatile EFI Variables:\n");
217 VariableInfo
= Entry
;
219 if (!VariableInfo
->Volatile
) {
221 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
222 &VariableInfo
->VendorGuid
,
223 VariableInfo
->ReadCount
,
224 VariableInfo
->CacheCount
,
225 VariableInfo
->WriteCount
,
226 VariableInfo
->DeleteCount
,
231 VariableInfo
= VariableInfo
->Next
;
232 } while (VariableInfo
!= NULL
);
234 Print (L
"Volatile EFI Variables:\n");
235 VariableInfo
= Entry
;
237 if (VariableInfo
->Volatile
) {
239 L
"%g R%03d(%03d) W%03d D%03d:%s\n",
240 &VariableInfo
->VendorGuid
,
241 VariableInfo
->ReadCount
,
242 VariableInfo
->CacheCount
,
243 VariableInfo
->WriteCount
,
244 VariableInfo
->DeleteCount
,
248 VariableInfo
= VariableInfo
->Next
;
249 } while (VariableInfo
!= NULL
);
252 Print (L
"Warning: Variable Dxe driver doesn't enable the feature of statistical information!\n");
253 Print (L
"If you want to see this info, please:\n");
254 Print (L
" 1. Set PcdVariableCollectStatistics as TRUE\n");
255 Print (L
" 2. Rebuild Variable Dxe driver\n");
256 Print (L
" 3. Run \"VariableInfo\" cmd again\n");