From: Carl Hetherington Date: Tue, 23 Jul 2013 16:24:12 +0000 (+0100) Subject: Merge Windows CPU code from master. X-Git-Tag: v2.0.48~1337^2~149 X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=38cedccdb55e35c8f6b835cfb7405ab2160889e0 Merge Windows CPU code from master. --- diff --git a/src/lib/cross.cc b/src/lib/cross.cc index 4e3739f57..5ecbedf6e 100644 --- a/src/lib/cross.cc +++ b/src/lib/cross.cc @@ -39,6 +39,7 @@ using std::pair; using std::list; using std::ifstream; using std::string; +using std::wstring; using std::make_pair; using boost::shared_ptr; @@ -53,12 +54,11 @@ dcpomatic_sleep (int s) #endif } -/** @return A pair containing CPU model name and the number of processors */ -pair +/** @return A string of CPU information (model name etc.) */ +string cpu_info () { - pair info; - info.second = 0; + string info; #ifdef DCPOMATIC_LINUX ifstream f ("/proc/cpuinfo"); @@ -68,24 +68,48 @@ cpu_info () if (boost::algorithm::starts_with (l, "model name")) { string::size_type const c = l.find (':'); if (c != string::npos) { - info.first = l.substr (c + 2); + info = l.substr (c + 2); } - } else if (boost::algorithm::starts_with (l, "processor")) { - ++info.second; } } #endif #ifdef DCPOMATIC_OSX - size_t N = sizeof (info.second); - sysctlbyname ("hw.ncpu", &info.second, &N, 0, 0); char buffer[64]; - N = sizeof (buffer); + size_t N = sizeof (buffer); if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) { - info.first = buffer; + info = buffer; } #endif +#ifdef DCPOMATIC_WINDOWS + HKEY key; + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &key) != ERROR_SUCCESS) { + return info; + } + + DWORD type; + DWORD data; + if (RegQueryValueEx (key, L"ProcessorNameString", 0, &type, 0, &data) != ERROR_SUCCESS) { + return info; + } + + if (type != REG_SZ) { + return info; + } + + wstring value (data / sizeof (wchar_t), L'\0'); + if (RegQueryValueEx (key, L"ProcessorNameString", 0, 0, reinterpret_cast (&value[0]), &data) != ERROR_SUCCESS) { + RegCloseKey (key); + return info; + } + + info = string (value.begin(), value.end()); + + RegCloseKey (key); + +#endif + return info; } diff --git a/src/lib/cross.h b/src/lib/cross.h index a00fee679..58fa821c7 100644 --- a/src/lib/cross.h +++ b/src/lib/cross.h @@ -26,6 +26,6 @@ class Log; void dcpomatic_sleep (int); -extern std::pair cpu_info (); +extern std::string cpu_info (); extern void run_ffprobe (boost::filesystem::path, boost::filesystem::path, boost::shared_ptr); extern std::list > mount_info (); diff --git a/src/lib/film.cc b/src/lib/film.cc index b8a26501e..fc06bb058 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -242,8 +242,7 @@ Film::make_dcp () #else log()->log ("libdcp built in optimised mode."); #endif - pair const c = cpu_info (); - log()->log (String::compose ("CPU: %1, %2 processors", c.first, c.second)); + log()->log (String::compose ("CPU: %1, %2 processors", cpu_info(), boost::thread::hardware_concurrency ())); list > const m = mount_info (); for (list >::const_iterator i = m.begin(); i != m.end(); ++i) { log()->log (String::compose ("Mount: %1 %2", i->first, i->second));