uint64_t ThreadCpuNanoTime() { #ifdefined(__linux__)
timespec now; if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now) != 0) { // TODO(415170313): For now just log an error. Once we have verified that // these don't happen often change this to a CHECK.
PLOG(ERROR) << "Failed to get thread cpu time";
} returnstatic_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; #else
UNIMPLEMENTED(WARNING); return -1; #endif
}
uint64_t ProcessCpuNanoTime() { #ifdefined(__linux__)
timespec now;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now); returnstatic_cast<uint64_t>(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; #else // We cannot use clock_gettime() here. Return the process wall clock time // (using art::NanoTime, which relies on gettimeofday()) as approximation of // the process CPU time instead. // // Note: clock_gettime() is available from macOS 10.12 (Darwin 16), but we try // to keep things simple here. return NanoTime(); #endif
}
int64_t end_sec = ts->tv_sec + ms / 1000;
constexpr int32_t int32_max = std::numeric_limits<int32_t>::max(); if (UNLIKELY(end_sec >= int32_max)) { // Either ms was intended to denote an infinite timeout, or we have a // problem. The former generally uses the largest possible millisecond // or nanosecond value. Log only in the latter case.
constexpr int64_t int64_max = std::numeric_limits<int64_t>::max(); if (ms != int64_max && ms != int64_max / (1000 * 1000)) {
LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
}
end_sec = int32_max - 1; // Allow for increment below.
}
ts->tv_sec = end_sec;
ts->tv_nsec = (ts->tv_nsec + (ms % 1000) * 1000000) + ns;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.