NLMISC::CSystemInfo Class Reference

#include <system_info.h>


Detailed Description

Author:
Vianney Lecroart

Nevrax France

Date:
2000

Definition at line 42 of file system_info.h.

Static Public Member Functions

uint32 availablePhysicalMemory ()
std::string getOS ()
std::string getProc ()
uint64 getProcessorFrequency (bool quick=false)
bool hasCPUID ()
bool hasMMX ()
bool hasSSE ()
bool isNT ()
uint32 totalPhysicalMemory ()

Static Private Attributes

bool _HaveMMX = DetectMMX ()
bool _HaveSSE = DetectSSE ()


Member Function Documentation

uint32 NLMISC::CSystemInfo::availablePhysicalMemory  )  [static]
 

returns all the physical memory available on this computer

Definition at line 671 of file system_info.cpp.

References uint32.

00672 {
00673 #ifdef NL_OS_WINDOWS
00674 
00675         MEMORYSTATUS ms;
00676         GlobalMemoryStatus (&ms);
00677         return ms.dwAvailPhys;
00678 
00679 #elif defined NL_OS_UNIX
00680 
00681         return getSystemMemory (2) + getSystemMemory (4) + getSystemMemory (5);
00682 
00683 #endif
00684 
00685         return 0;
00686 }

string NLMISC::CSystemInfo::getOS  )  [static]
 

Definition at line 49 of file system_info.cpp.

References buffer, len, nlwarning, and NLMISC::toString().

