File tree Expand file tree Collapse file tree 4 files changed +44
-1
lines changed
Expand file tree Collapse file tree 4 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -1293,6 +1293,14 @@ struct CPUInfo {
12931293 BENCHMARK_DISALLOW_COPY_AND_ASSIGN (CPUInfo);
12941294};
12951295
1296+ struct SystemInformation {
1297+ std::string name;
1298+ static const SystemInformation& Get ();
1299+ private:
1300+ SystemInformation ();
1301+ BENCHMARK_DISALLOW_COPY_AND_ASSIGN (SystemInformation);
1302+ };
1303+
12961304// Interface for custom benchmark result printers.
12971305// By default, benchmark reports are printed to stdout. However an application
12981306// can control the destination of the reports by calling
@@ -1302,6 +1310,7 @@ class BenchmarkReporter {
13021310 public:
13031311 struct Context {
13041312 CPUInfo const & cpu_info;
1313+ SystemInformation const & sys_info;
13051314 // The number of chars in the longest benchmark name.
13061315 size_t name_field_width;
13071316 static const char * executable_name;
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ bool JSONReporter::ReportContext(const Context& context) {
7777 std::string walltime_value = LocalDateTimeString ();
7878 out << indent << FormatKV (" date" , walltime_value) << " ,\n " ;
7979
80+ out << indent << FormatKV (" host_name" , context.sys_info .name ) << " ,\n " ;
81+
8082 if (Context::executable_name) {
8183 // windows uses backslash for its path separator,
8284 // which must be escaped in JSON otherwise it blows up conforming JSON
Original file line number Diff line number Diff line change @@ -79,7 +79,8 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out,
7979// No initializer because it's already initialized to NULL.
8080const char *BenchmarkReporter::Context::executable_name;
8181
82- BenchmarkReporter::Context::Context () : cpu_info(CPUInfo::Get()) {}
82+ BenchmarkReporter::Context::Context ()
83+ : cpu_info(CPUInfo::Get()), sys_info(SystemInformation::Get()) {}
8384
8485std::string BenchmarkReporter::Run::benchmark_name () const {
8586 std::string name = run_name;
Original file line number Diff line number Diff line change @@ -366,6 +366,30 @@ std::vector<CPUInfo::CacheInfo> GetCacheSizes() {
366366#endif
367367}
368368
369+ std::string GetSystemName () {
370+ #if defined(BENCHMARK_OS_WINDOWS)
371+ std::string str;
372+ const unsigned COUNT = MAX_COMPUTERNAME_LENGTH+1 ;
373+ TCHAR hostname[COUNT];
374+ DWORD DWCOUNT = COUNT;
375+ if (!GetComputerName (hostname, &DWCOUNT))
376+ return std::string (" Unable to Get Host Name" );
377+ #ifndef UNICODE
378+ str = hostname;
379+ #else
380+ std::wstring wStr = hostname;
381+ str = std::string (wStr.begin (), wStr.end ());
382+ #endif
383+ return str;
384+ #else
385+ const unsigned COUNT = HOST_NAME_MAX;
386+ char hostname[COUNT];
387+ int retVal = gethostname (hostname, COUNT);
388+ if (retVal != 0 ) return std::string (" Unable to Get Host Name" );
389+ return std::string (hostname);
390+ #endif
391+ }
392+
369393int GetNumCPUs () {
370394#ifdef BENCHMARK_HAS_SYSCTL
371395 int NumCPU = -1 ;
@@ -609,4 +633,11 @@ CPUInfo::CPUInfo()
609633 scaling_enabled(CpuScalingEnabled(num_cpus)),
610634 load_avg(GetLoadAvg()) {}
611635
636+
637+ const SystemInformation& SystemInformation::Get () {
638+ static const SystemInformation* info = new SystemInformation ();
639+ return *info;
640+ }
641+
642+ SystemInformation::SystemInformation () : name(GetSystemName()) {}
612643} // end namespace benchmark
You can’t perform that action at this time.
0 commit comments