Skip to content

Commit

Permalink
Merge 3f44492 into 19f7d5c
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinx committed Nov 29, 2018
2 parents 19f7d5c + 3f44492 commit f70f5b3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
9 changes: 9 additions & 0 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,14 @@ struct CPUInfo {
BENCHMARK_DISALLOW_COPY_AND_ASSIGN(CPUInfo);
};

struct SystemInformation {
std::string name;
static const SystemInformation& Get();
private:
SystemInformation();
BENCHMARK_DISALLOW_COPY_AND_ASSIGN(SystemInformation);
};

// Interface for custom benchmark result printers.
// By default, benchmark reports are printed to stdout. However an application
// can control the destination of the reports by calling
Expand All @@ -1302,6 +1310,7 @@ class BenchmarkReporter {
public:
struct Context {
CPUInfo const& cpu_info;
SystemInformation const& sys_info;
// The number of chars in the longest benchmark name.
size_t name_field_width;
static const char* executable_name;
Expand Down
5 changes: 4 additions & 1 deletion src/reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,

Out << LocalDateTimeString() << "\n";

const SystemInformation &sys_info = context.sys_info;
Out << "System Name "<< sys_info.name << "\n";

if (context.executable_name)
Out << "Running " << context.executable_name << "\n";

Expand Down Expand Up @@ -79,7 +82,7 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
// No initializer because it's already initialized to NULL.
const char *BenchmarkReporter::Context::executable_name;

BenchmarkReporter::Context::Context() : cpu_info(CPUInfo::Get()) {}
BenchmarkReporter::Context::Context() : cpu_info(CPUInfo::Get()), sys_info(SystemInformation::Get()) {}

std::string BenchmarkReporter::Run::benchmark_name() const {
std::string name = run_name;
Expand Down
31 changes: 31 additions & 0 deletions src/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,30 @@ std::vector<CPUInfo::CacheInfo> GetCacheSizes() {
#endif
}

std::string GetSystemName() {
#if defined(BENCHMARK_OS_WINDOWS)
std::string str;
const unsigned COUNT = 32767;
TCHAR hostname[COUNT];
DWORD DWCOUNT = COUNT;
if (!GetComputerName(hostname, &DWCOUNT))
return std::string("Unable to Get Host Name");
#ifndef UNICODE
str = hostname;
#else
std::wstring wStr = hostname;
str = std::string(wStr.begin(), wStr.end());
#endif
return str;
#else
const unsigned COUNT = 64;
char hostname[COUNT];
int retVal = gethostname(hostname, COUNT);
if (retVal != 0) return std::string("Unable to Get Host Name");
return std::string(hostname);
#endif
}

int GetNumCPUs() {
#ifdef BENCHMARK_HAS_SYSCTL
int NumCPU = -1;
Expand Down Expand Up @@ -609,4 +633,11 @@ CPUInfo::CPUInfo()
scaling_enabled(CpuScalingEnabled(num_cpus)),
load_avg(GetLoadAvg()) {}


const SystemInformation& SystemInformation::Get() {
static const SystemInformation* info = new SystemInformation();
return *info;
}

SystemInformation::SystemInformation() : name(GetSystemName()) {}
} // end namespace benchmark
1 change: 1 addition & 0 deletions test/reporter_output_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static int AddContextCases() {
AddCases(TC_ConsoleErr,
{
{"%int[-/]%int[-/]%int %int:%int:%int$", MR_Default},
{"System Name", MR_Next},
{"Running .*/reporter_output_test(\\.exe)?$", MR_Next},
{"Run on \\(%int X %float MHz CPU s?\\)", MR_Next},
});
Expand Down

0 comments on commit f70f5b3

Please sign in to comment.