00050 {
00051         string OSString = "Unknown";
00052 
00053 #ifdef NL_OS_WINDOWS
00054 
00055         OSVERSIONINFOEX osvi;
00056         BOOL bOsVersionInfoEx;
00057         const int BUFSIZE = 80;
00058 
00059         // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
00060         // If that fails, try using the OSVERSIONINFO structure.
00061 
00062         ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
00063         osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
00064 
00065         if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
00066         {
00067                 osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
00068                 if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) 
00069                 return OSString+" Can't GetVersionEx()";
00070         }
00071 
00072         switch (osvi.dwPlatformId)
00073         {
00074         // Test for the Windows NT product family.
00075         case VER_PLATFORM_WIN32_NT:
00076 
00077                 // Test for the specific product family.
00078                 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
00079                         OSString = "Microsoft Windows Server 2003 family ";
00080 
00081                 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
00082                         OSString = "Microsoft Windows XP ";
00083 
00084                 if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
00085                         OSString = "Microsoft Windows 2000 ";
00086 
00087                 if ( osvi.dwMajorVersion <= 4 )
00088                         OSString = "Microsoft Windows NT ";
00089 
00090          // Test for specific product on Windows NT 4.0 SP6 and later.
00091          if( bOsVersionInfoEx )
00092          {
00093                          // not available on visual 6 SP4, then comment it
00094 
00095 /*            // Test for the workstation type.
00096             if ( osvi.wProductType == VER_NT_WORKSTATION )
00097             {
00098                if( osvi.dwMajorVersion == 4 )
00099                   printf ( "Workstation 4.0 " );
00100                else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
00101                   printf ( "Home Edition " );
00102                else
00103                   printf ( "Professional " );
00104             }
00105             
00106             // Test for the server type.
00107             else if ( osvi.wProductType == VER_NT_SERVER )
00108             {
00109                if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 )
00110                {
00111                   if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
00112                      printf ( "Datacenter Edition " );
00113                   else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
00114                      printf ( "Enterprise Edition " );
00115                   else if ( osvi.wSuiteMask == VER_SUITE_BLADE )
00116                      printf ( "Web Edition " );
00117                   else
00118                      printf ( "Standard Edition " );
00119                }
00120 
00121                else if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
00122                {
00123                   if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
00124                      printf ( "Datacenter Server " );
00125                   else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
00126                      printf ( "Advanced Server " );
00127                   else
00128                      printf ( "Server " );
00129                }
00130 
00131                else  // Windows NT 4.0 
00132                {
00133                   if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
00134                      printf ("Server 4.0, Enterprise Edition " );
00135                   else
00136                      printf ( "Server 4.0 " );
00137                }
00138             }*/
00139                 }
00140                 else  // Test for specific product on Windows NT 4.0 SP5 and earlier
00141                 {
00142                         HKEY hKey;
00143                         char szProductType[BUFSIZE];
00144                         DWORD dwBufLen=BUFSIZE;
00145                         LONG lRet;
00146 
00147                         lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey );
00148                         if( lRet != ERROR_SUCCESS )
00149                                 return OSString + " Can't RegOpenKeyEx";
00150 
00151                         lRet = RegQueryValueEx( hKey, "ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
00152                         if( (lRet != ERROR_SUCCESS) || (dwBufLen > BUFSIZE) )
00153                                 return OSString + " Can't ReQueryValueEx";
00154 
00155                         RegCloseKey( hKey );
00156 
00157                         if ( lstrcmpi( "WINNT", szProductType) == 0 )
00158                                 OSString += "Workstation ";
00159                         if ( lstrcmpi( "LANMANNT", szProductType) == 0 )
00160                                 OSString += "Server ";
00161                         if ( lstrcmpi( "SERVERNT", szProductType) == 0 )
00162                                 OSString += "Advanced Server ";
00163          }
00164 
00165                 // Display service pack (if any) and build number.
00166 
00167                 if( osvi.dwMajorVersion == 4 && lstrcmpi( osvi.szCSDVersion, "Service Pack 6" ) == 0 )
00168                 {
00169                         HKEY hKey;
00170                         LONG lRet;
00171 
00172                         // Test for SP6 versus SP6a.
00173                         lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009", 0, KEY_QUERY_VALUE, &hKey );
00174                         if( lRet == ERROR_SUCCESS )
00175                                 OSString += toString("Service Pack 6a (Build %d) ", osvi.dwBuildNumber & 0xFFFF );
00176                         else // Windows NT 4.0 prior to SP6a
00177                         {
00178                                 OSString += toString("%s (Build %d) ", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
00179                         }
00180 
00181                         RegCloseKey( hKey );
00182                 }
00183                 else // Windows NT 3.51 and earlier or Windows 2000 and later
00184                 {
00185                         OSString += toString("%s (Build %d) ", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
00186                 }
00187 
00188                 break;
00189 
00190                 // Test for the Windows 95 product family.
00191                 case VER_PLATFORM_WIN32_WINDOWS:
00192 
00193                         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
00194                         {
00195                                 OSString = "Microsoft Windows 95 ";
00196                                 if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' )
00197                                         OSString += "OSR2 ";
00198                         } 
00199 
00200                         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
00201                         {
00202                                 OSString = "Microsoft Windows 98 ";
00203                                 if ( osvi.szCSDVersion[1] == 'A' )
00204                                         OSString += "SE ";
00205                         } 
00206 
00207                         if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
00208                         {
00209                                 OSString = "Microsoft Windows Millennium Edition ";
00210                         } 
00211                 break;
00212 
00213                 case VER_PLATFORM_WIN32s:
00214 
00215                         OSString = "Microsoft Win32s ";
00216                 break;
00217         }
00218 
00219         OSString += toString( "(%d.%d %d)", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF);
00220 
00221 #elif defined NL_OS_UNIX
00222         
00223         int fd = open("/proc/version", O_RDONLY);
00224         if (fd == -1)
00225         {
00226                 nlwarning ("SI: Can't get OS from /proc/version: %s", strerror (errno));
00227         }
00228         else
00229         {
00230                 char buffer[4096+1];
00231                 int len = read(fd, buffer, sizeof(buffer)-1);
00232                 close(fd);
00233                 
00234                 // remove the \n and set \0
00235                 buffer[len-1] = '\0';
00236                 
00237                 OSString = buffer;
00238         }
00239         
00240 #endif  // NL_OS_UNIX
00241         
00242         return OSString;
00243 }

string NLMISC::CSystemInfo::getProc  )  [static]
 

Definition at line 374 of file system_info.cpp.

References value.

