]> git.proxmox.com Git - mirror_edk2.git/commitdiff
use pcd to enable/disable variableInfo statistic feature in EmuRuntimeDxe driver.
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 4 Mar 2009 07:21:11 +0000 (07:21 +0000)
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 4 Mar 2009 07:21:11 +0000 (07:21 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7797 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c
MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf

index 1fdf25de27964ad4a69696a80157ebca3ac5859b..f17dab03b02130b2a35c2eb11c18c9012403511c 100644 (file)
@@ -21,6 +21,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 ///\r
 ESAL_VARIABLE_GLOBAL  *mVariableModuleGlobal;\r
 \r
+VARIABLE_INFO_ENTRY *gVariableInfo = NULL;\r
 \r
 /**\r
   Acquires lock only at boot time. Simply returns at runtime.\r
@@ -148,6 +149,103 @@ GetEndPointer (
   return (VARIABLE_HEADER *) ((UINTN) VolHeader + VolHeader->Size);\r
 }\r
 \r
+/**\r
+  Routine used to track statistical information about variable usage. \r
+  The data is stored in the EFI system table so it can be accessed later.\r
+  VariableInfo.efi can dump out the table. Only Boot Services variable \r
+  accesses are tracked by this code. The PcdVariableCollectStatistics\r
+  build flag controls if this feature is enabled. \r
+\r
+  A read that hits in the cache will have Read and Cache true for \r
+  the transaction. Data is allocated by this routine, but never\r
+  freed.\r
+\r
+  @param[in] VariableName   Name of the Variable to track\r
+  @param[in] VendorGuid     Guid of the Variable to track\r
+  @param[in] Volatile       TRUE if volatile FALSE if non-volatile\r
+  @param[in] Read           TRUE if GetVariable() was called\r
+  @param[in] Write          TRUE if SetVariable() was called\r
+  @param[in] Delete         TRUE if deleted via SetVariable()\r
+  @param[in] Cache          TRUE for a cache hit.\r
+\r
+**/\r
+VOID\r
+UpdateVariableInfo (\r
+  IN  CHAR16                  *VariableName,\r
+  IN  EFI_GUID                *VendorGuid,\r
+  IN  BOOLEAN                 Volatile,\r
+  IN  BOOLEAN                 Read,\r
+  IN  BOOLEAN                 Write,\r
+  IN  BOOLEAN                 Delete,\r
+  IN  BOOLEAN                 Cache\r
+  )\r
+{\r
+  VARIABLE_INFO_ENTRY   *Entry;\r
+\r
+  if (FeaturePcdGet (PcdVariableCollectStatistics)) {\r
+\r
+    if (EfiAtRuntime ()) {\r
+      // Don't collect statistics at runtime\r
+      return;\r
+    }\r
+\r
+    if (gVariableInfo == NULL) {\r
+      //\r
+      // on the first call allocate a entry and place a pointer to it in\r
+      // the EFI System Table\r
+      //\r
+      gVariableInfo = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));\r
+      ASSERT (gVariableInfo != NULL);\r
+\r
+      CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);\r
+      gVariableInfo->Name = AllocatePool (StrLen (VariableName));\r
+      ASSERT (gVariableInfo->Name != NULL);\r
+      StrCpy (gVariableInfo->Name, VariableName);\r
+      gVariableInfo->Volatile = Volatile;\r
+\r
+      gBS->InstallConfigurationTable (&gEfiVariableGuid, gVariableInfo);\r
+    }\r
+\r
+    \r
+    for (Entry = gVariableInfo; Entry != NULL; Entry = Entry->Next) {\r
+      if (CompareGuid (VendorGuid, &Entry->VendorGuid)) {\r
+        if (StrCmp (VariableName, Entry->Name) == 0) {\r
+          if (Read) {\r
+            Entry->ReadCount++;\r
+          }\r
+          if (Write) {\r
+            Entry->WriteCount++;\r
+          }\r
+          if (Delete) {\r
+            Entry->DeleteCount++;\r
+          }\r
+          if (Cache) {\r
+            Entry->CacheCount++;\r
+          }\r
+\r
+          return;\r
+        }\r
+      }\r
+\r
+      if (Entry->Next == NULL) {\r
+        //\r
+        // If the entry is not in the table add it.\r
+        // Next iteration of the loop will fill in the data\r
+        //\r
+        Entry->Next = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));\r
+        ASSERT (Entry->Next != NULL);\r
+\r
+        CopyGuid (&Entry->Next->VendorGuid, VendorGuid);\r
+        Entry->Next->Name = AllocatePool (StrLen (VariableName));\r
+        ASSERT (Entry->Next->Name != NULL);\r
+        StrCpy (Entry->Next->Name, VariableName);\r
+        Entry->Next->Volatile = Volatile;\r
+      }\r
+\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
   Finds variable in storage blocks of volatile and non-volatile storage areas.\r
 \r
@@ -303,6 +401,7 @@ GetVariable (
     }\r
 \r
     *DataSize = VarDataSize;\r
+    UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, TRUE, FALSE, FALSE, FALSE);\r
     Status = EFI_SUCCESS;\r
     goto Done;\r
   } else {\r
@@ -539,6 +638,7 @@ SetVariable (
     //\r
     if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) {\r
       Variable.CurrPtr->State &= VAR_DELETED;\r
+      UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, FALSE, FALSE, TRUE, FALSE);\r
       Status = EFI_SUCCESS;\r
       goto Done;\r
     }\r
@@ -653,6 +753,8 @@ SetVariable (
     Variable.CurrPtr->State &= VAR_DELETED;\r
   }\r
   \r
+  UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, FALSE, TRUE, FALSE, FALSE);\r
+\r
   Status = EFI_SUCCESS;\r
 Done:\r
   ReleaseLockOnlyAtBootTime (&Global->VariableServicesLock);\r
index 5e25d1efae4a862caef20cde35d8ec1b232d8961..4e9ebefc8acec2a88aa544df492e7b49c4a19921 100644 (file)
@@ -62,6 +62,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics\r
 \r
 [Depex]\r
   TRUE\r