]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/MemoryProfileInfo/MemoryProfileInfo.c
MdePkg: Convert all .uni files to utf-8
[mirror_edk2.git] / MdeModulePkg / Application / MemoryProfileInfo / MemoryProfileInfo.c
index 084b069fb8a70c4c57900213d2ed98d09e3e0dab..f69a3e77486a82368f127e42b5280fb2c3608865 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
   \r
-  Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<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
@@ -54,7 +54,9 @@ CHAR16 *mMemoryTypeString[] = {
   L"EfiMemoryMappedIO",\r
   L"EfiMemoryMappedIOPortSpace",\r
   L"EfiPalCode",\r
+  L"EfiPersistentMemory",\r
   L"EfiOSReserved",\r
+  L"EfiOemReserved",\r
 };\r
 \r
 CHAR16 *mSubsystemString[] = {\r
@@ -119,10 +121,10 @@ GetShortPdbFileName (
   UINTN StartIndex;\r
   UINTN EndIndex;\r
 \r
-  ZeroMem (UnicodeBuffer, PROFILE_NAME_STRING_LENGTH * sizeof (CHAR16));\r
+  ZeroMem (UnicodeBuffer, (PROFILE_NAME_STRING_LENGTH + 1) * sizeof (CHAR16));\r
 \r
   if (PdbFileName == NULL) {\r
-    StrnCpy (UnicodeBuffer, L" ", 1);\r
+    StrnCpyS (UnicodeBuffer, PROFILE_NAME_STRING_LENGTH + 1, L" ", 1);\r
   } else {\r
     StartIndex = 0;\r
     for (EndIndex = 0; PdbFileName[EndIndex] != 0; EndIndex++);\r
@@ -199,7 +201,7 @@ GetDriverNameString (
       //\r
       // Method 2: Get the name string from FFS UI section\r
       //\r
-      StrnCpy (mNameString, NameString, PROFILE_NAME_STRING_LENGTH);\r
+      StrnCpyS (mNameString, PROFILE_NAME_STRING_LENGTH + 1, NameString, PROFILE_NAME_STRING_LENGTH);\r
       mNameString[PROFILE_NAME_STRING_LENGTH] = 0;\r
       FreePool (NameString);\r
       return;\r
@@ -212,6 +214,38 @@ GetDriverNameString (
   UnicodeSPrint (mNameString, sizeof (mNameString), L"%g", &DriverInfo->FileName);\r
 }\r
 \r
+/**\r
+  Memory type to string.\r
+\r
+  @param[in] MemoryType Memory type.\r
+\r
+  @return Pointer to string.\r
+\r
+**/\r
+CHAR16 *\r
+ProfileMemoryTypeToStr (\r
+  IN EFI_MEMORY_TYPE    MemoryType\r
+  )\r
+{\r
+  UINTN     Index;\r
+\r
+  if ((UINT32) MemoryType >= 0x80000000) {\r
+    //\r
+    // OS reserved memory type.\r
+    //\r
+    Index = EfiMaxMemoryType;\r
+  } else if ((UINT32) MemoryType >= 0x70000000) {\r
+    //\r
+    // OEM reserved memory type.\r
+    //\r
+    Index = EfiMaxMemoryType + 1;\r
+  } else {\r
+    Index = MemoryType;\r
+  }\r
+\r
+  return mMemoryTypeString[Index];\r
+}\r
+\r
 /**\r
   Dump memory profile allocate information.\r
 \r
@@ -239,7 +273,7 @@ DumpMemoryProfileAllocInfo (
   Print (L"      CallerAddress - 0x%016lx (Offset: 0x%08x)\n", AllocInfo->CallerAddress, (UINTN) (AllocInfo->CallerAddress - DriverInfo->ImageBase));\r
   Print (L"      SequenceId    - 0x%08x\n", AllocInfo->SequenceId);\r
   Print (L"      Action        - 0x%08x (%s)\n", AllocInfo->Action, mActionString[(AllocInfo->Action < sizeof(mActionString)/sizeof(mActionString[0])) ? AllocInfo->Action : 0]);\r
-  Print (L"      MemoryType    - 0x%08x (%s)\n", AllocInfo->MemoryType, mMemoryTypeString[(AllocInfo->MemoryType < sizeof(mMemoryTypeString)/sizeof(mMemoryTypeString[0])) ? AllocInfo->MemoryType : (sizeof(mMemoryTypeString)/sizeof(mMemoryTypeString[0]) - 1)]);\r
+  Print (L"      MemoryType    - 0x%08x (%s)\n", AllocInfo->MemoryType, ProfileMemoryTypeToStr (AllocInfo->MemoryType));\r
   Print (L"      Buffer        - 0x%016lx\n", AllocInfo->Buffer);\r
   Print (L"      Size          - 0x%016lx\n", AllocInfo->Size);\r
 \r
@@ -281,7 +315,7 @@ DumpMemoryProfileDriverInfo (
   Print (L"    FileType                - 0x%02x (%s)\n", DriverInfo->FileType, mFileTypeString[(DriverInfo->FileType < sizeof(mFileTypeString)/sizeof(mFileTypeString[0])) ? DriverInfo->FileType : 0]);\r
   Print (L"    CurrentUsage            - 0x%016lx\n", DriverInfo->CurrentUsage);\r
   Print (L"    PeakUsage               - 0x%016lx\n", DriverInfo->PeakUsage);\r
-  for (TypeIndex = 0; TypeIndex <= EfiMaxMemoryType; TypeIndex++) {\r
+  for (TypeIndex = 0; TypeIndex < sizeof (DriverInfo->CurrentUsageByType) / sizeof (DriverInfo->CurrentUsageByType[0]); TypeIndex++) {\r
     if ((DriverInfo->CurrentUsageByType[TypeIndex] != 0) ||\r
         (DriverInfo->PeakUsageByType[TypeIndex] != 0)) {\r
       Print (L"    CurrentUsage[0x%02x]      - 0x%016lx (%s)\n", TypeIndex, DriverInfo->CurrentUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);\r
@@ -326,7 +360,7 @@ DumpMemoryProfileContext (
   Print (L"  Revision                      - 0x%04x\n", Context->Header.Revision);  \r
   Print (L"  CurrentTotalUsage             - 0x%016lx\n", Context->CurrentTotalUsage);\r
   Print (L"  PeakTotalUsage                - 0x%016lx\n", Context->PeakTotalUsage);\r
-  for (TypeIndex = 0; TypeIndex <= EfiMaxMemoryType; TypeIndex++) {\r
+  for (TypeIndex = 0; TypeIndex < sizeof (Context->CurrentTotalUsageByType) / sizeof (Context->CurrentTotalUsageByType[0]); TypeIndex++) {\r
     if ((Context->CurrentTotalUsageByType[TypeIndex] != 0) ||\r
         (Context->PeakTotalUsageByType[TypeIndex] != 0)) {\r
       Print (L"  CurrentTotalUsage[0x%02x]       - 0x%016lx (%s)\n", TypeIndex, Context->CurrentTotalUsageByType[TypeIndex], mMemoryTypeString[TypeIndex]);\r