Tetsuo's two patches

This commit is contained in:
Kenneth Heafield 2013-05-29 05:30:39 -04:00
parent b5bb500773
commit 59bd7deb4b
2 changed files with 16 additions and 5 deletions

View File

@ -25,7 +25,7 @@ uint64_t HashForVocab(const char *str, std::size_t len);
inline uint64_t HashForVocab(const StringPiece &str) {
return HashForVocab(str.data(), str.length());
}
class ProbingVocabularyHeader;
struct ProbingVocabularyHeader;
} // namespace detail
class WriteWordsWrapper : public EnumerateVocab {

View File

@ -21,6 +21,21 @@ namespace util {
#if !defined(_WIN32) && !defined(_WIN64)
namespace {
// On Mac OS X, clock_gettime is not implemented.
// CLOCK_MONOTONIC is not defined either.
#ifdef __MACH__
#define CLOCK_MONOTONIC 0
int clock_gettime(int clk_id, struct timespec *tp) {
struct timeval tv;
gettimeofday(&tv, NULL);
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
return 0;
}
#endif // __MACH__
float FloatSec(const struct timeval &tv) {
return static_cast<float>(tv.tv_sec) + (static_cast<float>(tv.tv_usec) / 1000000.0);
}
@ -36,9 +51,7 @@ const char *SkipSpaces(const char *at) {
class RecordStart {
public:
RecordStart() {
#ifdef CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &started_);
#endif
}
const struct timespec &Started() const {
@ -79,9 +92,7 @@ void PrintUsage(std::ostream &out) {
out << "CPU:" << (FloatSec(usage.ru_utime) + FloatSec(usage.ru_stime));
struct timespec current;
#ifdef CLOCK_MONOTONIC
clock_gettime(CLOCK_MONOTONIC, &current);
#endif
out << "\treal:" << (FloatSec(current) - FloatSec(kRecordStart.Started())) << '\n';
#endif
}