📄 preprocessor.cpp
字号:
#include "Preprocessor.h"
void Preprocessor::initializeRecordList(const char* fileName) throw (AppException) {
string sRecId;
string sSize;
string sFormat;
string sEventType;
string sFacility;
string sSeverity;
string sEventTime;
string sFlags;
string sThread;
string sJobId;
string sProcessor;
string sNode;
string sBlock;
string sEntryData;
string sLocation;
int count = 0;
try {
ifstream inFile(fileName, ios::in);
if (inFile.is_open()) {
cout << "opened file" << endl;
ptime epochTime(date(1970, 1, 1));
while (!inFile.eof()) {
if (inFile >> sRecId) {
string line;
getline(inFile, line);
if ( (line.length() < 50) || (! all(sRecId, is_digit())) ) {
//cout << sRecId << line << endl;
//cout << "LineNumber: " << count << endl;
continue;
}
//cout << sRecId << line << endl;
sEventType = line.substr(23, 10);
sFacility = line.substr(34, 10);
sSeverity = line.substr(45, 10);
sEventTime = line.substr(56, 20);
sFlags = line.substr(83, 10);
sThread = line.substr(94, 10);
sJobId = line.substr(105, 11);
sProcessor = line.substr(117, 11);
sNode = line.substr(129, 11);
sBlock = line.substr(141, 16);
sEntryData = line.substr(158, 1000);
if (line.length() > 1159) {
sLocation = line.substr(1159, 64);
}
trim(sEventType);
trim(sFacility);
trim(sSeverity);
trim(sEventTime);
trim(sFlags);
trim(sThread);
trim(sJobId);
trim(sProcessor);
trim(sNode);
trim(sBlock);
trim(sEntryData);
trim(sLocation);
//cout << "id: " << sRecId << "; eventTime: " << sEventTime << "; EventType: " << sEventType << "; Severity: " << sSeverity << endl;
//char ch; cin.get(ch);
if ( (sEventType == "RAS") &&
( (sSeverity == "FATAL") || (sSeverity == "FAILURE") ) ) {
int year = lexical_cast<int>(sEventTime.substr(0, 4));
int month = lexical_cast<int>(sEventTime.substr(5, 2));
int day = lexical_cast<int>(sEventTime.substr(8, 2));
int hr = lexical_cast<int>(sEventTime.substr(11, 2));
int mi = lexical_cast<int>(sEventTime.substr(14, 2));
int ss = lexical_cast<int>(sEventTime.substr(17, 2));
date dt(year, month, day);
time_duration td(hr, mi, ss);
ptime currTime(dt, td);
time_duration diff = currTime - epochTime;
//cout << "Diff: " << diff.total_seconds() << endl;
Record* record = new Record(sRecId, sEventType, sFacility,
sSeverity, diff.total_seconds(),
sEntryData, sLocation, sJobId);
//cout << "created record object" << endl;
fatalList->push_back(*record);
//cout << "added record object to recordList" << endl;
//cout << *record << endl;
//char ch; cin.get(ch);
++count;
delete record;
} /*else if ( (sEventType == "RAS") &&
( (sSeverity != "FATAL") && (sSeverity != "FAILURE") ) ) {
int year = lexical_cast<int>(sEventTime.substr(0, 4));
int month = lexical_cast<int>(sEventTime.substr(5, 2));
int day = lexical_cast<int>(sEventTime.substr(8, 2));
int hr = lexical_cast<int>(sEventTime.substr(11, 2));
int mi = lexical_cast<int>(sEventTime.substr(14, 2));
int ss = lexical_cast<int>(sEventTime.substr(17, 2));
date dt(year, month, day);
time_duration td(hr, mi, ss);
ptime currTime(dt, td);
time_duration diff = currTime - epochTime;
//cout << "Diff: " << diff.total_seconds() << endl;
Record* record = new Record(sRecId, sEventType, sFacility,
sSeverity, diff.total_seconds(),
sEntryData, sLocation, sJobId);
//cout << "created record object" << endl;
nonFatalList->push_back(*record);
//cout << "added record object to recordList" << endl;
//cout << *record << endl;
//char ch; cin.get(ch);
++count;
delete record;
}*/
}
}
inFile.close();
} else {
throw AppException(9, "unable to open Input file", __FILE__, __LINE__);
}
sort(fatalList->begin(), fatalList->end());
//fatalList->printItems();
cout << "Total Failure/Fatal RAS Records: " << count << endl;
} catch (bad_lexical_cast &e) {
throw AppException(9, string("lexical casting error - ") + string(e.what()), __FILE__, __LINE__);
} catch (exception &e) {
throw AppException(9, string("abnormal error in processing Input file - ") + string(e.what()), __FILE__, __LINE__);
}
};
void Preprocessor::init() {
//const char* dataFileName = "..\\rawData\\TBGLEVENTLOG.dat";
//const char* dataFileName = "..\\rawData\\tempFile2.dat";
const char* dataFileName = "..\\rawData\\rasdbdump.dat";
fatalList = new vector<Record>;
nonFatalList = new vector<Record>;
this->initializeRecordList(dataFileName);
}
Preprocessor::Preprocessor() {
init();
};
Preprocessor::~Preprocessor() {
delete fatalList;
delete nonFatalList;
};
vector<Record>* Preprocessor::getFatalList() const {
return fatalList;
};
vector<Record>* Preprocessor::getNonFatalList() const {
return nonFatalList;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -