Skip to content

Instantly share code, notes, and snippets.

@nelhage
Last active December 23, 2015 07:39
Show Gist options
  • Save nelhage/6602767 to your computer and use it in GitHub Desktop.
Save nelhage/6602767 to your computer and use it in GitHub Desktop.
/* Excerpted from https://github.com/mongodb/mongo/blob/ea83ad3103fef1664e9385d48537c4163344ce8a/src/mongo/util/debug_util.h#L37 */
// The following declare one unique counter per enclosing function.
// NOTE The implementation double-increments on a match, but we don't really care.
#define MONGO_SOMETIMES( occasion, howOften ) for( static unsigned occasion = 0; ++occasion % howOften == 0; )
#define SOMETIMES MONGO_SOMETIMES
#define MONGO_OCCASIONALLY SOMETIMES( occasionally, 16 )
#define OCCASIONALLY MONGO_OCCASIONALLY
#define MONGO_RARELY SOMETIMES( rarely, 128 )
#define RARELY MONGO_RARELY
#define MONGO_ONCE for( static bool undone = true; undone; undone = false )
#define ONCE MONGO_ONCE
/* Excerpted from https://github.com/mongodb/mongo/blob/ea83ad3103fef1664e9385d48537c4163344ce8a/src/mongo/bson/optime.cpp#L32 */
{
bool toLog = false;
ONCE toLog = true;
RARELY toLog = true;
last.i++;
if ( last.i & 0x80000000 )
toLog = true;
if ( toLog ) {
log() << "clock skew detected prev: " << last.secs << " now: " << (unsigned) time(0)
<< std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment