本文整理汇总了C++中curTimeMicros64函数的典型用法代码示例。如果您正苦于以下问题:C++ curTimeMicros64函数的具体用法?C++ curTimeMicros64怎么用?C++ curTimeMicros64使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了curTimeMicros64函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: curTimeMicros64
void Stats::rotate() {
unsigned long long now = curTimeMicros64();
unsigned long long dt = now - _lastRotate;
if( dt >= _intervalMicros && _intervalMicros ) {
// rotate
curr->_dtMillis = (unsigned) (dt/1000);
_lastRotate = now;
curr = other();
curr->reset();
}
}
示例2: REMAPPRIVATEVIEW
/** We need to remap the private views periodically. otherwise they would become very large.
Call within write lock.
*/
void REMAPPRIVATEVIEW() {
static unsigned startAt;
static unsigned long long lastRemap;
dbMutex.assertWriteLocked();
dbMutex._remapPrivateViewRequested = false;
assert( !commitJob.hasWritten() );
if( 0 ) {
log() << "TEMP remapprivateview disabled for testing - will eventually run oom in this mode if db bigger than ram" << endl;
return;
}
// we want to remap all private views about every 2 seconds. there could be ~1000 views so
// we do a little each pass; beyond the remap time, more significantly, there will be copy on write
// faults after remapping, so doing a little bit at a time will avoid big load spikes on
// remapping.
unsigned long long now = curTimeMicros64();
double fraction = (now-lastRemap)/20000000.0;
set<MongoFile*>& files = MongoFile::getAllFiles();
unsigned sz = files.size();
if( sz == 0 )
return;
unsigned ntodo = (unsigned) (sz * fraction);
if( ntodo < 1 ) ntodo = 1;
if( ntodo > sz ) ntodo = sz;
const set<MongoFile*>::iterator b = files.begin();
const set<MongoFile*>::iterator e = files.end();
set<MongoFile*>::iterator i = b;
// skip to our starting position
for( unsigned x = 0; x < startAt; x++ ) {
i++;
if( i == e ) i = b;
}
startAt = (startAt + ntodo) % sz; // mark where to start next time
for( unsigned x = 0; x < ntodo; x++ ) {
dassert( i != e );
if( (*i)->isMongoMMF() ) {
MongoMMF *mmf = (MongoMMF*) *i;
assert(mmf);
if( mmf->willNeedRemap() ) {
mmf->willNeedRemap() = false;
mmf->remapThePrivateView();
}
i++;
if( i == e ) i = b;
}
}
}
示例3: curTimeMicros64
void CurOp::ensureStarted() {
if ( _start == 0 ) {
_start = curTimeMicros64();
// If ensureStarted() is invoked after setMaxTimeMicros(), then time limit tracking will
// start here. This is because time limit tracking can only commence after the
// operation is assigned a start time.
if (_maxTimeMicros > 0) {
_maxTimeTracker.setTimeLimit(_start, _maxTimeMicros);
}
}
}
示例4: socket
bool Socket::connect(SockAddr& remote) {
_remote = remote;
_fd = socket(remote.getType(), SOCK_STREAM, 0);
if ( _fd == INVALID_SOCKET ) {
LOG(_logLevel) << "ERROR: connect invalid socket " << errnoWithDescription() << endl;
return false;
}
if ( _timeout > 0 ) {
setTimeout( _timeout );
}
static const unsigned int connectTimeoutMillis = 5000;
ConnectBG bg(_fd, remote);
bg.go();
if ( bg.wait(connectTimeoutMillis) ) {
if ( bg.inError() ) {
warning() << "Failed to connect to "
<< _remote.getAddr() << ":" << _remote.getPort()
<< ", reason: " << bg.getErrnoWithDescription() << endl;
close();
return false;
}
}
else {
// time out the connect
close();
bg.wait(); // so bg stays in scope until bg thread terminates
warning() << "Failed to connect to "
<< _remote.getAddr() << ":" << _remote.getPort()
<< " after " << connectTimeoutMillis << " milliseconds, giving up." << endl;
return false;
}
if (remote.getType() != AF_UNIX)
disableNagle(_fd);
#ifdef SO_NOSIGPIPE
// ignore SIGPIPE signals on osx, to avoid process exit
const int one = 1;
setsockopt( _fd , SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(int));
#endif
_local = getLocalAddrForBoundSocketFd(_fd);
_fdCreationMicroSec = curTimeMicros64();
_awaitingHandshake = false;
return true;
}
示例5: socket
bool Socket::connect(SockAddr& remote) {
_remote = remote;
_fd = socket(remote.getType(), SOCK_STREAM, 0);
if ( _fd == INVALID_SOCKET ) {
LOG(_logLevel) << "ERROR: connect invalid socket " << errnoWithDescription() << endl;
return false;
}
if ( _timeout > 0 ) {
setTimeout( _timeout );
}
ConnectBG bg(_fd, remote);
bg.go();
if ( bg.wait(5000) ) {
if ( bg.inError() ) {
close();
return false;
}
}
else {
// time out the connect
close();
bg.wait(); // so bg stays in scope until bg thread terminates
return false;
}
if (remote.getType() != AF_UNIX)
disableNagle(_fd);
#ifdef SO_NOSIGPIPE
// ignore SIGPIPE signals on osx, to avoid process exit
const int one = 1;
setsockopt( _fd , SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(int));
#endif
_local = getLocalAddrForBoundSocketFd(_fd);
_fdCreationMicroSec = curTimeMicros64();
return true;
}
示例6: dassert
void CurOp::MaxTimeTracker::setTimeLimit(uint64_t startEpochMicros, uint64_t durationMicros) {
dassert(durationMicros != 0);
_enabled = true;
_targetEpochMicros = startEpochMicros + durationMicros;
uint64_t now = curTimeMicros64();
// If our accurate time source thinks time is not up yet, calculate the next target for
// our approximate time source.
if (_targetEpochMicros > now) {
_approxTargetServerMillis = Listener::getElapsedTimeMillis() +
static_cast<int64_t>((_targetEpochMicros - now) / 1000);
}
// Otherwise, set our approximate time source target such that it thinks time is already
// up.
else {
_approxTargetServerMillis = Listener::getElapsedTimeMillis();
}
}
示例7: statsThread
void statsThread() {
/*cout << "TEMP disabled statsthread" << endl;
if( 1 )
return;*/
Client::initThread("stats");
unsigned long long timeLastPass = 0;
while ( 1 ) {
{
/* todo: do we even need readlock here? if so for what? */
readlock lk("");
Top::completeSnapshot();
q = (q+1)%NStats;
Timing timing;
dbMutex.info().getTimingInfo(timing.start, timing.timeLocked);
unsigned long long now = curTimeMicros64();
if ( timeLastPass ) {
unsigned long long dt = now - timeLastPass;
unsigned long long dlocked = timing.timeLocked - tlast.timeLocked;
{
stringstream ss;
ss << dt / 1000 << '\t';
ss << dlocked / 1000 << '\t';
if ( dt )
ss << (dlocked*100)/dt << '%';
string s = ss.str();
if ( cmdLine.cpu )
log() << "cpu: " << s << endl;
lockStats[q] = s;
ClientCursor::idleTimeReport( (unsigned) ((dt - dlocked)/1000) );
}
}
timeLastPass = now;
tlast = timing;
}
sleepsecs(4);
}
}
示例8: _initAndListen
//.........这里部分代码省略.........
//
// The invariant is *not* a statement that `repairDatabasesAndCheckVersion` must return
// `MustDowngrade`. Instead, it is meant as a guardrail to protect future developers from
// accidentally buying into this behavior. New errors that are returned from the method
// may or may not want to go through a clean shutdown, and they likely won't want the
// program to return an exit code of `EXIT_NEED_DOWNGRADE`.
severe(LogComponent::kControl) << "** IMPORTANT: "
<< swNonLocalDatabases.getStatus().reason();
invariant(swNonLocalDatabases == ErrorCodes::MustDowngrade);
exitCleanly(EXIT_NEED_DOWNGRADE);
}
// Assert that the in-memory featureCompatibilityVersion parameter has been explicitly set. If
// we are part of a replica set and are started up with no data files, we do not set the
// featureCompatibilityVersion until a primary is chosen. For this case, we expect the in-memory
// featureCompatibilityVersion parameter to still be uninitialized until after startup.
if (canCallFCVSetIfCleanStartup &&
(!replSettings.usingReplSets() || swNonLocalDatabases.getValue())) {
invariant(serverGlobalParams.featureCompatibility.isVersionInitialized());
}
if (storageGlobalParams.upgrade) {
log() << "finished checking dbs";
exitCleanly(EXIT_CLEAN);
}
// Start up health log writer thread.
HealthLog::get(startupOpCtx.get()).startup();
auto const globalAuthzManager = AuthorizationManager::get(serviceContext);
uassertStatusOK(globalAuthzManager->initialize(startupOpCtx.get()));
// This is for security on certain platforms (nonce generation)
srand((unsigned)(curTimeMicros64()) ^ (unsigned(uintptr_t(&startupOpCtx))));
if (globalAuthzManager->shouldValidateAuthSchemaOnStartup()) {
Status status = verifySystemIndexes(startupOpCtx.get());
if (!status.isOK()) {
log() << redact(status);
if (status == ErrorCodes::AuthSchemaIncompatible) {
exitCleanly(EXIT_NEED_UPGRADE);
} else if (status == ErrorCodes::NotMaster) {
// Try creating the indexes if we become master. If we do not become master,
// the master will create the indexes and we will replicate them.
} else {
quickExit(EXIT_FAILURE);
}
}
// SERVER-14090: Verify that auth schema version is schemaVersion26Final.
int foundSchemaVersion;
status =
globalAuthzManager->getAuthorizationVersion(startupOpCtx.get(), &foundSchemaVersion);
if (!status.isOK()) {
log() << "Auth schema version is incompatible: "
<< "User and role management commands require auth data to have "
<< "at least schema version " << AuthorizationManager::schemaVersion26Final
<< " but startup could not verify schema version: " << status;
log() << "To manually repair the 'authSchema' document in the admin.system.version "
"collection, start up with --setParameter "
"startupAuthSchemaValidation=false to disable validation.";
exitCleanly(EXIT_NEED_UPGRADE);
}
if (foundSchemaVersion <= AuthorizationManager::schemaVersion26Final) {
log() << "This server is using MONGODB-CR, an authentication mechanism which "
示例9: networkWarnWithDescription
//.........这里部分代码省略.........
if (!setBlock(_fd, false)) {
networkWarnWithDescription(*this, "set socket to non-blocking mode");
return false;
}
const Milliseconds connectTimeoutMillis(static_cast<int64_t>(
_timeout > 0 ? std::min(kMaxConnectTimeoutMS, (_timeout * 1000)) : kMaxConnectTimeoutMS));
const Date_t expiration = Date_t::now() + connectTimeoutMillis;
bool connectSucceeded = ::connect(_fd, _remote.raw(), _remote.addressSize) == 0;
if (!connectSucceeded) {
#ifdef _WIN32
if (WSAGetLastError() != WSAEWOULDBLOCK) {
networkWarnWithDescription(*this, "connect");
return false;
}
#else
if (errno != EINTR && errno != EINPROGRESS) {
networkWarnWithDescription(*this, "connect");
return false;
}
#endif
pollfd pfd;
pfd.fd = _fd;
pfd.events = POLLOUT;
while (true) {
const auto timeout = std::max(Milliseconds(0), expiration - Date_t::now());
int pollReturn = socketPoll(&pfd, 1, timeout.count());
#ifdef _WIN32
if (pollReturn == SOCKET_ERROR) {
networkWarnWithDescription(*this, "poll");
return false;
}
#else
if (pollReturn == -1) {
if (errno != EINTR) {
networkWarnWithDescription(*this, "poll");
return false;
}
// EINTR in poll, try again
continue;
}
#endif
// No activity for the full duration of the timeout.
if (pollReturn == 0) {
warning() << "Failed to connect to " << _remote.getAddr() << ":"
<< _remote.getPort() << " after " << connectTimeoutMillis
<< " milliseconds, giving up.";
return false;
}
// We had a result, see if there's an error on the socket.
int optVal;
socklen_t optLen = sizeof(optVal);
if (::getsockopt(
_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&optVal), &optLen) == -1) {
networkWarnWithDescription(*this, "getsockopt");
return false;
}
if (optVal != 0) {
networkWarnWithDescription(*this, "checking socket for error after poll", optVal);
return false;
}
// We had activity and we don't have errors on the socket, we're connected.
break;
}
}
if (!setBlock(_fd, true)) {
networkWarnWithDescription(*this, "could not set socket to blocking mode");
return false;
}
if (_timeout > 0) {
setTimeout(_timeout);
}
if (remote.getType() != AF_UNIX)
disableNagle(_fd);
#ifdef SO_NOSIGPIPE
// ignore SIGPIPE signals on osx, to avoid process exit
const int one = 1;
setsockopt(_fd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(int));
#endif
_local = getLocalAddrForBoundSocketFd(_fd);
_fdCreationMicroSec = curTimeMicros64();
_awaitingHandshake = false;
return true;
}
示例10: curTimeMicros64
void CurOp::ensureStarted() {
if ( _start == 0 )
_start = curTimeMicros64();
}
示例11: _initAndListen
//.........这里部分代码省略.........
ss << "repairpath (" << storageGlobalParams.repairpath << ") does not exist";
uassert(12590, ss.str().c_str(), boost::filesystem::exists(storageGlobalParams.repairpath));
}
// TODO: This should go into a MONGO_INITIALIZER once we have figured out the correct
// dependencies.
if (snmpInit) {
snmpInit();
}
if (!storageGlobalParams.readOnly) {
boost::filesystem::remove_all(storageGlobalParams.dbpath + "/_tmp/");
}
if (mmapv1GlobalOptions.journalOptions & MMAPV1Options::JournalRecoverOnly)
return EXIT_NET_ERROR;
if (mongodGlobalParams.scriptingEnabled) {
ScriptEngine::setup();
}
auto startupOpCtx = getGlobalServiceContext()->makeOperationContext(&cc());
repairDatabasesAndCheckVersion(startupOpCtx.get());
if (storageGlobalParams.upgrade) {
log() << "finished checking dbs";
exitCleanly(EXIT_CLEAN);
}
uassertStatusOK(getGlobalAuthorizationManager()->initialize(startupOpCtx.get()));
/* this is for security on certain platforms (nonce generation) */
srand((unsigned)(curTimeMicros64() ^ startupSrandTimer.micros()));
// The snapshot thread provides historical collection level and lock statistics for use
// by the web interface. Only needed when HTTP is enabled.
if (serverGlobalParams.isHttpInterfaceEnabled) {
statsSnapshotThread.go();
invariant(dbWebServer);
stdx::thread web(stdx::bind(&webServerListenThread, dbWebServer));
web.detach();
}
#ifndef _WIN32
mongo::signalForkSuccess();
#endif
AuthorizationManager* globalAuthzManager = getGlobalAuthorizationManager();
if (globalAuthzManager->shouldValidateAuthSchemaOnStartup()) {
Status status = authindex::verifySystemIndexes(startupOpCtx.get());
if (!status.isOK()) {
log() << redact(status);
exitCleanly(EXIT_NEED_UPGRADE);
}
// SERVER-14090: Verify that auth schema version is schemaVersion26Final.
int foundSchemaVersion;
status =
globalAuthzManager->getAuthorizationVersion(startupOpCtx.get(), &foundSchemaVersion);
if (!status.isOK()) {
log() << "Auth schema version is incompatible: "
<< "User and role management commands require auth data to have "
<< "at least schema version " << AuthorizationManager::schemaVersion26Final
<< " but startup could not verify schema version: " << status;
exitCleanly(EXIT_NEED_UPGRADE);
示例12: run
void run() {
int iterations = 1000*1000;
while(iterations--){
curTimeMicros64();
}
}
示例13: run
void run(){
if ( _token.size() == 0 && _name.size() == 0 ){
log(1) << "mms not configured" << endl;
return;
}
if ( _token.size() == 0 ){
log() << "no token for mms - not running" << endl;
return;
}
if ( _name.size() == 0 ){
log() << "no name for mms - not running" << endl;
return;
}
log() << "mms monitor staring... token:" << _token << " name:" << _name << " interval: " << _secsToSleep << endl;
unsigned long long lastTime = 0;
unsigned long long lastLockTime = 0;
while ( ! inShutdown() ){
sleepsecs( _secsToSleep );
stringstream url;
url << _baseurl << _token << "?";
url << "monitor_name=" << _name << "&";
url << "version=" << versionString << "&";
url << "git_hash=" << gitVersion() << "&";
{ //percent_locked
unsigned long long time = curTimeMicros64();
unsigned long long start , lock;
dbMutexInfo.timingInfo( start , lock );
if ( lastTime ){
double timeDiff = (double) (time - lastTime);
double lockDiff = (double) (lock - lastLockTime);
url << "percent_locked=" << (int)ceil( 100 * ( lockDiff / timeDiff ) ) << "&";
}
lastTime = time;
lastLockTime = lock;
}
vector< string > dbNames;
getDatabaseNames( dbNames );
boost::intmax_t totalSize = 0;
for ( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) {
boost::intmax_t size = dbSize( i->c_str() );
totalSize += size;
}
url << "data_size=" << totalSize / ( 1024 * 1024 ) << "&";
/* TODO:
message_operations
update_operations
insert_operations
get_more_operations
delete_operations
kill_cursors_operations
*/
log(1) << "mms url: " << url.str() << endl;
try {
HttpClient c;
map<string,string> headers;
stringstream ss;
int rc = c.get( url.str() , headers , ss );
log(1) << "\t response code: " << rc << endl;
if ( rc != 200 ){
log() << "mms error response code:" << rc << endl;
log(1) << "mms error body:" << ss.str() << endl;
}
}
catch ( std::exception& e ){
log() << "mms get exception: " << e.what() << endl;
}
}
}
示例14: durThread
//.........这里部分代码省略.........
// Now that the write intents have been copied to the buffer, the commit job is
// free to be reused. We need to reset the commit job's contents while under
// the S flush lock, because otherwise someone might have done a write and this
// would wipe out their changes without ever being committed.
commitJob.committingReset();
double systemMemoryPressurePercentage =
ProcessInfo::getSystemMemoryPressurePercentage();
// Now that the in-memory modifications have been collected, we can potentially
// release the flush lock if remap is not necessary.
// When we remap due to memory pressure, we look at two criteria
// 1. If the amount of 4k pages touched exceeds 512 MB,
// a reasonable estimate of memory pressure on Linux.
// 2. Check if the amount of free memory on the machine is running low,
// since #1 is underestimates the memory pressure on Windows since
// commits in 64MB chunks.
const bool shouldRemap = (estimatedPrivateMapSize >= UncommittedBytesLimit) ||
(systemMemoryPressurePercentage > 0.0) ||
(commitCounter % NumCommitsBeforeRemap == 0) ||
(mmapv1GlobalOptions.journalOptions & MMAPV1Options::JournalAlwaysRemap);
double remapFraction = 0.0;
if (shouldRemap) {
// We want to remap all private views about every 2 seconds. There could be
// ~1000 views so we do a little each pass. There will be copy on write
// faults after remapping, so doing a little bit at a time will avoid big
// load spikes when the pages are touched.
//
// TODO: Instead of the time-based logic above, consider using ProcessInfo
// and watching for getResidentSize to drop, which is more precise.
remapFraction = (curTimeMicros64() - remapLastTimestamp) / 2000000.0;
if (mmapv1GlobalOptions.journalOptions & MMAPV1Options::JournalAlwaysRemap) {
remapFraction = 1;
} else {
// We don't want to get close to the UncommittedBytesLimit
const double remapMemFraction =
estimatedPrivateMapSize / ((double)UncommittedBytesLimit);
remapFraction = std::max(remapMemFraction, remapFraction);
remapFraction = std::max(systemMemoryPressurePercentage, remapFraction);
}
} else {
LOG(4) << "Early release flush lock";
// We will not be doing a remap so drop the flush lock. That way we will be
// doing the journal I/O outside of lock, so other threads can proceed.
invariant(!shouldRemap);
autoFlushLock.release();
}
buffer->journalListenerToken = getJournalListener()->getToken();
// Request async I/O to the journal. This may block.
journalWriter.writeBuffer(buffer, commitNumber);
// Data has now been written to the shared view. If remap was requested, we
// would still be holding the S flush lock here, so just upgrade it and
// perform the remap.
if (shouldRemap) {
// Need to wait for the previously scheduled journal writes to complete
// before any remap is attempted.
journalWriter.flush();
示例15: memset
void Stats::S::reset() {
memset(this, 0, sizeof(*this));
_startTimeMicros = curTimeMicros64();
}