Click here to Skip to main content
15,893,381 members
Articles / Programming Languages / C++

Debug Toolkit

Rate me:
Please Sign up or sign in to vote.
4.20/5 (5 votes)
27 Mar 2000 180.6K   1.5K   88  
A complete debug toolkit to add intelligent debugging capability to your application.
#ifndef PROCESSORINFO_H
#define PROCESSORINFO_H

class CProcessorInfo
{
protected:

	SYSTEM_INFO m_sysInfo;

public:
   CProcessorInfo(void)
   {
      ::GetSystemInfo(&m_sysInfo);
   }

   virtual ~CProcessorInfo(void)
   {
   }

   CString GetProcessorName(void)
   {
      CString sRC;

      CString sSpeed;
      CString sVendor;

   	// Get the processor speed info.
   	HKEY hKey;
   	LONG result = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);

	   // Check if the function has succeeded.
      if (result == ERROR_SUCCESS) 
      {
      	DWORD data;
		   DWORD dataSize = sizeof(data);
         result = ::RegQueryValueEx (hKey, _T("~MHz"), NULL, NULL, (LPBYTE)&data, &dataSize);
		
         if (result == ERROR_SUCCESS)
         {
            sSpeed.Format ("Speed: %dMHz ", data);
         }
         else
         {
            sSpeed = "Speed: Unknown ";
         }

      	TCHAR vendorData [64];
		   dataSize = sizeof (vendorData);

		   result = ::RegQueryValueEx (hKey, _T("VendorIdentifier"), NULL, NULL, (LPBYTE)vendorData, &dataSize);

         if (result == ERROR_SUCCESS)
         {
            sVendor.Format ("Vendor: %s ", vendorData);
         }
         else
         {
            sVendor = "Vendor: Unknown ";
         }
	   }

	   // Make sure to close the reg key
      RegCloseKey (hKey);

      CString sType;
	   switch (m_sysInfo.dwProcessorType)
      {
      case PROCESSOR_INTEL_386:
         sType = "Type: Intel 386 ";
         break;
      case PROCESSOR_INTEL_486:
         sType = "Type: Intel 486 ";
         break;
      case PROCESSOR_INTEL_PENTIUM:
         sType = "Type: Intel Pentium ";
         break;
      case PROCESSOR_MIPS_R4000:
         sType = "Type: MIPS ";
         break;
      case PROCESSOR_ALPHA_21064:
         sType = "Type: Alpha ";
         break;
      default:
         sType = "Type: Unknown ";
         break;
	   }
      
      CString sProcessors;
      sProcessors.Format("Number Of Processors: %lu ", m_sysInfo.dwNumberOfProcessors);

      CString sArchitecture;
      CString sProcessorLevel;
      CString sStepping;

