|
52 | 52 | #include <limits>
|
53 | 53 | #include <memory>
|
54 | 54 | #include <sstream>
|
| 55 | +#include <locale> |
| 56 | +#include <codecvt> |
55 | 57 |
|
56 | 58 | #include "check.h"
|
57 | 59 | #include "cycleclock.h"
|
@@ -366,6 +368,35 @@ std::vector<CPUInfo::CacheInfo> GetCacheSizes() {
|
366 | 368 | #endif
|
367 | 369 | }
|
368 | 370 |
|
| 371 | +std::string GetSystemName() { |
| 372 | +#if defined(BENCHMARK_OS_WINDOWS) |
| 373 | + std::string str; |
| 374 | + const unsigned COUNT = MAX_COMPUTERNAME_LENGTH+1; |
| 375 | + TCHAR hostname[COUNT] = {'\0'}; |
| 376 | + DWORD DWCOUNT = COUNT; |
| 377 | + if (!GetComputerName(hostname, &DWCOUNT)) |
| 378 | + return std::string("Unable to Get Host Name"); |
| 379 | +#ifndef UNICODE |
| 380 | + str = std::string(hostname, DWCOUNT); |
| 381 | +#else |
| 382 | + //Using wstring_convert, Is deprecated in C++17 |
| 383 | + using convert_type = std::codecvt_utf8<wchar_t>; |
| 384 | + std::wstring_convert<convert_type, wchar_t> converter; |
| 385 | + std::wstring wStr(hostname, DWCOUNT); |
| 386 | + str = converter.to_bytes(wStr); |
| 387 | +#endif |
| 388 | + return str; |
| 389 | +#else // defined(BENCHMARK_OS_WINDOWS) |
| 390 | +#ifdef BENCHMARK_OS_MACOSX //Mac Doesnt have HOST_NAME_MAX defined |
| 391 | +#define HOST_NAME_MAX 64 |
| 392 | +#endif |
| 393 | + char hostname[HOST_NAME_MAX]; |
| 394 | + int retVal = gethostname(hostname, HOST_NAME_MAX); |
| 395 | + if (retVal != 0) return std::string("Unable to Get Host Name"); |
| 396 | + return std::string(hostname); |
| 397 | +#endif // Catch-all POSIX block. |
| 398 | +} |
| 399 | + |
369 | 400 | int GetNumCPUs() {
|
370 | 401 | #ifdef BENCHMARK_HAS_SYSCTL
|
371 | 402 | int NumCPU = -1;
|
@@ -609,4 +640,11 @@ CPUInfo::CPUInfo()
|
609 | 640 | scaling_enabled(CpuScalingEnabled(num_cpus)),
|
610 | 641 | load_avg(GetLoadAvg()) {}
|
611 | 642 |
|
| 643 | + |
| 644 | +const SystemInformation& SystemInformation::Get() { |
| 645 | + static const SystemInformation* info = new SystemInformation(); |
| 646 | + return *info; |
| 647 | +} |
| 648 | + |
| 649 | +SystemInformation::SystemInformation() : name(GetSystemName()) {} |
612 | 650 | } // end namespace benchmark
|
0 commit comments