You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-27 21:01:50 +03:00
Reformat all code to coding standard
This commit is contained in:
@ -50,118 +50,128 @@ namespace
|
||||
|
||||
void pause_(unsigned delay)
|
||||
{
|
||||
struct timespec req;
|
||||
struct timespec rem;
|
||||
struct timespec req;
|
||||
struct timespec rem;
|
||||
|
||||
req.tv_sec = delay;
|
||||
req.tv_nsec = 0;
|
||||
req.tv_sec = delay;
|
||||
req.tv_nsec = 0;
|
||||
|
||||
rem.tv_sec = 0;
|
||||
rem.tv_nsec = 0;
|
||||
rem.tv_sec = 0;
|
||||
rem.tv_nsec = 0;
|
||||
#ifdef _MSC_VER
|
||||
Sleep(req.tv_sec * 1000);
|
||||
Sleep(req.tv_sec * 1000);
|
||||
#else
|
||||
again:
|
||||
if (nanosleep(&req, &rem) != 0)
|
||||
if (rem.tv_sec > 0 || rem.tv_nsec > 0) {
|
||||
req = rem;
|
||||
goto again;
|
||||
}
|
||||
|
||||
if (nanosleep(&req, &rem) != 0)
|
||||
if (rem.tv_sec > 0 || rem.tv_nsec > 0)
|
||||
{
|
||||
req = rem;
|
||||
goto again;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
const string timestr()
|
||||
{
|
||||
// Get a timestamp for output.
|
||||
struct tm tm;
|
||||
struct timeval tv;
|
||||
// Get a timestamp for output.
|
||||
struct tm tm;
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, 0);
|
||||
localtime_r(reinterpret_cast<time_t*>(&tv.tv_sec), &tm);
|
||||
gettimeofday(&tv, 0);
|
||||
localtime_r(reinterpret_cast<time_t*>(&tv.tv_sec), &tm);
|
||||
|
||||
ostringstream oss;
|
||||
oss << setfill('0')
|
||||
<< setw(2) << tm.tm_hour << ':'
|
||||
<< setw(2) << tm.tm_min << ':'
|
||||
<< setw(2) << tm.tm_sec << '.'
|
||||
<< setw(4) << tv.tv_usec/100;
|
||||
ostringstream oss;
|
||||
oss << setfill('0')
|
||||
<< setw(2) << tm.tm_hour << ':'
|
||||
<< setw(2) << tm.tm_min << ':'
|
||||
<< setw(2) << tm.tm_sec << '.'
|
||||
<< setw(4) << tv.tv_usec / 100;
|
||||
|
||||
return oss.str();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
class TraceFile
|
||||
{
|
||||
public:
|
||||
TraceFile(uint32_t sessionID, const char* name)
|
||||
{
|
||||
if (sessionID > 0 )
|
||||
{
|
||||
const char* outName;
|
||||
if (name == 0)
|
||||
outName = "lbids";
|
||||
else
|
||||
outName = name;
|
||||
ostringstream oss;
|
||||
TraceFile(uint32_t sessionID, const char* name)
|
||||
{
|
||||
if (sessionID > 0 )
|
||||
{
|
||||
const char* outName;
|
||||
|
||||
if (name == 0)
|
||||
outName = "lbids";
|
||||
else
|
||||
outName = name;
|
||||
|
||||
ostringstream oss;
|
||||
#ifdef _MSC_VER
|
||||
oss << "C:/Calpont/log/trace/" << outName << '.' << sessionID;
|
||||
oss << "C:/Calpont/log/trace/" << outName << '.' << sessionID;
|
||||
#else
|
||||
oss << "/var/log/mariadb/columnstore/trace/" << outName << '.' << sessionID;
|
||||
oss << "/var/log/mariadb/columnstore/trace/" << outName << '.' << sessionID;
|
||||
#endif
|
||||
oFile.reset(new ofstream());
|
||||
oFile->open(oss.str().c_str(), ios_base::out | ios_base::ate | ios_base::app);
|
||||
}
|
||||
}
|
||||
oFile.reset(new ofstream());
|
||||
oFile->open(oss.str().c_str(), ios_base::out | ios_base::ate | ios_base::app);
|
||||
}
|
||||
}
|
||||
|
||||
~TraceFile()
|
||||
{
|
||||
}
|
||||
~TraceFile()
|
||||
{
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
if (oFile)
|
||||
{
|
||||
oFile->close();
|
||||
}
|
||||
}
|
||||
void close()
|
||||
{
|
||||
if (oFile)
|
||||
{
|
||||
oFile->close();
|
||||
}
|
||||
}
|
||||
|
||||
void log(OID_t oid, uint64_t lbid, pthread_t thdid, char event='\0')
|
||||
{
|
||||
*oFile << oid << ' ' << timestr() << ' ' << lbid
|
||||
<< ' ' << thdid;
|
||||
if (event != '\0')
|
||||
*oFile << ' ' << event;
|
||||
*oFile << endl;
|
||||
oFile->flush();
|
||||
}
|
||||
void log(OID_t oid, uint64_t lbid, pthread_t thdid, char event = '\0')
|
||||
{
|
||||
*oFile << oid << ' ' << timestr() << ' ' << lbid
|
||||
<< ' ' << thdid;
|
||||
|
||||
if (event != '\0')
|
||||
*oFile << ' ' << event;
|
||||
|
||||
*oFile << endl;
|
||||
oFile->flush();
|
||||
}
|
||||
|
||||
private:
|
||||
//Compiler defaults okay
|
||||
//TraceFile(const TraceFile& rhs);
|
||||
//TraceFile operator=(const TraceFile& rhs);
|
||||
boost::shared_ptr<ofstream> oFile;
|
||||
//Compiler defaults okay
|
||||
//TraceFile(const TraceFile& rhs);
|
||||
//TraceFile operator=(const TraceFile& rhs);
|
||||
boost::shared_ptr<ofstream> oFile;
|
||||
|
||||
};
|
||||
|
||||
struct TraceFileInfo
|
||||
{
|
||||
TraceFileInfo(uint32_t session=0, const char* name=0) : traceFile(session, name), lastTouched(0) { }
|
||||
~TraceFileInfo() { }
|
||||
TraceFileInfo(uint32_t session = 0, const char* name = 0) : traceFile(session, name), lastTouched(0) { }
|
||||
~TraceFileInfo() { }
|
||||
|
||||
void log(OID_t oid, uint64_t lbid, pthread_t thdid, char event='\0')
|
||||
{
|
||||
traceFile.log(oid, lbid, thdid, event);
|
||||
lastTouched = time(0);
|
||||
}
|
||||
void log(OID_t oid, uint64_t lbid, pthread_t thdid, char event = '\0')
|
||||
{
|
||||
traceFile.log(oid, lbid, thdid, event);
|
||||
lastTouched = time(0);
|
||||
}
|
||||
|
||||
void close() { traceFile.close(); }
|
||||
void close()
|
||||
{
|
||||
traceFile.close();
|
||||
}
|
||||
|
||||
TraceFile traceFile;
|
||||
time_t lastTouched;
|
||||
TraceFile traceFile;
|
||||
time_t lastTouched;
|
||||
|
||||
private:
|
||||
//Compiler defaults okay
|
||||
//TraceFileInfo(const TraceFileInfo& rhs);
|
||||
//TraceFileInfo operator=(const TraceFileInfo& rhs);
|
||||
//Compiler defaults okay
|
||||
//TraceFileInfo(const TraceFileInfo& rhs);
|
||||
//TraceFileInfo operator=(const TraceFileInfo& rhs);
|
||||
};
|
||||
|
||||
//map a session id to a trace file
|
||||
@ -174,49 +184,51 @@ mutex traceFileMapMutex;
|
||||
class StatMon
|
||||
{
|
||||
public:
|
||||
StatMon()
|
||||
{
|
||||
StatMon()
|
||||
{
|
||||
#ifndef _MSC_VER
|
||||
sigset_t sigset;
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGPIPE);
|
||||
sigaddset(&sigset, SIGUSR1);
|
||||
sigaddset(&sigset, SIGUSR2);
|
||||
pthread_sigmask(SIG_BLOCK, &sigset, 0);
|
||||
sigset_t sigset;
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGPIPE);
|
||||
sigaddset(&sigset, SIGUSR1);
|
||||
sigaddset(&sigset, SIGUSR2);
|
||||
pthread_sigmask(SIG_BLOCK, &sigset, 0);
|
||||
#endif
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
//struct timespec ts = { 60 * 1, 0 };
|
||||
mutex::scoped_lock lk(traceFileMapMutex);
|
||||
TraceFileMap_t::iterator iter;
|
||||
TraceFileMap_t::iterator end;
|
||||
for (;;)
|
||||
{
|
||||
lk.unlock();
|
||||
time_t beforeSleep = time(0);
|
||||
//nanosleep(&ts, 0);
|
||||
pause_(60);
|
||||
lk.lock();
|
||||
iter = traceFileMap.begin();
|
||||
end = traceFileMap.end();
|
||||
while (iter != end)
|
||||
{
|
||||
if (iter->second.lastTouched < beforeSleep)
|
||||
{
|
||||
//remove this session trace file
|
||||
iter->second.close();
|
||||
traceFileMap.erase(iter++);
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void operator()() const
|
||||
{
|
||||
//struct timespec ts = { 60 * 1, 0 };
|
||||
mutex::scoped_lock lk(traceFileMapMutex);
|
||||
TraceFileMap_t::iterator iter;
|
||||
TraceFileMap_t::iterator end;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
lk.unlock();
|
||||
time_t beforeSleep = time(0);
|
||||
//nanosleep(&ts, 0);
|
||||
pause_(60);
|
||||
lk.lock();
|
||||
iter = traceFileMap.begin();
|
||||
end = traceFileMap.end();
|
||||
|
||||
while (iter != end)
|
||||
{
|
||||
if (iter->second.lastTouched < beforeSleep)
|
||||
{
|
||||
//remove this session trace file
|
||||
iter->second.close();
|
||||
traceFileMap.erase(iter++);
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
//Compiler defaults okay
|
||||
//StatMon(const StatMon& rhs);
|
||||
//StatMon operator=(const StatMon& rhs);
|
||||
//Compiler defaults okay
|
||||
//StatMon(const StatMon& rhs);
|
||||
//StatMon operator=(const StatMon& rhs);
|
||||
};
|
||||
|
||||
}
|
||||
@ -225,52 +237,56 @@ namespace dbbc
|
||||
{
|
||||
|
||||
Stats::Stats() :
|
||||
fMonitorp(0)
|
||||
fMonitorp(0)
|
||||
{
|
||||
|
||||
fMonitorp = new boost::thread(StatMon());
|
||||
fMonitorp = new boost::thread(StatMon());
|
||||
}
|
||||
|
||||
Stats::Stats(const char *name) :
|
||||
fMonitorp(0), fName(name)
|
||||
Stats::Stats(const char* name) :
|
||||
fMonitorp(0), fName(name)
|
||||
{
|
||||
fMonitorp = new boost::thread(StatMon());
|
||||
//fName << name;
|
||||
fMonitorp = new boost::thread(StatMon());
|
||||
//fName << name;
|
||||
}
|
||||
|
||||
Stats::~Stats()
|
||||
{
|
||||
delete fMonitorp;
|
||||
delete fMonitorp;
|
||||
}
|
||||
|
||||
void Stats::touchedLBID(uint64_t lbid, pthread_t thdid, uint32_t session)
|
||||
{
|
||||
if (lbid < 0 || session == 0) return;
|
||||
if (lbid < 0 || session == 0) return;
|
||||
|
||||
mutex::scoped_lock lk(traceFileMapMutex);
|
||||
TraceFileMap_t::iterator iter = traceFileMap.find(session);
|
||||
if (iter == traceFileMap.end())
|
||||
{
|
||||
traceFileMap[session] = TraceFileInfo(session);
|
||||
iter = traceFileMap.find(session);
|
||||
idbassert(iter != traceFileMap.end());
|
||||
}
|
||||
iter->second.log(lbid2oid(lbid), lbid, thdid);
|
||||
mutex::scoped_lock lk(traceFileMapMutex);
|
||||
TraceFileMap_t::iterator iter = traceFileMap.find(session);
|
||||
|
||||
if (iter == traceFileMap.end())
|
||||
{
|
||||
traceFileMap[session] = TraceFileInfo(session);
|
||||
iter = traceFileMap.find(session);
|
||||
idbassert(iter != traceFileMap.end());
|
||||
}
|
||||
|
||||
iter->second.log(lbid2oid(lbid), lbid, thdid);
|
||||
}
|
||||
|
||||
void Stats::markEvent(const uint64_t lbid, const pthread_t thdid, const uint32_t session, const char event)
|
||||
{
|
||||
if (lbid < 0 || session == 0) return;
|
||||
if (lbid < 0 || session == 0) return;
|
||||
|
||||
mutex::scoped_lock lk(traceFileMapMutex);
|
||||
TraceFileMap_t::iterator iter = traceFileMap.find(session);
|
||||
if (iter == traceFileMap.end())
|
||||
{
|
||||
traceFileMap[session] = TraceFileInfo(session, fName);
|
||||
iter = traceFileMap.find(session);
|
||||
idbassert(iter != traceFileMap.end());
|
||||
}
|
||||
iter->second.log(lbid2oid(lbid), lbid, thdid, event);
|
||||
mutex::scoped_lock lk(traceFileMapMutex);
|
||||
TraceFileMap_t::iterator iter = traceFileMap.find(session);
|
||||
|
||||
if (iter == traceFileMap.end())
|
||||
{
|
||||
traceFileMap[session] = TraceFileInfo(session, fName);
|
||||
iter = traceFileMap.find(session);
|
||||
idbassert(iter != traceFileMap.end());
|
||||
}
|
||||
|
||||
iter->second.log(lbid2oid(lbid), lbid, thdid, event);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user