From 910cdb3754c00589de745944bd4e3f6ae161c83a Mon Sep 17 00:00:00 2001 From: Stinkfist0 Date: Mon, 1 Oct 2018 13:19:31 +0300 Subject: [PATCH] IfcConvert: print durations of file parsing and XML conversion. --- src/ifcconvert/IfcConvert.cpp | 53 ++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index 4659875800..7847f139b8 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -116,6 +116,7 @@ bool rename_file(const std::string& old_filename, const std::string& new_filenam static std::stringstream log_stream; void write_log(bool); +std::string format_duration(time_t start, time_t end); /// @todo make the filters non-global IfcGeom::entity_filter entity_filter; // Entity filter is used always by default. @@ -473,11 +474,15 @@ int main(int argc, char** argv) int exit_code = EXIT_FAILURE; try { if (init_input_file(input_filename, ifc_file, no_progress || quiet, mmap)) { + time_t start, end; + time(&start); XmlSerializer s(output_temp_filename); s.setFile(&ifc_file); Logger::Status("Writing XML output..."); s.finalize(); - Logger::Status("Done!"); + time(&end); + Logger::Status("Done! Conversion took " + format_duration(start, end)); + rename_file(output_temp_filename, output_filename); exit_code = EXIT_SUCCESS; } @@ -760,28 +765,33 @@ int main(int argc, char** argv) time(&end); - if (!quiet) { - int seconds = (int)difftime(end, start); - std::stringstream msg; - int minutes = seconds / 60; - seconds = seconds % 60; - msg << "\nConversion took"; - if (minutes > 0) { - msg << " " << minutes << " minute"; - if (minutes > 1) { - msg << "s"; - } - } - msg << " " << seconds << " second"; - if (seconds > 1) { - msg << "s"; - } - Logger::Status(msg.str()); - } + if (!quiet) { + Logger::Status("\nConversion took " + format_duration(start, end)); + } return successful ? EXIT_SUCCESS : EXIT_FAILURE; } +std::string format_duration(time_t start, time_t end) +{ + int seconds = (int)difftime(end, start); + std::stringstream ss; + int minutes = seconds / 60; + seconds = seconds % 60; + if (minutes > 0) { + ss << minutes << " minute"; + if (minutes == 0 || minutes > 1) { + ss << "s"; + } + ss << " "; + } + ss << seconds << " second"; + if (seconds == 0 || seconds > 1) { + ss << "s"; + } + return ss.str(); +} + void write_log(bool header) { std::string log = log_stream.str(); if (!log.empty()) { @@ -794,9 +804,12 @@ void write_log(bool header) { bool init_input_file(const std::string &filename, IfcParse::IfcFile &ifc_file, bool no_progress, bool mmap) { + time_t start, end; + // Prevent IfcFile::Init() prints by setting output to null temporarily if (no_progress) { Logger::SetOutput(NULL, &log_stream); } + time(&start); #ifdef USE_MMAP if (!ifc_file.Init(filename, mmap)) { #else @@ -806,8 +819,10 @@ bool init_input_file(const std::string &filename, IfcParse::IfcFile &ifc_file, b Logger::Error("Unable to parse input file '" + filename + "'"); return false; } + time(&end); if (no_progress) { Logger::SetOutput(&std::cout, &log_stream); } + else { Logger::Status("Parsing input file took " + format_duration(start, end)); } return true; }