]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiDpLib/Dp.c
ShellPkg/tftp: Convert from NULL class library to Dynamic Command
[mirror_edk2.git] / ShellPkg / Library / UefiDpLib / Dp.c
index 6b06d20749f29c3bc695abd99880fa294061456e..94fa61c7108e55e421e9cd98fdffa645379b4fa6 100644 (file)
@@ -13,8 +13,8 @@
   Dp uses this information to group records in different ways.  It also uses\r
   timer information to calculate elapsed time for each measurement.\r
  \r
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.\r
-  (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
+  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.\r
+  (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 **/\r
 \r
 #include "UefiDpLib.h"\r
-#include <Guid/GlobalVariable.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/HandleParsingLib.h>\r
-#include <Library/DevicePathLib.h>\r
-\r
 #include <Library/ShellLib.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
 #include <Library/DebugLib.h>\r
-#include <Library/TimerLib.h>\r
 #include <Library/UefiLib.h>\r
 \r
 #include <Guid/Performance.h>\r
@@ -137,10 +131,10 @@ InitCumulativeData (
   @param[in]  ImageHandle     The image handle.\r
   @param[in]  SystemTable     The system table.\r
   \r
-  @retval EFI_SUCCESS            Command completed successfully.\r
-  @retval EFI_INVALID_PARAMETER  Command usage error.\r
-  @retval value                  Unknown error.\r
-  \r
+  @retval SHELL_SUCCESS            Command completed successfully.\r
+  @retval SHELL_INVALID_PARAMETER  Command usage error.\r
+  @retval SHELL_ABORTED            The user aborts the operation.\r
+  @retval value                    Unknown error.\r
 **/\r
 SHELL_STATUS\r
 EFIAPI\r
@@ -153,8 +147,7 @@ ShellCommandRunDp (
   CONST CHAR16              *CmdLineArg;\r
   EFI_STATUS                Status;\r
 \r
-  UINT64                    Freq;\r
-  UINT64                    Ticker;\r
+  PERFORMANCE_PROPERTY      *PerformanceProperty;\r
   UINTN                     Number2Display;\r
 \r
   EFI_STRING                StringPtr;\r
@@ -168,6 +161,8 @@ ShellCommandRunDp (
   BOOLEAN                   CumulativeMode;\r
   CONST CHAR16              *CustomCumulativeToken;\r
   PERF_CUM_DATA             *CustomCumulativeData;\r
+  UINTN                     NameSize;\r
+  SHELL_STATUS              ShellStatus;\r
 \r
   StringPtr   = NULL;\r
   SummaryMode = FALSE;\r
@@ -179,11 +174,7 @@ ShellCommandRunDp (
   ExcludeMode = FALSE;\r
   CumulativeMode = FALSE;\r
   CustomCumulativeData = NULL;\r
-\r
-  // Get DP's entry time as soon as possible.\r
-  // This is used as the Shell-Phase end time.\r
-  //\r
-  Ticker  = GetPerformanceCounter ();\r
+  ShellStatus = SHELL_SUCCESS;\r
 \r
   //\r
   // initialize the shell lib (we must be in non-auto-init...)\r
@@ -256,13 +247,20 @@ ShellCommandRunDp (
   CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, L"-c");\r
   if (CustomCumulativeToken != NULL) {\r
     CustomCumulativeData = AllocateZeroPool (sizeof (PERF_CUM_DATA));\r
-    ASSERT (CustomCumulativeData != NULL);\r
-    CustomCumulativeData->MinDur = 0;\r
+    if (CustomCumulativeData == NULL) {\r
+      return SHELL_OUT_OF_RESOURCES;\r
+    }\r
+    CustomCumulativeData->MinDur = PERF_MAXDUR;\r
     CustomCumulativeData->MaxDur = 0;\r
     CustomCumulativeData->Count  = 0;\r
     CustomCumulativeData->Duration = 0;\r
-    CustomCumulativeData->Name   = AllocateZeroPool (StrLen (CustomCumulativeToken) + 1);\r
-    UnicodeStrToAsciiStr (CustomCumulativeToken, CustomCumulativeData->Name);\r
+    NameSize = StrLen (CustomCumulativeToken) + 1;\r
+    CustomCumulativeData->Name   = AllocateZeroPool (NameSize);\r
+    if (CustomCumulativeData->Name == NULL) {\r
+      FreePool (CustomCumulativeData);\r
+      return SHELL_OUT_OF_RESOURCES;\r
+    }\r
+    UnicodeStrToAsciiStrS (CustomCumulativeToken, CustomCumulativeData->Name, NameSize);\r
   }\r
 \r
   //\r
@@ -273,10 +271,15 @@ ShellCommandRunDp (
   //    StartCount = Value loaded into the counter when it starts counting\r
   //      EndCount = Value counter counts to before it needs to be reset\r
   //\r
-  Freq = GetPerformanceCounterProperties (&TimerInfo.StartCount, &TimerInfo.EndCount);\r
+  Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);\r
+  if (EFI_ERROR (Status) || (PerformanceProperty == NULL)) {\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PERF_PROPERTY_NOT_FOUND), gDpHiiHandle);\r
+    goto Done;\r
+  }\r
 \r
-  // Convert the Frequency from Hz to KHz\r
-  TimerInfo.Frequency = (UINT32)DivU64x32 (Freq, 1000);\r
+  TimerInfo.Frequency  = (UINT32)DivU64x32 (PerformanceProperty->Frequency, 1000);\r
+  TimerInfo.StartCount = PerformanceProperty->TimerStartValue;\r
+  TimerInfo.EndCount   = PerformanceProperty->TimerEndValue;\r
 \r
   // Determine in which direction the performance counter counts.\r
   TimerInfo.CountUp = (BOOLEAN) (TimerInfo.EndCount >= TimerInfo.StartCount);\r
@@ -329,14 +332,22 @@ ShellCommandRunDp (
     ProcessCumulative (CustomCumulativeData);\r
   } else if (AllMode) {\r
     if (TraceMode) {\r
-      DumpAllTrace( Number2Display, ExcludeMode);\r
+      Status = DumpAllTrace( Number2Display, ExcludeMode);\r
+      if (Status == EFI_ABORTED) {\r
+        ShellStatus = SHELL_ABORTED;\r
+        goto Done;\r
+      }\r
     }\r
     if (ProfileMode) {\r
       DumpAllProfile( Number2Display, ExcludeMode);\r
     }\r
   } else if (RawMode) {\r
     if (TraceMode) {\r
-      DumpRawTrace( Number2Display, ExcludeMode);\r
+      Status = DumpRawTrace( Number2Display, ExcludeMode);\r
+      if (Status == EFI_ABORTED) {\r
+        ShellStatus = SHELL_ABORTED;\r
+        goto Done;\r
+      }\r
     }\r
     if (ProfileMode) {\r
       DumpRawProfile( Number2Display, ExcludeMode);\r
@@ -344,14 +355,27 @@ ShellCommandRunDp (
   } else {\r
     //------------- Begin Cooked Mode Processing\r
     if (TraceMode) {\r
-      ProcessPhases ( Ticker );\r
+      ProcessPhases ();\r
       if ( ! SummaryMode) {\r
         Status = ProcessHandles ( ExcludeMode);\r
-        if ( ! EFI_ERROR( Status)) {\r
-          ProcessPeims ();\r
-          ProcessGlobal ();\r
-          ProcessCumulative (NULL);\r
+        if (Status == EFI_ABORTED) {\r
+          ShellStatus = SHELL_ABORTED;\r
+          goto Done;\r
+        }\r
+\r
+        Status = ProcessPeims ();\r
+        if (Status == EFI_ABORTED) {\r
+          ShellStatus = SHELL_ABORTED;\r
+          goto Done;\r
         }\r
+\r
+        Status = ProcessGlobal ();\r
+        if (Status == EFI_ABORTED) {\r
+          ShellStatus = SHELL_ABORTED;\r
+          goto Done;\r
+        }\r
+\r
+        ProcessCumulative (NULL);\r
       }\r
     }\r
     if (ProfileMode) {\r
@@ -362,11 +386,15 @@ ShellCommandRunDp (
     DumpStatistics();\r
   }\r
 \r
+Done:\r
+  if (ParamPackage != NULL) {\r
+    ShellCommandLineFreeVarList (ParamPackage);\r
+  }\r
   SHELL_FREE_NON_NULL (StringPtr);\r
   if (CustomCumulativeData != NULL) {\r
     SHELL_FREE_NON_NULL (CustomCumulativeData->Name);\r
   }\r
   SHELL_FREE_NON_NULL (CustomCumulativeData);\r
 \r
-  return SHELL_SUCCESS;\r
+  return ShellStatus;\r
 }\r