]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c
MdeModulePkg: Update performance library instances
[mirror_edk2.git] / MdeModulePkg / Library / DxePerformanceLib / DxePerformanceLib.c
index 9ed50d22b8d42b0ff4ad4a2c2675e5bc676fb340..664e8261af999f7c5004f1ca51544ad2c653ad02 100644 (file)
@@ -378,3 +378,71 @@ PerformanceMeasurementEnabled (
 {\r
   return (BOOLEAN) ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0);\r
 }\r
+\r
+/**\r
+  Create performance record with event description and a timestamp.\r
+\r
+  @param CallerIdentifier  - Image handle or pointer to caller ID GUID\r
+  @param Guid              - Pointer to a GUID\r
+  @param String            - Pointer to a string describing the measurement\r
+  @param Address           - Pointer to a location in memory relevant to the measurement\r
+  @param Identifier        - Performance identifier describing the type of measurement\r
+\r
+  @retval RETURN_SUCCESS           - Successfully created performance record\r
+  @retval RETURN_OUT_OF_RESOURCES  - Ran out of space to store the records\r
+  @retval RETURN_INVALID_PARAMETER - Invalid parameter passed to function - NULL\r
+                                     pointer or invalid PerfId\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+LogPerformanceMeasurement (\r
+  IN CONST VOID   *CallerIdentifier,\r
+  IN CONST VOID   *Guid,    OPTIONAL\r
+  IN CONST CHAR8  *String,  OPTIONAL\r
+  IN  UINT64       Address, OPTIONAL\r
+  IN UINT32       Identifier\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = GetPerformanceMeasurementProtocol ();\r
+  if (EFI_ERROR (Status)) {\r
+    return RETURN_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  if (mPerformanceMeasurement != NULL) {\r
+    Status = mPerformanceMeasurement->CreatePerformanceMeasurement (CallerIdentifier, Guid, String, 0, Address, Identifier, PerfEntry);\r
+  } else {\r
+    ASSERT (FALSE);\r
+  }\r
+\r
+  return (RETURN_STATUS) Status;\r
+}\r
+\r
+/**\r
+  Check whether the specified performance measurement can be logged.\r
+\r
+  This function returns TRUE when the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of PcdPerformanceLibraryPropertyMask is set\r
+  and the Type disable bit in PcdPerformanceLibraryPropertyMask is not set.\r
+\r
+  @param Type        - Type of the performance measurement entry.\r
+\r
+  @retval TRUE         The performance measurement can be logged.\r
+  @retval FALSE        The performance measurement can NOT be logged.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+LogPerformanceMeasurementEnabled (\r
+  IN  CONST UINTN        Type\r
+  )\r
+{\r
+  //\r
+  // When Performance measurement is enabled and the type is not filtered, the performance can be logged.\r
+  //\r
+  if (PerformanceMeasurementEnabled () && (PcdGet8(PcdPerformanceLibraryPropertyMask) & Type) == 0) {\r
+    return TRUE;\r
+  }\r
+  return FALSE;\r
+}\r