void Throttler::limit(ThreadCtx& threadCtx, double deltaProgress) { // now should be before taking the lock std::chrono::time_point<Clock> now = Clock::now(); double sleepTimeSeconds = calculateSleep(deltaProgress, now); if (throttlerLogTimeMillis_ > 0) { printPeriodicLogs(now, deltaProgress); } if (sleepTimeSeconds > 0) { /* sleep override */ PerfStatCollector statCollector(threadCtx, PerfStatReport::THROTTLER_SLEEP); std::this_thread::sleep_for( std::chrono::duration<double>(sleepTimeSeconds)); } }
int WdtSocket::getUnackedBytes() const { #ifdef WDT_HAS_SOCKIOS_H int numUnackedBytes; int ret; { PerfStatCollector statCollector(threadCtx_, PerfStatReport::IOCTL); ret = ::ioctl(fd_, SIOCOUTQ, &numUnackedBytes); } if (ret != 0) { PLOG(ERROR) << "Failed to get unacked bytes for socket " << fd_; numUnackedBytes = -1; } return numUnackedBytes; #else LOG(WARNING) << "Wdt has no way to determine unacked bytes for socket"; return -1; #endif }
int64_t WdtSocket::writeWithAbortCheck(const char *buf, int64_t nbyte, int timeoutMs, bool tryFull) { PerfStatCollector statCollector(threadCtx_, PerfStatReport::SOCKET_WRITE); return ioWithAbortCheck(::write, buf, nbyte, timeoutMs, tryFull); }