      switch(m_sysInfo.wProcessorArchitecture)
      {
      case PROCESSOR_ARCHITECTURE_INTEL:
         sArchitecture = "Architecture: Intel ";
   		switch (m_sysInfo.wProcessorLevel) 
         {
			case 3:
            sProcessorLevel = "Level: 80386";
            {
               int iSteppingLevel = m_sysInfo.wProcessorRevision / 100;
               int iStepping = m_sysInfo.wProcessorRevision % 100;
               sStepping.Format("Stepping: %c%u ", iSteppingLevel, iStepping);
            }
				break;
			case 4:
            sProcessorLevel = "Level: 80486";
            {
               int iSteppingLevel = m_sysInfo.wProcessorRevision / 100;
               int iStepping = m_sysInfo.wProcessorRevision % 100;
               sStepping.Format("Stepping: %c%u ", iSteppingLevel, iStepping);
            }
				break;
			case 5:
            sProcessorLevel = "Level: Pentium";
            {
               typedef BOOL (*PIPFP)(DWORD);
				   PIPFP lpfn = (PIPFP)::GetProcAddress(GetModuleHandle("kernel32.dll"), "IsProcessorFeaturePresentA");
				   if (lpfn)
				   {
				      if ((lpfn)(PF_MMX_INSTRUCTIONS_AVAILABLE)) 
					   {
					      sProcessorLevel += _T (" MMX");
                  }
				   }

               int iModel = m_sysInfo.wProcessorRevision / 100;
               int iStepping = m_sysInfo.wProcessorRevision % 100;
               sStepping.Format("Stepping: %u-%u ", iModel, iStepping);
            }
				break;
         case 6:
            sProcessorLevel = "Level: Pentium II/Pro";
            {
               int iModel = m_sysInfo.wProcessorRevision / 100;
               int iStepping = m_sysInfo.wProcessorRevision % 100;
               sStepping.Format("Stepping: %u-%u ", iModel, iStepping);
            }
				break;
         default:
            sProcessorLevel.Format("Level: Unknown %u ", m_sysInfo.wProcessorLevel);
            {
               int iModel = m_sysInfo.wProcessorRevision / 100;
               int iStepping = m_sysInfo.wProcessorRevision % 100;
               sStepping.Format("Stepping: %u-%u ", iModel, iStepping);
            }
            break;
         }
         break;
      case PROCESSOR_ARCHITECTURE_MIPS:
         sArchitecture = "Architecture: MIPS ";
         switch(m_sysInfo.wProcessorLevel)
         {
         case 0004:
            sProcessorLevel = "Level: R4000 ";
				break;
         default:
            sProcessorLevel.Format("Level: Unknown %u ", m_sysInfo.wProcessorLevel);
            break;
         }
         sStepping.Format("Stepping: 00%u", m_sysInfo.wProcessorRevision);
         break;
      case PROCESSOR_ARCHITECTURE_ALPHA:
         sArchitecture = "Architecture: Alpha ";
         sProcessorLevel.Format("Level: %u ", m_sysInfo.wProcessorLevel);
         {
            int iModel = m_sysInfo.wProcessorRevision / 100;
            int iStepping = m_sysInfo.wProcessorRevision % 100;
            sStepping.Format("Stepping: %c%u ", iModel, iStepping);
         }
         break;
      case PROCESSOR_ARCHITECTURE_PPC:
         sArchitecture = "Architecture: PowerPC ";
         switch(m_sysInfo.wProcessorLevel)
         {
			case 1:
            sProcessorLevel = "Level: 601 ";
				break;
			case 3:
            sProcessorLevel = "Level: 603 ";
				break;
			case 4:
            sProcessorLevel = "Level: 604 ";
				break;
			case 6:
            sProcessorLevel = "Level: 603+ ";
				break;
			case 9:
            sProcessorLevel = "Level: 604+ ";
				break;
			case 20:
            sProcessorLevel = "Level: 620 ";
				break;
         default:
            sProcessorLevel.Format("Level: Unknown %u ", m_sysInfo.wProcessorLevel);
            break;
         }
         {
            int iModel = m_sysInfo.wProcessorRevision / 100;
            int iStepping = m_sysInfo.wProcessorRevision % 100;
            sStepping.Format("Stepping: %u.%u ", iModel, iStepping);
         }
         break;
      case PROCESSOR_ARCHITECTURE_UNKNOWN:
         sArchitecture = "Architecture: Unknown ";
         sProcessorLevel.Format("Level: Unknown %u ", m_sysInfo.wProcessorLevel);
         {
            int iModel = m_sysInfo.wProcessorRevision / 100;
            int iStepping = m_sysInfo.wProcessorRevision % 100;
            sStepping.Format("Stepping: %u-%u ", iModel, iStepping);
         }
         break;
      default:
         sArchitecture.Format("Architecture: Unknown %u ", m_sysInfo.wProcessorArchitecture);
         sProcessorLevel.Format("Level: Unknown %u ", m_sysInfo.wProcessorLevel);
         {
            int iModel = m_sysInfo.wProcessorRevision / 100;
            int iStepping = m_sysInfo.wProcessorRevision % 100;
            sStepping.Format("Stepping: %u-%u ", iModel, iStepping);
         }
         break;
      }

      sRC = sVendor + "," + sSpeed + "," + sType + "," + sProcessors + "," + sArchitecture + "," + sProcessorLevel + "," + sStepping;

      return sRC;
   }
};

class CMemoryInfo
{
protected:

public:

   CMemoryInfo(void)
   {
   }

   CString GetMemoryInfo(void)
   {
      CString sRC;

	   MEMORYSTATUS memoryStatus;

	   memset (&memoryStatus, sizeof (MEMORYSTATUS), 0);
	   memoryStatus.dwLength = sizeof (MEMORYSTATUS);
	   GlobalMemoryStatus (&memoryStatus);

      DWORD dwMinWSSize;
      DWORD dwMaxWSSize;

      ::GetProcessWorkingSetSize(GetCurrentProcess(), &dwMinWSSize, &dwMaxWSSize);

      sRC.Format("Memory Used %lu%%, Total Physical Memory %luKB, Physical Memory Available %luKB, Total Virtual Memory %luKB, Available Virtual Memory %luKB, Working Set Min : %luKB Max : %luKB .\r\n", memoryStatus.dwMemoryLoad, memoryStatus.dwTotalPhys / 1024, memoryStatus.dwAvailPhys / 1024, memoryStatus.dwTotalVirtual / 1024, memoryStatus.dwAvailVirtual / 1024, dwMinWSSize/1024, dwMaxWSSize/1024);

      return sRC;
   }

};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions