Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#722 Adding Host Name in Reporting #733

Merged
merged 9 commits into from
Dec 11, 2018
Merged

#722 Adding Host Name in Reporting #733

merged 9 commits into from
Dec 11, 2018

Conversation

jatinx
Copy link
Contributor

@jatinx jatinx commented Nov 29, 2018

PR with CLA signed

src/reporter.cc Outdated
@@ -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()) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linewrap

src/reporter.cc Outdated
@@ -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";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this printed only for the json dumper, or for all of them?
Put differently, i don't think it should be in the console output, it is getting rather crowded already.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed from console and added only to JSON

src/sysinfo.cc Outdated
#endif
return str;
#else
const unsigned COUNT = 64;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use HOST_NAME_MAX

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOST_NAME_MAX was not present on OSx, added local initialization.
The Job on Travis failed in config, can you please have a look at it?

src/sysinfo.cc Outdated
std::string GetSystemName() {
#if defined(BENCHMARK_OS_WINDOWS)
std::string str;
const unsigned COUNT = 32767;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why invent a magic number.
MAX_COMPUTERNAME_LENGTH+1 ?
And that being said, isn't that a rather too big to have as an array on stack?
Maybe use resized std::string?

@@ -16,6 +16,7 @@ static int AddContextCases() {
AddCases(TC_ConsoleErr,
{
{"%int[-/]%int[-/]%int %int:%int:%int$", MR_Default},
{"System Name", MR_Next},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "system name"?
How is this different from "host name"?
If it is exactly the "host name", just use that term?

@coveralls
Copy link

coveralls commented Nov 29, 2018

Coverage Status

Coverage increased (+0.06%) to 89.352% when pulling a651c6f on jatinx:HostName into eee8b05 on google:master.

@AppVeyorBot
Copy link

Build benchmark 1584 failed (commit f70f5b39af by @jatinx)

@AppVeyorBot
Copy link

Build benchmark 1585 failed (commit 7f7bb81561 by @jatinx)

@AppVeyorBot
Copy link

Build benchmark 1586 completed (commit 7e957a81be by @jatinx)

@AppVeyorBot
Copy link

Build benchmark 1587 completed (commit ffd0fa611f by @jatinx)

@AppVeyorBot
Copy link

Build benchmark 1589 completed (commit 7fda14a749 by @jatinx)

@jatinx
Copy link
Contributor Author

jatinx commented Nov 30, 2018

@LebedevRI did the asked changes, can you please have a look at it?

@jatinx
Copy link
Contributor Author

jatinx commented Dec 7, 2018

@LebedevRI its been a week, is something wrong with my design, would like some comments if thats the case.

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, lost track.

src/sysinfo.cc Outdated
str = hostname;
#else
std::wstring wStr = hostname;
str = std::string(wStr.begin(), wStr.end());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? Is this already done elsewhere in the library?
wchar is bigger than char, what makes sure that this isn't lossy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Standard wstring_convert to fix this

src/sysinfo.cc Outdated
#ifdef BENCHMARK_OS_MACOSX //Mac Doesnt have a copy for Host Name in it
#define HOST_NAME_MAX 64
#endif
const unsigned COUNT = HOST_NAME_MAX;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just use HOST_NAME_MAX directly, why do you need COUNT variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing unnecessary COUNT variable references, using macro directly

src/sysinfo.cc Outdated
int retVal = gethostname(hostname, COUNT);
if (retVal != 0) return std::string("Unable to Get Host Name");
return std::string(hostname);
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And others?

#if defined(__CYGWIN__)
#define BENCHMARK_OS_CYGWIN 1
#elif defined(_WIN32)
#define BENCHMARK_OS_WINDOWS 1
#if defined(__MINGW32__)
#define BENCHMARK_OS_MINGW 1
#endif
#elif defined(__APPLE__)
#define BENCHMARK_OS_APPLE 1
#include "TargetConditionals.h"
#if defined(TARGET_OS_MAC)
#define BENCHMARK_OS_MACOSX 1
#if defined(TARGET_OS_IPHONE)
#define BENCHMARK_OS_IOS 1
#endif
#endif
#elif defined(__FreeBSD__)
#define BENCHMARK_OS_FREEBSD 1
#elif defined(__NetBSD__)
#define BENCHMARK_OS_NETBSD 1
#elif defined(__OpenBSD__)
#define BENCHMARK_OS_OPENBSD 1
#elif defined(__linux__)
#define BENCHMARK_OS_LINUX 1
#elif defined(__native_client__)
#define BENCHMARK_OS_NACL 1
#elif defined(__EMSCRIPTEN__)
#define BENCHMARK_OS_EMSCRIPTEN 1
#elif defined(__rtems__)
#define BENCHMARK_OS_RTEMS 1
#elif defined(__Fuchsia__)
#define BENCHMARK_OS_FUCHSIA 1
#elif defined (__SVR4) && defined (__sun)
#define BENCHMARK_OS_SOLARIS 1
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only segregation needed here is POSIX vs non POSIX Compliance.
POSIX has gethostname

src/sysinfo.cc Outdated
if (!GetComputerName(hostname, &DWCOUNT))
return std::string("Unable to Get Host Name");
#ifndef UNICODE
str = hostname;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you 100.0% sure this is safe?
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-getcomputernamew

On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs copied to the destination buffer, not including the terminating null character.

I'd recommend to use 'returned' DWCOUNT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialising TCHAR to null and only copying DWCOUNT into string.

src/sysinfo.cc Outdated
str = hostname;
#else
std::wstring wStr = hostname;
str = std::string(wStr.begin(), wStr.end());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, same comment about DWCOUNT.

src/sysinfo.cc Outdated
str = std::string(wStr.begin(), wStr.end());
#endif
return str;
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#else
#else // defined(BENCHMARK_OS_WINDOWS)
// Catch-all POSIX block.

src/sysinfo.cc Outdated
int retVal = gethostname(hostname, COUNT);
if (retVal != 0) return std::string("Unable to Get Host Name");
return std::string(hostname);
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#endif
#endif // Catch-all POSIX block.

jatinx pushed a commit to jatinx/benchmark that referenced this pull request Dec 10, 2018
@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot
Copy link

CLAs look good, thanks!

@AppVeyorBot
Copy link

Build benchmark 1598 completed (commit 5c4b5786b0 by @)

@@ -77,6 +77,8 @@ bool JSONReporter::ReportContext(const Context& context) {
std::string walltime_value = LocalDateTimeString();
out << indent << FormatKV("date", walltime_value) << ",\n";

out << indent << FormatKV("host_name", context.sys_info.name) << ",\n";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We are sure that this won't contain \\? (see executable_name)
  2. Do we want to print "Unable to Get Host Name"?2
  3. I wonder if this should be after the executable_name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No. We should check and only output if it's available.

Copy link
Contributor Author

@jatinx jatinx Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes, I checked the output of the function, it just outputs the hostname for windows without the \\
  2. Addressed
  3. I am not sure about this one, it can be done, but since the output being in json only, is it desirable?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we still always printing it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks about right other than this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you talking about the 2nd point?
I have placed an empty string incase it fails to fetch the host name

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general seems to look ok, but i'd prefer to leave this for @dominichamon.

@AppVeyorBot
Copy link

Build benchmark 1600 completed (commit 58dde37f5d by @jatinx)

@@ -1293,6 +1293,14 @@ struct CPUInfo {
BENCHMARK_DISALLOW_COPY_AND_ASSIGN(CPUInfo);
};

struct SystemInformation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for consistency with CPUInfo, maybe SystemInfo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done, let me know if you want me proceed with this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/sysinfo.cc Outdated
TCHAR hostname[COUNT] = {'\0'};
DWORD DWCOUNT = COUNT;
if (!GetComputerName(hostname, &DWCOUNT))
return std::string("Unable to Get Host Name");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return empty string and don't print in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging requested changes

@jatinx
Copy link
Contributor Author

jatinx commented Dec 10, 2018

Sometimes, on travis-ci, the last build on MacOS fails in configure.
It gets resolved if I restart the build with a minor comment merge.
This has happened twice now.

@dominichamon @LebedevRI

@AppVeyorBot
Copy link

Build benchmark 1603 completed (commit f61aac7286 by @jatinx)

@AppVeyorBot
Copy link

Build benchmark 1604 completed (commit e16277d78a by @jatinx)

@dmah42 dmah42 merged commit 47a5f77 into google:master Dec 11, 2018
@dmah42
Copy link
Member

dmah42 commented Dec 11, 2018

Thanks! I'll keep an eye on the travis build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants