]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
Modify the implementation of performance library so that:
[mirror_edk2.git] / EdkModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
index 8a3ac4053f1813133ec3b4d096263840f2d79e95..74d71c54d96afde54feb5ff61e227263b14b74af 100644 (file)
@@ -27,24 +27,30 @@ STATIC PERFORMANCE_PROTOCOL    *mPerformance = NULL;
   The constructor function locates Performance protocol from protocol database.\r
   It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
 \r
-  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
-  @param  SystemTable   A pointer to the EFI System Table.\r
-  \r
-  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+  @retval EFI_SUCCESS     Performance protocol is successfully located.\r
+  @retval Other           Performance protocol is not located to log performance.  \r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-PerformanceLibConstructor (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
+GetPerformanceProtocol (\r
+  VOID\r
   )\r
 {\r
   EFI_STATUS            Status;\r
+  PERFORMANCE_PROTOCOL  *Performance;\r
+\r
+  if (mPerformance != NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
-  Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &mPerformance);\r
-  ASSERT_EFI_ERROR (Status);\r
-  ASSERT (mPerformance != NULL);\r
+  Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &Performance);\r
+  if (!EFI_ERROR (Status)) {\r
+    ASSERT (Performance != NULL);\r
+    //\r
+    // Cache performance protocol.\r
+    //\r
+    mPerformance = Performance;\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -79,9 +85,14 @@ StartPerformanceMeasurement (
   )\r
 {\r
   EFI_STATUS  Status;\r
+\r
+  Status = GetPerformanceProtocol ();\r
+  if (EFI_ERROR (Status)) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
   \r
   Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp);\r
-\r
+  \r
   return (RETURN_STATUS) Status;\r
 }\r
 \r
@@ -119,6 +130,11 @@ EndPerformanceMeasurement (
 {\r
   EFI_STATUS  Status;\r
 \r
+  Status = GetPerformanceProtocol ();\r
+  if (EFI_ERROR (Status)) {\r
+    return RETURN_NOT_FOUND;\r
+  }\r
+\r
   Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp);\r
 \r
   return (RETURN_STATUS) Status;\r
@@ -181,6 +197,11 @@ GetPerformanceMeasurement (
   ASSERT (StartTimeStamp != NULL);\r
   ASSERT (EndTimeStamp != NULL);\r
 \r
+  Status = GetPerformanceProtocol ();\r
+  if (EFI_ERROR (Status)) {\r
+    return 0;\r
+  }\r
+\r
   Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData);\r
   \r
   //\r