00375 {
00376         string ProcString = "Unknown";
00377 
00378 #ifdef NL_OS_WINDOWS
00379 
00380         LONG result;
00381         char value[1024];
00382         DWORD valueSize;
00383         HKEY hKey;
00384 
00385         result = ::RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);
00386         if (result == ERROR_SUCCESS)
00387         {
00388                 // get processor name
00389                 valueSize = 1024;
00390                 result = ::RegQueryValueEx (hKey, _T("ProcessorNameString"), NULL, NULL, (LPBYTE)&value, &valueSize);
00391                 if (result == ERROR_SUCCESS)
00392                         ProcString = value;
00393                 else
00394                         ProcString = "UnknownProc";
00395 
00396                 ProcString += " / ";
00397 
00398                 // get processor identifier
00399                 valueSize = 1024;
00400                 result = ::RegQueryValueEx (hKey, _T("Identifier"), NULL, NULL, (LPBYTE)&value, &valueSize);
00401                 if (result == ERROR_SUCCESS)
00402                         ProcString += value;
00403                 else
00404                         ProcString += "UnknownIdentifier";
00405 
00406                 ProcString += " / ";
00407 
00408                 // get processor vendor
00409                 valueSize = 1024;
00410                 result = ::RegQueryValueEx (hKey, _T("VendorIdentifier"), NULL, NULL, (LPBYTE)&value, &valueSize);
00411                 if (result == ERROR_SUCCESS)
00412                         ProcString += value;
00413                 else
00414                         ProcString += "UnknownVendor";
00415 
00416                 ProcString += " / ";
00417                 
00418                 // get processor frequence
00419                 result = ::RegQueryValueEx (hKey, _T("~MHz"), NULL, NULL, (LPBYTE)&value, &valueSize);
00420                 if (result == ERROR_SUCCESS)
00421                 {
00422                         ProcString += itoa (*(int *)value, value, 10);
00423                         ProcString += "MHz";
00424                 }
00425                 else
00426                         ProcString += "UnknownFreq";
00427         }
00428 
00429         // Make sure to close the reg key
00430 
00431         RegCloseKey (hKey);
00432 
00433 #elif defined NL_OS_UNIX
00434 
00435 
00436 #endif
00437 
00438         return ProcString;
00439 }

uint64 NLMISC::CSystemInfo::getProcessorFrequency bool  quick = false  )  [static]
 

Gives an evalutation of the processor frequency, in hertz

Parameters:
quick true to do quick frequency evaluation
Warning:
Supports only intel architectures for now. Returns 0 if not implemented.

Definition at line 441 of file system_info.cpp.

References NLMISC::CTime::getPerformanceTime(), nlinfo, NLMISC::nlSleep(), NLMISC::TTicks, uint, and uint64.

00442 {
00443         static uint64 freq = 0;
00444 #ifdef  NL_CPU_INTEL
00445         static bool freqComputed = false;       
00446         if (freqComputed) return freq;
00447         
00448         if (!quick)
00449         {
00450                 TTicks bestNumTicks   = 0;
00451                 uint64 bestNumCycles;
00452                 uint64 numCycles;
00453                 const uint numSamples = 5;
00454                 const uint numLoops   = 50000000;
00455                 
00456                 volatile uint k; // prevent optimisation for the loop
00457                 for(uint l = 0; l < numSamples; ++l)
00458                 {       
00459                         TTicks startTick = NLMISC::CTime::getPerformanceTime();
00460                         uint64 startCycle = rdtsc();
00461                         volatile uint dummy = 0;
00462                         for(k = 0; k < numLoops; ++k)
00463                         {               
00464                                 ++ dummy;
00465                         }               
00466                         numCycles = rdtsc() - startCycle;
00467                         TTicks numTicks = NLMISC::CTime::getPerformanceTime() - startTick;
00468                         if (numTicks > bestNumTicks)
00469                         {               
00470                                 bestNumTicks  = numTicks;
00471                                 bestNumCycles = numCycles;
00472                         }
00473                 }
00474                 freq = (uint64) ((double) bestNumCycles * 1 / CTime::ticksToSecond(bestNumTicks));
00475         }
00476         else
00477         {
00478                 TTicks timeBefore = NLMISC::CTime::getPerformanceTime();
00479                 uint64 tickBefore = rdtsc();
00480                 nlSleep (100);
00481                 TTicks timeAfter = NLMISC::CTime::getPerformanceTime();
00482                 TTicks tickAfter = rdtsc();
00483                 
00484                 double timeDelta = CTime::ticksToSecond(timeAfter - timeBefore);
00485                 TTicks tickDelta = tickAfter - tickBefore;
00486                 
00487                 freq = (uint64) ((double)tickDelta / timeDelta);
00488         }
00489         
00490         nlinfo ("SI: CSystemInfo: Processor frequency is %.0f MHz", (float)freq/1000000.0);
00491         freqComputed = true;
00492 #endif // NL_CPU_INTEL
00493         return freq;
00494 }

