You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
Reformat all code to coding standard
This commit is contained in:
@ -53,17 +53,19 @@ using namespace std;
|
||||
return err; \
|
||||
} while (0)
|
||||
|
||||
namespace {
|
||||
|
||||
void log(logging::LOG_TYPE whichLogFile, const string &msg)
|
||||
namespace
|
||||
{
|
||||
logging::Logger logger(12); //12 = configcpp
|
||||
logger.logMessage(whichLogFile, msg, logging::LoggingID(12));
|
||||
|
||||
void log(logging::LOG_TYPE whichLogFile, const string& msg)
|
||||
{
|
||||
logging::Logger logger(12); //12 = configcpp
|
||||
logger.logMessage(whichLogFile, msg, logging::LoggingID(12));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace utils {
|
||||
namespace utils
|
||||
{
|
||||
|
||||
CGroupConfigurator::CGroupConfigurator()
|
||||
{
|
||||
@ -75,6 +77,7 @@ CGroupConfigurator::CGroupConfigurator()
|
||||
cGroupDefined = false;
|
||||
else
|
||||
cGroupDefined = true;
|
||||
|
||||
totalMemory = 0;
|
||||
totalSwap = 0;
|
||||
printedWarning = false;
|
||||
@ -96,24 +99,31 @@ uint32_t CGroupConfigurator::getNumCoresFromCGroup()
|
||||
|
||||
if (!in)
|
||||
RETURN_NO_GROUP(0);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Need to parse & count how many CPUs we have access to
|
||||
in >> cpusString;
|
||||
}
|
||||
catch (...) {
|
||||
catch (...)
|
||||
{
|
||||
RETURN_READ_ERROR(0);
|
||||
}
|
||||
|
||||
// the file has comma-deliminted CPU ranges like "0-7,9,11-12".
|
||||
size_t first = 0, last;
|
||||
bool lastRange = false;
|
||||
while (!lastRange) {
|
||||
|
||||
while (!lastRange)
|
||||
{
|
||||
size_t dash;
|
||||
string oneRange;
|
||||
|
||||
last = cpusString.find(',', first);
|
||||
if (last == string::npos) {
|
||||
|
||||
if (last == string::npos)
|
||||
{
|
||||
lastRange = true;
|
||||
oneRange = cpusString.substr(first);
|
||||
}
|
||||
@ -122,14 +132,17 @@ uint32_t CGroupConfigurator::getNumCoresFromCGroup()
|
||||
|
||||
if ((dash = oneRange.find('-')) == string::npos) // single-cpu range
|
||||
cpus++;
|
||||
else {
|
||||
const char *data = oneRange.c_str();
|
||||
else
|
||||
{
|
||||
const char* data = oneRange.c_str();
|
||||
uint32_t firstCPU = strtol(data, NULL, 10);
|
||||
uint32_t lastCPU = strtol(&data[dash+1], NULL, 10);
|
||||
uint32_t lastCPU = strtol(&data[dash + 1], NULL, 10);
|
||||
cpus += lastCPU - firstCPU + 1;
|
||||
}
|
||||
|
||||
first = last + 1;
|
||||
}
|
||||
|
||||
//cout << "found " << cpus << " CPUS in the string " << cpusString << endl;
|
||||
return cpus;
|
||||
}
|
||||
@ -137,13 +150,13 @@ uint32_t CGroupConfigurator::getNumCoresFromCGroup()
|
||||
uint32_t CGroupConfigurator::getNumCoresFromProc()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
SYSTEM_INFO siSysInfo;
|
||||
GetSystemInfo(&siSysInfo);
|
||||
return siSysInfo.dwNumberOfProcessors;
|
||||
SYSTEM_INFO siSysInfo;
|
||||
GetSystemInfo(&siSysInfo);
|
||||
return siSysInfo.dwNumberOfProcessors;
|
||||
#else
|
||||
uint32_t nc = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
return nc;
|
||||
return nc;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -160,11 +173,14 @@ uint32_t CGroupConfigurator::getNumCores()
|
||||
|
||||
if (!cGroupDefined)
|
||||
ret = getNumCoresFromProc();
|
||||
else {
|
||||
else
|
||||
{
|
||||
ret = getNumCoresFromCGroup();
|
||||
|
||||
if (ret == 0)
|
||||
ret = getNumCoresFromProc();
|
||||
}
|
||||
|
||||
//cout << "There are " << ret << " cores available" << endl;
|
||||
return ret;
|
||||
}
|
||||
@ -178,11 +194,14 @@ uint64_t CGroupConfigurator::getTotalMemory()
|
||||
|
||||
if (!cGroupDefined)
|
||||
ret = getTotalMemoryFromProc();
|
||||
else {
|
||||
else
|
||||
{
|
||||
ret = getTotalMemoryFromCGroup();
|
||||
|
||||
if (ret == 0)
|
||||
ret = getTotalMemoryFromProc();
|
||||
}
|
||||
|
||||
//cout << "Total mem available is " << ret << endl;
|
||||
totalMemory = ret;
|
||||
return totalMemory;
|
||||
@ -190,44 +209,46 @@ uint64_t CGroupConfigurator::getTotalMemory()
|
||||
|
||||
uint64_t CGroupConfigurator::getTotalMemoryFromProc()
|
||||
{
|
||||
size_t memTot;
|
||||
size_t memTot;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
MEMORYSTATUSEX memStat;
|
||||
memStat.dwLength = sizeof(memStat);
|
||||
if (GlobalMemoryStatusEx(&memStat) == 0)
|
||||
//FIXME: Assume 2GB?
|
||||
memTot = 2 * 1024 * 1024;
|
||||
else
|
||||
{
|
||||
MEMORYSTATUSEX memStat;
|
||||
memStat.dwLength = sizeof(memStat);
|
||||
|
||||
if (GlobalMemoryStatusEx(&memStat) == 0)
|
||||
//FIXME: Assume 2GB?
|
||||
memTot = 2 * 1024 * 1024;
|
||||
else
|
||||
{
|
||||
#ifndef _WIN64
|
||||
memStat.ullTotalPhys = std::min(memStat.ullTotalVirtual, memStat.ullTotalPhys);
|
||||
memStat.ullTotalPhys = std::min(memStat.ullTotalVirtual, memStat.ullTotalPhys);
|
||||
#endif
|
||||
//We now have the total phys mem in bytes
|
||||
memTot = memStat.ullTotalPhys / 1024;
|
||||
}
|
||||
//We now have the total phys mem in bytes
|
||||
memTot = memStat.ullTotalPhys / 1024;
|
||||
}
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
string cmd("sysctl -a | awk '/realmem/ {print int(($2+1023)/1024);}'");
|
||||
FILE* cmdPipe;
|
||||
char input[80];
|
||||
cmdPipe = popen(cmd.c_str(), "r");
|
||||
input[0] = '\0';
|
||||
fgets(input, 80, cmdPipe);
|
||||
input[79] = '\0';
|
||||
pclose(cmdPipe);
|
||||
memTot = atoi(input);
|
||||
string cmd("sysctl -a | awk '/realmem/ {print int(($2+1023)/1024);}'");
|
||||
FILE* cmdPipe;
|
||||
char input[80];
|
||||
cmdPipe = popen(cmd.c_str(), "r");
|
||||
input[0] = '\0';
|
||||
fgets(input, 80, cmdPipe);
|
||||
input[79] = '\0';
|
||||
pclose(cmdPipe);
|
||||
memTot = atoi(input);
|
||||
#else
|
||||
ifstream in("/proc/meminfo");
|
||||
string x;
|
||||
ifstream in("/proc/meminfo");
|
||||
string x;
|
||||
|
||||
in >> x;
|
||||
in >> memTot;
|
||||
in >> x;
|
||||
in >> memTot;
|
||||
#endif
|
||||
|
||||
//memTot is now in KB, convert to bytes
|
||||
memTot *= 1024;
|
||||
//memTot is now in KB, convert to bytes
|
||||
memTot *= 1024;
|
||||
|
||||
return memTot;
|
||||
return memTot;
|
||||
}
|
||||
|
||||
uint64_t CGroupConfigurator::getTotalMemoryFromCGroup()
|
||||
@ -241,15 +262,19 @@ uint64_t CGroupConfigurator::getTotalMemoryFromCGroup()
|
||||
filename = os.str();
|
||||
|
||||
in.open(filename.c_str());
|
||||
|
||||
if (!in)
|
||||
RETURN_NO_GROUP(0);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
in >> ret;
|
||||
}
|
||||
catch (...) {
|
||||
catch (...)
|
||||
{
|
||||
RETURN_READ_ERROR(0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -259,13 +284,16 @@ uint64_t CGroupConfigurator::getFreeMemory()
|
||||
|
||||
if (!cGroupDefined)
|
||||
ret = getFreeMemoryFromProc();
|
||||
else {
|
||||
else
|
||||
{
|
||||
uint64_t usage = getMemUsageFromCGroup();
|
||||
|
||||
if (usage == 0)
|
||||
ret = getFreeMemoryFromProc();
|
||||
else
|
||||
ret = getTotalMemory() - usage;
|
||||
}
|
||||
|
||||
//cout << "free memory = " << ret << endl;
|
||||
return ret;
|
||||
}
|
||||
@ -276,28 +304,34 @@ uint64_t CGroupConfigurator::getMemUsageFromCGroup()
|
||||
bool found = false;
|
||||
char oneline[80];
|
||||
|
||||
if (memUsageFilename.empty()) {
|
||||
if (memUsageFilename.empty())
|
||||
{
|
||||
ostringstream filename;
|
||||
filename << "/sys/fs/cgroup/memory/" << cGroupName << "/memory.stat";
|
||||
memUsageFilename = filename.str();
|
||||
}
|
||||
|
||||
ifstream in(memUsageFilename.c_str());
|
||||
string &filename = memUsageFilename;
|
||||
string& filename = memUsageFilename;
|
||||
|
||||
if (!in)
|
||||
RETURN_NO_GROUP(0);
|
||||
|
||||
try {
|
||||
while (in && !found) {
|
||||
try
|
||||
{
|
||||
while (in && !found)
|
||||
{
|
||||
in.getline(oneline, 80);
|
||||
|
||||
if (strncmp(oneline, "rss", 2) == 0) {
|
||||
if (strncmp(oneline, "rss", 2) == 0)
|
||||
{
|
||||
ret = atoll(&oneline[3]);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
catch (...)
|
||||
{
|
||||
RETURN_READ_ERROR(0);
|
||||
}
|
||||
|
||||
@ -306,59 +340,66 @@ uint64_t CGroupConfigurator::getMemUsageFromCGroup()
|
||||
|
||||
uint64_t CGroupConfigurator::getFreeMemoryFromProc()
|
||||
{
|
||||
uint64_t memFree = 0;
|
||||
uint64_t buffers = 0;
|
||||
uint64_t cached = 0;
|
||||
uint64_t memTotal = 0;
|
||||
uint64_t memAvailable = 0;
|
||||
uint64_t memFree = 0;
|
||||
uint64_t buffers = 0;
|
||||
uint64_t cached = 0;
|
||||
uint64_t memTotal = 0;
|
||||
uint64_t memAvailable = 0;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
MEMORYSTATUSEX memStat;
|
||||
memStat.dwLength = sizeof(memStat);
|
||||
if (GlobalMemoryStatusEx(&memStat))
|
||||
{
|
||||
memAvailable = memStat.ullAvailPhys;
|
||||
MEMORYSTATUSEX memStat;
|
||||
memStat.dwLength = sizeof(memStat);
|
||||
|
||||
if (GlobalMemoryStatusEx(&memStat))
|
||||
{
|
||||
memAvailable = memStat.ullAvailPhys;
|
||||
#ifndef _WIN64
|
||||
uint64_t tmp = getTotalMemoryFromProc();
|
||||
if (memFree > tmp)
|
||||
memAvailable = tmp;
|
||||
|
||||
if (memFree > tmp)
|
||||
memAvailable = tmp;
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
// FreeBSD is not supported, no optimization.
|
||||
memAvailable = 0;
|
||||
// FreeBSD is not supported, no optimization.
|
||||
memAvailable = 0;
|
||||
#else
|
||||
ifstream in("/proc/meminfo");
|
||||
string x;
|
||||
ifstream in("/proc/meminfo");
|
||||
string x;
|
||||
|
||||
in >> x; // MemTotal:
|
||||
in >> memTotal;
|
||||
in >> x; // kB
|
||||
in >> x; // MemTotal:
|
||||
in >> memTotal;
|
||||
in >> x; // kB
|
||||
|
||||
in >> x; // MemFree:
|
||||
in >> memFree;
|
||||
in >> x; // kB
|
||||
in >> x; // MemFree:
|
||||
in >> memFree;
|
||||
in >> x; // kB
|
||||
|
||||
//check if available or buffers is passed
|
||||
in >> x;
|
||||
if ( x == "MemAvailable:")
|
||||
{
|
||||
in >> memAvailable; // MemAvailable
|
||||
}
|
||||
else
|
||||
{ // centos 6 and older OSs
|
||||
in >> buffers;
|
||||
in >> x; // kB
|
||||
//check if available or buffers is passed
|
||||
in >> x;
|
||||
|
||||
if ( x == "MemAvailable:")
|
||||
{
|
||||
in >> memAvailable; // MemAvailable
|
||||
}
|
||||
else
|
||||
{
|
||||
// centos 6 and older OSs
|
||||
in >> buffers;
|
||||
in >> x; // kB
|
||||
|
||||
in >> x; // Cached:
|
||||
in >> cached;
|
||||
|
||||
memAvailable = memFree + buffers + cached;
|
||||
}
|
||||
|
||||
in >> x; // Cached:
|
||||
in >> cached;
|
||||
|
||||
memAvailable = memFree + buffers + cached;
|
||||
}
|
||||
#endif
|
||||
|
||||
// amount available for application
|
||||
memAvailable *= 1024;
|
||||
// amount available for application
|
||||
memAvailable *= 1024;
|
||||
return memAvailable;
|
||||
}
|
||||
|
||||
@ -371,14 +412,17 @@ uint64_t CGroupConfigurator::getTotalSwapSpace()
|
||||
|
||||
if (!cGroupDefined)
|
||||
ret = getTotalSwapFromSysinfo();
|
||||
else {
|
||||
else
|
||||
{
|
||||
ret = getTotalMemAndSwapFromCGroup();
|
||||
|
||||
// if no limit is set in the cgroup, the file contains maxint64. Use sysinfo in that case.
|
||||
if (ret == -1 || ret == numeric_limits<int64_t>::max())
|
||||
ret = getTotalSwapFromSysinfo();
|
||||
else
|
||||
ret -= getTotalMemory();
|
||||
}
|
||||
|
||||
//cout << "total swap=" << ret << endl;
|
||||
totalSwap = ret;
|
||||
return ret;
|
||||
@ -402,15 +446,19 @@ int64_t CGroupConfigurator::getTotalMemAndSwapFromCGroup()
|
||||
os << "/sys/fs/cgroup/memory/" << cGroupName << "/memory.memsw.limit_in_bytes";
|
||||
filename = os.str();
|
||||
in.open(filename.c_str());
|
||||
|
||||
if (!in)
|
||||
RETURN_NO_GROUP(-1);
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
in >> ret;
|
||||
}
|
||||
catch(...) {
|
||||
catch (...)
|
||||
{
|
||||
RETURN_READ_ERROR(-1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -420,11 +468,14 @@ uint64_t CGroupConfigurator::getSwapInUse()
|
||||
|
||||
if (!cGroupDefined)
|
||||
ret = getSwapInUseFromSysinfo();
|
||||
else {
|
||||
else
|
||||
{
|
||||
ret = getSwapInUseFromCGroup();
|
||||
|
||||
if (ret == -1)
|
||||
ret = getSwapInUseFromSysinfo();
|
||||
}
|
||||
|
||||
//cout << "current swap in use=" << ret << endl;
|
||||
return ret;
|
||||
}
|
||||
@ -436,29 +487,37 @@ int64_t CGroupConfigurator::getSwapInUseFromCGroup()
|
||||
bool found = false;
|
||||
char oneline[80];
|
||||
|
||||
if (usedSwapFilename.empty()) {
|
||||
if (usedSwapFilename.empty())
|
||||
{
|
||||
ostringstream os;
|
||||
os << "/sys/fs/cgroup/memory/" << cGroupName << "/memory.stat";
|
||||
usedSwapFilename = os.str();
|
||||
}
|
||||
string &filename = usedSwapFilename;
|
||||
|
||||
string& filename = usedSwapFilename;
|
||||
in.open(filename.c_str());
|
||||
|
||||
if (!in)
|
||||
RETURN_NO_GROUP(-1);
|
||||
|
||||
try {
|
||||
while (in && !found) {
|
||||
try
|
||||
{
|
||||
while (in && !found)
|
||||
{
|
||||
in.getline(oneline, 80);
|
||||
|
||||
if (strncmp(oneline, "swap", 4) == 0) {
|
||||
if (strncmp(oneline, "swap", 4) == 0)
|
||||
{
|
||||
ret = atoll(&oneline[5]);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(...) {
|
||||
catch (...)
|
||||
{
|
||||
RETURN_READ_ERROR(-1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user