本文整理汇总了C++中MemoryMappedFile::mapWithOptions方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryMappedFile::mapWithOptions方法的具体用法?C++ MemoryMappedFile::mapWithOptions怎么用?C++ MemoryMappedFile::mapWithOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryMappedFile
的用法示例。
在下文中一共展示了MemoryMappedFile::mapWithOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: say
void say(unsigned long long n, int ms, string s) {
unsigned long long rps = n*1000/ms;
cout << "stats " << setw(33) << left << s << ' ' << right << setw(9) << rps << ' ' << right << setw(5) << ms << "ms ";
if( showDurStats() )
cout << dur::stats.curr->_asCSV();
cout << endl;
/* if you want recording of the timings, place the password for the perf database
in ./../settings.py:
pstatspassword="<pwd>"
*/
const char *fn = "../../settings.py";
static bool ok = true;
if( ok ) {
DEV {
// no writing to perf db if dev
}
else if( !exists(fn) ) {
cout << "no ../../settings.py file found. will not write perf stats to db" << endl;
}
else {
try {
if( conn == 0 ) {
MemoryMappedFile f;
const char *p = (const char *) f.mapWithOptions(fn, MongoFile::READONLY);
string pwd;
{
const char *q = str::after(p, "pstatspassword=\"");
if( *q == 0 ) {
cout << "info perftests.cpp: no pstatspassword= in settings.py" << endl;
ok = false;
}
else {
pwd = str::before(q, '\"');
}
}
if( ok ) {
conn = new DBClientConnection(false, 0, 10);
string err;
if( conn->connect("mongo05.10gen.cust.cbici.net", err) ) {
if( !conn->auth("perf", "perf", pwd, err) ) {
cout << "info: authentication with stats db failed: " << err << endl;
assert(false);
}
}
else {
cout << err << " (to log perfstats)" << endl;
ok = false;
}
}
}
if( conn && !conn->isFailed() ) {
const char *ns = "perf.pstats";
if( perfHist ) {
static bool needver = true;
try {
// try to report rps from last time */
Query q;
{
BSONObjBuilder b;
b.append("host",getHostName()).append("test",s).append("dur",cmdLine.dur);
DEV b.append("info.DEBUG",true);
else b.appendNull("info.DEBUG");
if( sizeof(int*) == 4 ) b.append("info.bits", 32);
else b.appendNull("info.bits");
q = Query(b.obj()).sort("when",-1);
}
//cout << q.toString() << endl;
BSONObj fields = BSON( "rps" << 1 << "info" << 1 );
vector<BSONObj> v;
conn->findN(v, ns, q, perfHist, 0, &fields);
for( vector<BSONObj>::iterator i = v.begin(); i != v.end(); i++ ) {
BSONObj o = *i;
double lastrps = o["rps"].Number();
if( lastrps ) {
cout << "stats " << setw(33) << right << "new/old:" << ' ' << setw(9);
cout << fixed << setprecision(2) << rps / lastrps;
if( needver ) {
cout << " " << o.getFieldDotted("info.git").toString();
}
cout << '\n';
}
}
} catch(...) { }
cout.flush();
needver = false;
}
{
bob b;
b.append("host", getHostName());
b.appendTimeT("when", time(0));
b.append("test", s);
b.append("rps", (int) rps);
b.append("millis", ms);
b.appendBool("dur", cmdLine.dur);
if( showDurStats() && cmdLine.dur )
b.append("durStats", dur::stats.curr->_asObj());
{
//.........这里部分代码省略.........
示例2: connect
/* if you want recording of the timings, place the password for the perf database
in ./../settings.py:
pstatspassword="<pwd>"
*/
void connect() {
if( once )
return;
++once;
// no writing to perf db if _DEBUG
DEV return;
const char *fn = "../../settings.py";
if( !exists(fn) ) {
if( exists("settings.py") )
fn = "settings.py";
else {
cout << "no ../../settings.py or ./settings.py file found. will not write perf stats to pstats db." << endl;
cout << "it is recommended this be enabled even on dev boxes" << endl;
return;
}
}
try {
if( conn == 0 ) {
MemoryMappedFile f;
const char *p = (const char *) f.mapWithOptions(fn, MongoFile::READONLY);
string pwd;
{
const char *q = str::after(p, "pstatspassword=\"");
if( *q == 0 ) {
cout << "info perftests.cpp: no pstatspassword= in settings.py" << endl;
return;
}
else {
pwd = str::before(q, '\"');
}
}
boost::shared_ptr<DBClientConnection> c(new DBClientConnection(false, 0, 60));
string err;
if( c->connect("perfdb.10gen.cc", err) ) {
if( !c->auth("perf", "perf", pwd, err) ) {
cout << "info: authentication with stats db failed: " << err << endl;
assert(false);
}
conn = c;
// override the hostname with the buildbot hostname, if present
ifstream hostf( "../../info/host" );
if ( hostf.good() ) {
char buf[1024];
hostf.getline(buf, sizeof(buf));
_perfhostname = buf;
}
else {
_perfhostname = getHostName();
}
}
else {
cout << err << " (to log perfstats)" << endl;
}
}
}
catch(...) { }
}