Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
215 changes: 98 additions & 117 deletions etc/timer/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@
using namespace std;
namespace fs = filesystem;
#define DEBUG
#define IND (string)"\t"
#define IND (string) "\t"

#define functionDefinition "__FUNCTION_DEFINITION__ "
#define typeDefinition "__TYPE_DEFINITION__ "
#define timeElapsed "__TIME_ELAPSED__ "
#define parameterDefinition "__PARAMETER_DEFINITION__ "

void findFlagAndExtract (const string &line, vector<string> *out);
bool processLog(const string &filePathm, vector<string> *output);
void addLogToHtml(vector<string> *input, ofstream &htmlFile);
void addTimeDiv (ofstream &file, vector<string>::iterator it, int indent);
string getFlag (const string &line);
void findFlagAndExtract(const string &line, vector< string > *out);
bool processLog(const string &filePathm, vector< string > *output);
void addLogToHtml(vector< string > *input, ofstream &htmlFile);
void addTimeDiv(ofstream &file, vector< string >::iterator it, int indent);
string getFlag(const string &line);
string getValue(const string &line);
string getClass (const string &line);
string getInd (int n);
string getClass(const string &line);
string getInd(int n);

/*!
* \brief Main function
* \param argc Number of arguments
* \param argv Argument(s) value(s)
* \return Success / Failure
*/
int main (int argc, char *argv[]) {
int main(int argc, char *argv[]) {
// Parameters
string unitDirectory = "../FreeFem-sources/unit/";
string flagValOutputFile = "flagVal";
Expand All @@ -41,8 +41,7 @@ int main (int argc, char *argv[]) {
unitDirectory = argv[1];
flagValOutputFile = argv[2];
htmlOutputFile = argv[3];
}
else if (argc != 1) {
} else if (argc != 1) {
cout << "Correct use : ./parser.exe [unitdirectory] [flagvaloutputfile] [htmlfile]" << endl;
return EXIT_FAILURE;
}
Expand All @@ -52,35 +51,31 @@ int main (int argc, char *argv[]) {
ofstream htmlFile(htmlOutputFile);

// Retrieve and process all .log files
for(auto &logdir : fs::directory_iterator(unitDirectory)) {
if (!logdir.is_directory())
continue;
for (auto &logdir : fs::directory_iterator(unitDirectory)) {
if (!logdir.is_directory( )) continue;

for(auto &log : fs::directory_iterator(logdir.path())) {
if (log.path().extension() != ".log")
continue;
for (auto &log : fs::directory_iterator(logdir.path( ))) {
if (log.path( ).extension( ) != ".log") continue;

#ifdef DEBUG
cout << endl << log.path().filename().string() << endl;
#endif
#ifdef DEBUG
cout << endl << log.path( ).filename( ).string( ) << endl;
#endif

// find the flags and their associated values
vector<string> output;
if (!processLog(log.path().string(), &output))
return EXIT_FAILURE;
vector< string > output;
if (!processLog(log.path( ).string( ), &output)) return EXIT_FAILURE;

// add flags and their associated values to flagVal file
for (vector<string>::iterator it = output.begin(); it != output.end(); ++it)
flagValFile << *it << endl;
for (vector< string >::iterator it = output.begin( ); it != output.end( ); ++it) flagValFile << *it << endl;

// add formated flag and value to html file
addLogToHtml(&output, htmlFile);
}
}

flagValFile.close();
htmlFile.close();
return EXIT_SUCCESS;
flagValFile.close( );
htmlFile.close( );
return EXIT_SUCCESS;
}

/*!
Expand All @@ -89,15 +84,13 @@ int main (int argc, char *argv[]) {
* \param type Type
* \param out Out
*/
void findFlagAndExtract (const string &line, vector<string> *output) {
if (!line.length())
return;
size_t pos = line.find(functionDefinition);
void findFlagAndExtract(const string &line, vector< string > *output) {
if (!line.length( )) return;
size_t pos = line.find(functionDefinition);
if (pos == string::npos) pos = line.find(typeDefinition);
if (pos == string::npos) pos = line.find(timeElapsed);
if (pos == string::npos) pos = line.find(parameterDefinition);
if (line[0] == '_' && pos != string::npos)
output->push_back(line);
if (line[0] == '_' && pos != string::npos) output->push_back(line);
}

/*!
Expand All @@ -106,135 +99,123 @@ void findFlagAndExtract (const string &line, vector<string> *output) {
* \param output String vector containing flag anv their associated values
* \return Successfully processed or not
*/
bool processLog(const string &filePath, vector<string> *output) {
vector<string> fileContent;
ifstream file(filePath, ios::in); // open file, read only mode
if (file) {
string temp;
while (getline(file, temp)) // read all lines, keep ones containing flags
bool processLog(const string &filePath, vector< string > *output) {
vector< string > fileContent;
ifstream file(filePath, ios::in); // open file, read only mode
if (file) {
string temp;
while (getline(file, temp)) // read all lines, keep ones containing flags
findFlagAndExtract(temp, output);
} else { // return error
cerr << "Unable to open " << filePath << endl;
} else { // return error
cerr << "Unable to open " << filePath << endl;
return false;
}
file.close();
}
file.close( );

#ifdef DEBUG
cout << output->size() << (output->size() < 2 ? " flag" : " flags") << " found" << endl;
// Display vector content
for (vector<string>::iterator it = output->begin(); it != output->end(); ++it)
cout << *it << endl;
#endif
#ifdef DEBUG
cout << output->size( ) << (output->size( ) < 2 ? " flag" : " flags") << " found" << endl;
// Display vector content
for (vector< string >::iterator it = output->begin( ); it != output->end( ); ++it) cout << *it << endl;
#endif

return true;
}

/*!
* \brief Add formated log content to html file
* \param input Log formatted content
* \param htmlFile HTML output file
*/
void addLogToHtml(vector<string> *input, ofstream &htmlFile) {
if (!htmlFile || !input->size())
return;
* \brief Add formated log content to html file
* \param input Log formatted content
* \param htmlFile HTML output file
*/
void addLogToHtml(vector< string > *input, ofstream &htmlFile) {
if (!htmlFile || !input->size( )) return;

vector<string>::iterator it = input->begin();
vector< string >::iterator it = input->begin( );

if (input->size() == 1) {
if (input->size( ) == 1) {
htmlFile << "<div class=\"" << getClass(*it) << "\">" << endl;
htmlFile << getInd(1) << "<p>" << getValue(*it) << "</p>" << endl;
htmlFile << "</div>" << endl;
return;
}

while((it != input->end()) && (getFlag(*it) == functionDefinition)) {
while ((it != input->end( )) && (getFlag(*it) == functionDefinition)) {
htmlFile << "<div class=\"" << getClass(*it) << "\">" << endl;
htmlFile << getInd(1) << "<p>" << getValue(*it) << "</p>" << endl;
it++;

flagsleft: {
if ((getFlag(*it) != typeDefinition) && (getFlag(*it) != parameterDefinition))
goto timeonly;
flagsleft: {
if ((getFlag(*it) != typeDefinition) && (getFlag(*it) != parameterDefinition)) goto timeonly;

while ((it != input->end()) && ((getFlag(*it) == typeDefinition) || (getFlag(*it) == parameterDefinition))) {
htmlFile << getInd(1) << "<div class=\"" << getClass(*it) << "\">" << endl;
htmlFile << getInd(2) << "<p>" << getValue(*it) << "</p>" << endl;
while ((it != input->end( )) && ((getFlag(*it) == typeDefinition) || (getFlag(*it) == parameterDefinition))) {
htmlFile << getInd(1) << "<div class=\"" << getClass(*it) << "\">" << endl;
htmlFile << getInd(2) << "<p>" << getValue(*it) << "</p>" << endl;
it++;
while ((it < input->end( )) && (getFlag(*it) == timeElapsed)) {
addTimeDiv(htmlFile, it, 2);
it++;
while ((it < input->end()) && (getFlag(*it) == timeElapsed)) {
addTimeDiv(htmlFile, it, 2);
it++;
}
htmlFile << getInd(1) << "</div>" << endl;
}
htmlFile << getInd(1) << "</div>" << endl;
}

timeonly: while ((it != input->end()) && (getFlag(*it) == timeElapsed)) {
addTimeDiv(htmlFile, it, 1);
it++;
}
timeonly:
while ((it != input->end( )) && (getFlag(*it) == timeElapsed)) {
addTimeDiv(htmlFile, it, 1);
it++;
}
}

if ((it != input->end()) && (getFlag(*it) != functionDefinition))
goto flagsleft;
if ((it != input->end( )) && (getFlag(*it) != functionDefinition)) goto flagsleft;

htmlFile << "</div>" << endl;
}
}

/*!
* \brief Add div element containing time elapsed to html file
* \param it String iterator
* \param indent Div indentation
*/
void addTimeDiv (ofstream &htmlFile, vector<string>::iterator it, int indent) {
* \brief Add div element containing time elapsed to html file
* \param it String iterator
* \param indent Div indentation
*/
void addTimeDiv(ofstream &htmlFile, vector< string >::iterator it, int indent) {
htmlFile << getInd(indent) << "<div class=\"" << getClass(*it) << "\">" << endl;
htmlFile << getInd(indent + 1) << "<p>" << getValue(*it) << "</p>" << endl;
htmlFile << getInd(indent) <<"</div>" << endl;
htmlFile << getInd(indent) << "</div>" << endl;
}

/*!
* \brief Extract flag on a line
* \param line Line to process
* \return Flag on line
*/
string getFlag (const string &line) {
return line.substr(0, line.find(" ") + 1);
}
* \brief Extract flag on a line
* \param line Line to process
* \return Flag on line
*/
string getFlag(const string &line) { return line.substr(0, line.find(" ") + 1); }

/*!
* \brief Extract value after a flag
* \param line Line containing a flag
* \return Value on line
*/
string getValue (const string &line) {
return line.substr(line.find(" ") + 1);
}
* \brief Extract value after a flag
* \param line Line containing a flag
* \return Value on line
*/
string getValue(const string &line) { return line.substr(line.find(" ") + 1); }

/*!
* \brief Returns class for html format
* \param line Line containing the flag
* \return Html class
*/
string getClass (const string &line) {
* \brief Returns class for html format
* \param line Line containing the flag
* \return Html class
*/
string getClass(const string &line) {
string flag = getFlag(line);
if (flag == timeElapsed)
return "time";
if (flag == typeDefinition)
return "type";
if (flag == parameterDefinition)
return "parameter";
if (flag == functionDefinition)
return "function";
if (flag == timeElapsed) return "time";
if (flag == typeDefinition) return "type";
if (flag == parameterDefinition) return "parameter";
if (flag == functionDefinition) return "function";
return "";
}

/*!
* \brief Returns a specific number of indentations
* \param n Number of indentations
* \return Indentations
*/
string getInd (int n) {
* \brief Returns a specific number of indentations
* \param n Number of indentations
* \return Indentations
*/
string getInd(int n) {
string out = "";
for (int i = 0; i < n; i++)
out += IND;
for (int i = 0; i < n; i++) out += IND;
return out;
}
Loading
Loading