]> git.proxmox.com Git - mirror_edk2.git/blobdiff - PerformancePkg/Dp_App/Dp.c
ShellPkg : Cache the environment variable into memory to enhance
[mirror_edk2.git] / PerformancePkg / Dp_App / Dp.c
index 57144a8fb87467315cf54756a2cab8ed5bdbaabe..b24a0de72d74c952b285f3f9150273535de87301 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 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\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
@@ -81,6 +82,7 @@ PARAM_ITEM_LIST  ParamList[] = {
 #endif\r
   {STRING_TOKEN (STR_DP_OPTION_LX), TypeFlag},   // -x   eXclude Cumulative Items\r
   {STRING_TOKEN (STR_DP_OPTION_LI), TypeFlag},   // -i   Display Identifier\r
+  {STRING_TOKEN (STR_DP_OPTION_LC), TypeValue},  // -c   Display cumulative data.\r
   {STRING_TOKEN (STR_DP_OPTION_LN), TypeValue},  // -n # Number of records to display for A and R\r
   {STRING_TOKEN (STR_DP_OPTION_LT), TypeValue}   // -t # Threshold of interest\r
   };\r
@@ -138,6 +140,7 @@ ShowHelp( void )
   PrintToken (STRING_TOKEN (STR_DP_HELP_THRESHOLD));\r
   PrintToken (STRING_TOKEN (STR_DP_HELP_COUNT));\r
   PrintToken (STRING_TOKEN (STR_DP_HELP_ID));\r
+  PrintToken (STRING_TOKEN (STR_DP_HELP_CUM_DATA));\r
   PrintToken (STRING_TOKEN (STR_DP_HELP_HELP));\r
   Print(L"\n");\r
 }\r
@@ -168,16 +171,35 @@ DumpStatistics( void )
   FreePool (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
+\r
   @retval EFI_SUCCESS            Command completed successfully.\r
   @retval EFI_INVALID_PARAMETER  Command usage error.\r
+  @retval EFI_ABORTED            The user aborts the operation.\r
   @retval value                  Unknown error.\r
-  \r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -203,6 +225,9 @@ InitializeDp (
   BOOLEAN                   TraceMode;\r
   BOOLEAN                   ProfileMode;\r
   BOOLEAN                   ExcludeMode;\r
+  BOOLEAN                   CumulativeMode;\r
+  CONST CHAR16              *CustomCumulativeToken;\r
+  PERF_CUM_DATA             *CustomCumulativeData;\r
 \r
   EFI_STRING                StringDpOptionQh;\r
   EFI_STRING                StringDpOptionLh;\r
@@ -218,6 +243,7 @@ InitializeDp (
   EFI_STRING                StringDpOptionLn;\r
   EFI_STRING                StringDpOptionLt;\r
   EFI_STRING                StringDpOptionLi;\r
+  EFI_STRING                StringDpOptionLc;\r
   \r
   SummaryMode     = FALSE;\r
   VerboseMode     = FALSE;\r
@@ -226,6 +252,8 @@ InitializeDp (
   TraceMode       = FALSE;\r
   ProfileMode     = FALSE;\r
   ExcludeMode     = FALSE;\r
+  CumulativeMode = FALSE;\r
+  CustomCumulativeData = NULL;\r
 \r
   StringDpOptionQh = NULL;\r
   StringDpOptionLh = NULL;\r
@@ -241,6 +269,7 @@ InitializeDp (
   StringDpOptionLn = NULL;\r
   StringDpOptionLt = NULL;\r
   StringDpOptionLi = NULL;\r
+  StringDpOptionLc = NULL;\r
   StringPtr        = NULL;\r
 \r
   // Get DP's entry time as soon as possible.\r
@@ -289,6 +318,7 @@ InitializeDp (
       StringDpOptionLn = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LN), NULL);\r
       StringDpOptionLt = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LT), NULL);\r
       StringDpOptionLi = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LI), NULL);\r
+      StringDpOptionLc = HiiGetString (gHiiHandle, STRING_TOKEN (STR_DP_OPTION_LC), NULL);\r
       \r
       // Boolean Options\r
       // \r
@@ -303,6 +333,7 @@ InitializeDp (
 #endif  // PROFILING_IMPLEMENTED\r
       ExcludeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLx);\r
       mShowId     =  ShellCommandLineGetFlag (ParamPackage, StringDpOptionLi);\r
+      CumulativeMode = ShellCommandLineGetFlag (ParamPackage, StringDpOptionLc);\r
 \r
       // Options with Values\r
       CmdLineArg  = ShellCommandLineGetValue (ParamPackage, StringDpOptionLn);\r
@@ -331,6 +362,21 @@ InitializeDp (
 #endif  // PROFILING_IMPLEMENTED\r
       }\r
 \r
+  //\r
+  // Init the custom cumulative data.\r
+  //\r
+  CustomCumulativeToken = ShellCommandLineGetValue (ParamPackage, StringDpOptionLc);\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
@@ -392,10 +438,15 @@ InitializeDp (
 ****    !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
+            goto Done;\r
+          }\r
         }\r
         if (ProfileMode) {\r
           DumpAllProfile( Number2Display, ExcludeMode);\r
@@ -403,7 +454,10 @@ InitializeDp (
       }\r
       else if (RawMode) {\r
         if (TraceMode) {\r
-          DumpRawTrace( Number2Display, ExcludeMode);\r
+          Status = DumpRawTrace( Number2Display, ExcludeMode);\r
+          if (Status == EFI_ABORTED) {\r
+            goto Done;\r
+          }\r
         }\r
         if (ProfileMode) {\r
           DumpRawProfile( Number2Display, ExcludeMode);\r
@@ -415,11 +469,21 @@ InitializeDp (
           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
+              goto Done;\r
+            }\r
+\r
+            Status = ProcessPeims ();\r
+            if (Status == EFI_ABORTED) {\r
+              goto Done;\r
             }\r
+\r
+            Status = ProcessGlobal ();\r
+            if (Status == EFI_ABORTED) {\r
+              goto Done;\r
+            }\r
+\r
+            ProcessCumulative (NULL);\r
           }\r
         }\r
         if (ProfileMode) {\r
@@ -432,6 +496,9 @@ InitializeDp (
     }\r
   }\r
 \r
+Done:\r
+\r
+  //\r
   // Free the memory allocate from HiiGetString\r
   //\r
   ListIndex = 0;\r
@@ -455,9 +522,18 @@ InitializeDp (
   SafeFreePool (StringDpOptionLn);\r
   SafeFreePool (StringDpOptionLt);\r
   SafeFreePool (StringDpOptionLi);\r
+  SafeFreePool (StringDpOptionLc);\r
   SafeFreePool (StringPtr);\r
   SafeFreePool (mPrintTokenBuffer);\r
 \r
+  if (ParamPackage != NULL) {\r
+    ShellCommandLineFreeVarList (ParamPackage);\r
+  }\r
+  if (CustomCumulativeData != NULL) {\r
+    SafeFreePool (CustomCumulativeData->Name);\r
+  }\r
+  SafeFreePool (CustomCumulativeData);\r
+\r
   HiiRemovePackages (gHiiHandle);\r
   return Status;\r
 }\r