]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiDpLib/Dp.c
ShellPkg/UefiDpLib: Support execution break
[mirror_edk2.git] / ShellPkg / Library / UefiDpLib / Dp.c
index 4fe9083b0033f2a9e5231c9f38b491558e854d6f..0176e31bc0d6624ad0371b3ecb01b181d69c9beb 100644 (file)
@@ -13,7 +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 - 2013, Intel Corporation. All rights reserved.\r
+  Copyright (c) 2009 - 2015, 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
@@ -38,7 +39,7 @@
 \r
 #include <Guid/Performance.h>\r
 \r
-#include <PerformanceTokens.h>\r
+#include "PerformanceTokens.h"\r
 #include "Dp.h"\r
 #include "Literals.h"\r
 #include "DpInternal.h"\r
@@ -78,6 +79,7 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
 #endif // PROFILING_IMPLEMENTED\r
   {L"-x", TypeFlag},   // -x   eXclude Cumulative Items\r
   {L"-i", TypeFlag},   // -i   Display Identifier\r
+  {L"-c", TypeValue},  // -c   Display cumulative data.\r
   {L"-n", TypeValue},  // -n # Number of records to display for A and R\r
   {L"-t", TypeValue},  // -t # Threshold of interest\r
   {NULL, TypeMax}\r
@@ -110,16 +112,35 @@ DumpStatistics( void )
   SHELL_FREE_NON_NULL (StringPtrUnknown);\r
 }\r
 \r
-/** \r
+/**\r
+  Initialize the cumulative data.\r
+\r
+**/\r
+VOID\r
+InitCumulativeData (\r
+  VOID\r
+  )\r
+{\r
+  UINTN                             Index;\r
+\r
+  for (Index = 0; Index < NumCum; ++Index) {\r
+    CumData[Index].Count = 0;\r
+    CumData[Index].MinDur = PERF_MAXDUR;\r
+    CumData[Index].MaxDur = 0;\r
+    CumData[Index].Duration = 0;\r
+  }\r
+}\r
+\r
+/**\r
   Dump performance data.\r
   \r
   @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
@@ -144,6 +165,10 @@ ShellCommandRunDp (
   BOOLEAN                   TraceMode;\r
   BOOLEAN                   ProfileMode;\r
   BOOLEAN                   ExcludeMode;\r
+  BOOLEAN                   CumulativeMode;\r
+  CONST CHAR16              *CustomCumulativeToken;\r
+  PERF_CUM_DATA             *CustomCumulativeData;\r
+  SHELL_STATUS              ShellStatus;\r
 \r
   StringPtr   = NULL;\r
   SummaryMode = FALSE;\r
@@ -153,6 +178,9 @@ ShellCommandRunDp (
   TraceMode   = FALSE;\r
   ProfileMode = FALSE;\r
   ExcludeMode = FALSE;\r
+  CumulativeMode = FALSE;\r
+  CustomCumulativeData = NULL;\r
+  ShellStatus = SHELL_SUCCESS;\r
 \r
   // Get DP's entry time as soon as possible.\r
   // This is used as the Shell-Phase end time.\r
@@ -190,6 +218,7 @@ ShellCommandRunDp (
 #endif  // PROFILING_IMPLEMENTED\r
   ExcludeMode = ShellCommandLineGetFlag (ParamPackage, L"-x");\r
   mShowId     = ShellCommandLineGetFlag (ParamPackage, L"-i");\r
+  CumulativeMode = ShellCommandLineGetFlag (ParamPackage, L"-c");\r
 \r
   // Options with Values\r
   CmdLineArg  = ShellCommandLineGetValue (ParamPackage, L"-n");\r
@@ -218,6 +247,26 @@ ShellCommandRunDp (
 #endif  // PROFILING_IMPLEMENTED\r
   }\r
 \r
+  //\r
+  // Initialize the pre-defined cumulative data.\r
+  //\r
+  InitCumulativeData ();\r
+\r
+  //\r
+  // Init the custom cumulative data.\r
+  //\r
+  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
+    CustomCumulativeData->MaxDur = 0;\r
+    CustomCumulativeData->Count  = 0;\r
+    CustomCumulativeData->Duration = 0;\r
+    CustomCumulativeData->Name   = AllocateZeroPool (StrLen (CustomCumulativeToken) + 1);\r
+    UnicodeStrToAsciiStr (CustomCumulativeToken, CustomCumulativeData->Name);\r
+  }\r
+\r
   //\r
   // Timer specific processing\r
   //\r
@@ -277,17 +326,27 @@ ShellCommandRunDp (
 ****    !T &&  P  := (2) Only Profile records are displayed\r
 ****     T &&  P  := (3) Same as Default, both are displayed\r
 ****************************************************************************/\r
-  GatherStatistics();\r
-  if (AllMode) {\r
+  GatherStatistics (CustomCumulativeData);\r
+  if (CumulativeMode) {                       \r
+    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
@@ -298,11 +357,24 @@ ShellCommandRunDp (
       ProcessPhases ( Ticker );\r
       if ( ! SummaryMode) {\r
         Status = ProcessHandles ( ExcludeMode);\r
-        if ( ! EFI_ERROR( Status)) {\r
-          ProcessPeims ();\r
-          ProcessGlobal ();\r
-          ProcessCumulative ();\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
@@ -313,7 +385,12 @@ ShellCommandRunDp (
     DumpStatistics();\r
   }\r
 \r
+Done:\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