bool NLMISC::CSystemInfo::hasCPUID  )  [static]
 

test wether the cpuid instruction is supported (always false on non intel architectures)

Definition at line 570 of file system_info.cpp.

References uint32.

00571 {
00572         #ifdef NL_OS_WINDOWS
00573                  uint32 result;
00574                  __asm
00575                  {
00576                          pushad
00577                          pushfd
00578                          //      If ID bit of EFLAGS can change, then cpuid is available
00579                          pushfd
00580                          pop  eax                                       // Get EFLAG
00581                          mov  ecx,eax
00582                          xor  eax,0x200000                      // Flip ID bit
00583                          push eax
00584                          popfd                                          // Write EFLAGS
00585                          pushfd      
00586                          pop  eax                                       // read back EFLAG
00587                          xor  eax,ecx
00588                          je   noCpuid                           // no flip -> no CPUID instr.
00589                          
00590                          popfd                                          // restore state
00591                          popad
00592                          mov  result, 1
00593                          jmp  CPUIDPresent
00594                 
00595                         noCpuid:
00596                          popfd                                      // restore state
00597                          popad
00598                          mov result, 0
00599                         CPUIDPresent:
00600                  }
00601                  return result == 1;
00602         #else
00603                  return false;
00604         #endif
00605 }

bool NLMISC::CSystemInfo::hasMMX void   )  [inline, static]
 

helps to know wether the processor features mmx instruction set This is initialized at started, so its fast (always false on non 0x86 architecture ...)

Definition at line 64 of file system_info.h.

References _HaveMMX.

Referenced by NL3D::computeGradient(), and NL3D::CTextureFar::rebuildPatch().

00064 {return _HaveMMX;}

bool NLMISC::CSystemInfo::hasSSE void   )  [inline, static]
 

helps to know wether the processor has streaming SIMD instructions (the OS must supports it) This is initialized at started, so its fast (always false on non 0x86 architecture ...)

Definition at line 70 of file system_info.h.

References _HaveSSE.

00070 {return _HaveSSE;}

bool NLMISC::CSystemInfo::isNT  )  [static]
 

Definition at line 608 of file system_info.cpp.

00609 {
00610 #ifdef NL_OS_WINDOWS
00611         OSVERSIONINFO ver;
00612         ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
00613         GetVersionEx(&ver);
00614         return ver.dwPlatformId == VER_PLATFORM_WIN32_NT;
00615 #else
00616         return false;
00617 #endif
00618 }

uint32 NLMISC::CSystemInfo::totalPhysicalMemory  )  [static]
 

returns all the physical memory on this computer

Definition at line 688 of file system_info.cpp.

References uint32.

00689 {
00690 #ifdef NL_OS_WINDOWS
00691 
00692         MEMORYSTATUS ms;
00693         GlobalMemoryStatus (&ms);
00694         return ms.dwTotalPhys;
00695 
00696 #elif defined NL_OS_UNIX
00697 
00698         return getSystemMemory (0);
00699         
00700 #endif
00701 
00702         return 0;
00703 }


Field Documentation

bool NLMISC::CSystemInfo::_HaveMMX = DetectMMX () [static, private]
 

Definition at line 567 of file system_info.cpp.

Referenced by hasMMX().

bool NLMISC::CSystemInfo::_HaveSSE = DetectSSE () [static, private]
 

Definition at line 568 of file system_info.cpp.

Referenced by hasSSE().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:37:04 2004 for NeL by doxygen 1.3.6