//------------------------------------------------------------------------------------- void DBTransaction::commit() { KBE_ASSERT(!committed_); uint64 startTime = timestamp(); try { pdbi_->query(SQL_COMMIT, false); } catch (DBException & e) { bool ret = static_cast<DBInterfaceMysql*>(pdbi_)->processException(e); KBE_ASSERT(ret); } uint64 duration = timestamp() - startTime; if(duration > stampsPerSecond() * 0.2f) { WARNING_MSG(fmt::format("DBTransaction::commit(): took {:.2f} seconds\n", (double(duration)/stampsPerSecondD()))); } committed_ = true; }
//------------------------------------------------------------------------------------- double Proxy::getTimeSinceHeardFromClient() const { if(clientMailbox() == NULL || clientMailbox()->getChannel() == NULL || clientMailbox()->getChannel()->pEndPoint() == NULL) return DBL_MAX; return double(timestamp() - clientMailbox()->getChannel()->lastReceivedTime()) / stampsPerSecondD(); }
//------------------------------------------------------------------------------------- double EventDispatcher::calculateWait() const { double maxWait = maxWait_; if (!pTimers_->empty()) { maxWait = std::min(maxWait, pTimers_->nextExp(timestamp()) / stampsPerSecondD()); } return maxWait; }
//------------------------------------------------------------------------------------- bool DBTaskBase::process() { uint64 startTime = timestamp(); bool ret = db_thread_process(); uint64 duration = startTime - initTime_; if(duration > stampsPerSecond()) { WARNING_MSG(fmt::format("DBTask::process(): delay {0:.2f} seconds, try adjusting the kbengine[_defs].xml(numConnections) and MySQL(my.cnf->max_connections or innodb_flush_log_at_trx_commit)!\nsql:({1})\n", (double(duration)/stampsPerSecondD()), pdbi_->lastquery())); } duration = timestamp() - startTime; if (duration > stampsPerSecond() * 0.2f) { WARNING_MSG(fmt::format("DBTask::process(): took {:.2f} seconds\nsql:({})\n", (double(duration)/stampsPerSecondD()), pdbi_->lastquery())); } return ret; }
//------------------------------------------------------------------------------------- void DBTransaction::commit() { KBE_ASSERT(!committed_); uint64 startTime = timestamp(); pdbi_->query(SQL_COMMIT, false); uint64 duration = timestamp() - startTime; if(duration > stampsPerSecond() * 0.2f) { WARNING_MSG(fmt::format("DBTransaction::commit(): took {:.2f} seconds\n", (double(duration)/stampsPerSecondD()))); } committed_ = true; }
//------------------------------------------------------------------------------------- TimerHandle EventDispatcher::addTimerCommon(int64 microseconds, TimerHandler * handler, void * arg, bool recurrent) { KBE_ASSERT(handler); if (microseconds <= 0) return TimerHandle(); uint64 interval = int64( (((double)microseconds)/1000000.0) * stampsPerSecondD()); TimerHandle handle = pTimers_->add(timestamp() + interval, recurrent ? interval : 0, handler, arg); return handle; }
//------------------------------------------------------------------------------------- double EventDispatcher::calculateWait() const { double maxWait = maxWait_; if (!pTimers_->empty()) { maxWait = std::min(maxWait, pTimers_->nextExp(timestamp()) / stampsPerSecondD()); } ChildDispatchers::const_iterator iter = childDispatchers_.begin(); while (iter != childDispatchers_.end()) { maxWait = std::min(maxWait, (*iter)->calculateWait()); ++iter; } return maxWait; }
std::string ErrorReporter::addressErrorToString( const Address & address, const std::string & errorString, const ErrorReportAndCount & reportAndCount, const uint64 & now) { int64 deltaStamps = now - reportAndCount.lastReportStamps; double deltaMillis = 1000 * deltaStamps / stampsPerSecondD(); char * buf = NULL; int bufLen = 64; int strLen = bufLen; do { bufLen = strLen + 1; delete [] buf; buf = new char[ bufLen ]; #if KBE_PLATFORM == PLATFORM_WIN32 strLen = _snprintf(buf, bufLen, "%d reports of '%s' " "in the last %.00fms", reportAndCount.count, addressErrorToString(address, errorString).c_str(), deltaMillis); if (strLen == -1) strLen = (bufLen - 1) * 2; #else strLen = snprintf(buf, bufLen, "%d reports of '%s' " "in the last %.00fms", reportAndCount.count, addressErrorToString(address, errorString).c_str(), deltaMillis); #endif } while (strLen >= bufLen); std::string out(buf); delete [] buf; return out; }
/** 将秒为单位的时间转换为每秒所耗的stamps */ inline uint64 secondsToStamps(float seconds) { return (uint64)(seconds * stampsPerSecondD()); }
inline TimeStamp TimeStamp::fromSeconds( double seconds ) { return uint64( seconds * stampsPerSecondD() ); }
inline double TimeStamp::toSeconds( uint64 stamps ) { return double( stamps )/stampsPerSecondD(); }
inline double stampsToSeconds( uint64 stamps ) { return double( stamps )/stampsPerSecondD(); }
//------------------------------------------------------------------------------------- double EventDispatcher::proportionalSpareTime() const { double ret = (double)(int64)(totSpareTime_ - oldSpareTime_); return ret / stampsPerSecondD(); return 0; }