1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-04 04:42:30 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@ -27,19 +27,19 @@
// the first time start() is called until finish() is called. You should always match your
// start and stop calls up.
//
// This works fine as long as you don't use it with huge numbers of calls. If you call start
// This works fine as long as you don't use it with huge numbers of calls. If you call start
// and stop too many times the overhead of the StopWatch class will start factoring in to your
// results.
//
// How to use:
//
//
// StopWatch timer;
// timer.start("Loop only");
// for(int i = 0; i < 6999075; i++)
// {
// }
// timer.stop("Loop only");
//
//
// timer.start("Loop Plus");
// for(int i = 0; i < 100000; i++)
// {
@ -50,14 +50,14 @@
// timer.finish();
//
// Produces this:
//
//
// Seconds Percentage Calls Description
// 0.02865 9.377% 1 Loop only
// 0.27680 90.59% 1 Loop Plus
// 0.12138 39.72% 100000 Inside loop
//
//
// 0.30553 100 % 1 Total
//
//
// Note that you can have overlapping timers which will make your percentages add up to more than 100%.
#include <iostream>
#include <fstream>
@ -78,143 +78,169 @@ namespace logging
void StopWatch::stop(const string& message)
{
stop(message, 1);
stop(message, 1);
}
bool StopWatch::stop(const string& message, const int limit) {
gettimeofday(&fTvLast, 0);
fOpenCalls--;
bool found = false;
uint32_t idx = 0;
for(uint32_t i = 0; i < fProcessStats.size(); i++) {
if(fProcessStats[i].fProcess == message) {
idx = i;
found = true;
break;
}
}
if(!found) {
//throw std::runtime_error("StopWatch::stop " + message + " called without calling start first.");
std::cerr << "StopWatch receiving STOP for unknown event: " << message << std::endl;
return false;
}
fProcessStats[idx].processStop();
if(fProcessStats[idx].fStopCount >= limit)
return true;
return false;
}
bool StopWatch::stop(const string& message, const int limit)
{
gettimeofday(&fTvLast, 0);
fOpenCalls--;
bool found = false;
uint32_t idx = 0;
void StopWatch::start(const string& message) {
fOpenCalls++;
gettimeofday(&fTvLast, 0);
bool found = false;
uint32_t idx = 0;
ProcessStats processStats;
if(!fStarted) {
fStarted = true;
gettimeofday(&fTvStart, 0);
}
for(uint32_t i = 0; i < fProcessStats.size(); i++) {
if(fProcessStats[i].fProcess == message) {
idx = i;
found = true;
break;
}
}
if(!found) {
fProcessStats.push_back(processStats);
idx = fProcessStats.size() - 1;
}
fProcessStats[idx].fProcess = message;
fProcessStats[idx].processStart();
}
void StopWatch::finish() {
ostringstream oss;
oss << endl;
oss << "Seconds Percentage Calls Description" << endl;
// total seconds elapsed
double totalSeconds = 1.0;
// Add a last entry into the vector for total.
ProcessStats total;
total.fProcess = "Total";
if (fProcessStats.size() > 0)
{
// Calculate the total seconds elapsed.
totalSeconds =
(fTvLast.tv_sec + (fTvLast.tv_usec / 1000000.0)) -
(fTvStart.tv_sec + (fTvStart.tv_usec / 1000000.0));
total.fTotalSeconds = totalSeconds;
total.fStartCount = 1;
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (fProcessStats[i].fProcess == message)
{
idx = i;
found = true;
break;
}
}
else
{
total.fTotalSeconds = 0.0;
total.fStartCount = 0;
}
fProcessStats.push_back(total);
for(uint32_t i = 0; i < fProcessStats.size(); i++) {
if (!found)
{
//throw std::runtime_error("StopWatch::stop " + message + " called without calling start first.");
std::cerr << "StopWatch receiving STOP for unknown event: " << message << std::endl;
return false;
}
if(i == (fProcessStats.size() - 1)) {
oss << endl;
}
fProcessStats[idx].processStop();
// Seconds.
string seconds;
ostringstream ossTemp;
ossTemp << fProcessStats[i].fTotalSeconds;
seconds = ossTemp.str();
seconds.resize(11, ' ');
oss << seconds << " ";
if (fProcessStats[idx].fStopCount >= limit)
return true;
// Percentage.
string percentage;
ossTemp.str(""); // clear the stream.
ossTemp << (fProcessStats[i].fTotalSeconds / totalSeconds) * 100.0;
percentage = ossTemp.str();
percentage.resize(11, ' ');
oss << percentage << "% ";
return false;
}
// Times Initiated.
ossTemp.str(""); // clear the stream.
ossTemp << fProcessStats[i].fStartCount;
string timesInitiated = ossTemp.str();
timesInitiated.resize(10, ' ');
oss << timesInitiated << " ";
// Description.
if(fId >= 0)
oss << fId << ": " << fProcessStats[i].fProcess << endl;
else
oss << fProcessStats[i].fProcess << endl;
}
if(fOutputToFile) {
void StopWatch::start(const string& message)
{
fOpenCalls++;
gettimeofday(&fTvLast, 0);
bool found = false;
uint32_t idx = 0;
ProcessStats processStats;
ofstream profLog;
profLog.open(fLogFile.c_str(), std::ios::app);
if (!fStarted)
{
fStarted = true;
gettimeofday(&fTvStart, 0);
}
// Output the date and time.
time_t t = time(0);
char timeString[50];
ctime_r(&t, timeString);
timeString[ strlen(timeString)-1 ] = '\0';
profLog << endl << timeString;
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (fProcessStats[i].fProcess == message)
{
idx = i;
found = true;
break;
}
}
// Output the stopwatch info.
profLog << oss.str();
}
else {
cout << oss.str();
}
if (!found)
{
fProcessStats.push_back(processStats);
idx = fProcessStats.size() - 1;
}
fProcessStats[idx].fProcess = message;
fProcessStats[idx].processStart();
}
void StopWatch::finish()
{
ostringstream oss;
oss << endl;
oss << "Seconds Percentage Calls Description" << endl;
// total seconds elapsed
double totalSeconds = 1.0;
// Add a last entry into the vector for total.
ProcessStats total;
total.fProcess = "Total";
if (fProcessStats.size() > 0)
{
// Calculate the total seconds elapsed.
totalSeconds =
(fTvLast.tv_sec + (fTvLast.tv_usec / 1000000.0)) -
(fTvStart.tv_sec + (fTvStart.tv_usec / 1000000.0));
total.fTotalSeconds = totalSeconds;
total.fStartCount = 1;
}
else
{
total.fTotalSeconds = 0.0;
total.fStartCount = 0;
}
fProcessStats.push_back(total);
for (uint32_t i = 0; i < fProcessStats.size(); i++)
{
if (i == (fProcessStats.size() - 1))
{
oss << endl;
}
// Seconds.
string seconds;
ostringstream ossTemp;
ossTemp << fProcessStats[i].fTotalSeconds;
seconds = ossTemp.str();
seconds.resize(11, ' ');
oss << seconds << " ";
// Percentage.
string percentage;
ossTemp.str(""); // clear the stream.
ossTemp << (fProcessStats[i].fTotalSeconds / totalSeconds) * 100.0;
percentage = ossTemp.str();
percentage.resize(11, ' ');
oss << percentage << "% ";
// Times Initiated.
ossTemp.str(""); // clear the stream.
ossTemp << fProcessStats[i].fStartCount;
string timesInitiated = ossTemp.str();
timesInitiated.resize(10, ' ');
oss << timesInitiated << " ";
// Description.
if (fId >= 0)
oss << fId << ": " << fProcessStats[i].fProcess << endl;
else
oss << fProcessStats[i].fProcess << endl;
}
if (fOutputToFile)
{
ofstream profLog;
profLog.open(fLogFile.c_str(), std::ios::app);
// Output the date and time.
time_t t = time(0);
char timeString[50];
ctime_r(&t, timeString);
timeString[ strlen(timeString) - 1 ] = '\0';
profLog << endl << timeString;
// Output the stopwatch info.
profLog << oss.str();
}
else
{
cout << oss.str();
}
// Clear everything out.
fStarted = false;
fProcessStats.clear();
// Clear everything out.
fStarted = false;
fProcessStats.clear();
}
} // end of logging namespace