Skip to content
Snippets Groups Projects
Commit 78d84cb6 authored by Mohcine Chraibi's avatar Mohcine Chraibi
Browse files

add git logging to jpscore

parent 9fd03ad6
Branches
Tags
1 merge request!26Develop
...@@ -27,7 +27,7 @@ set(JPSCORE_PATCH_VERSION 3) ...@@ -27,7 +27,7 @@ set(JPSCORE_PATCH_VERSION 3)
set(JPSCORE_VERSION set(JPSCORE_VERSION
${JPSCORE_MAJOR_VERSION}.${JPSCORE_MINOR_VERSION}.${JPSCORE_PATCH_VERSION}) ${JPSCORE_MAJOR_VERSION}.${JPSCORE_MINOR_VERSION}.${JPSCORE_PATCH_VERSION})
message(STATUS "JPSCORE_VERSION: " ${JPSCORE_VERSION}) message(STATUS "JPSCORE_VERSION: " ${JPSCORE_VERSION})
add_definitions("-DJPSCORE_VERSION=\"${JPSCORE_VERSION}\"")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(warnings "-Wall -Wextra") set(warnings "-Wall -Wextra")
...@@ -113,6 +113,7 @@ message(STATUS " CMake generator: " ${CMAKE_GENERATOR}) ...@@ -113,6 +113,7 @@ message(STATUS " CMake generator: " ${CMAKE_GENERATOR})
message(STATUS " CMake build tool: " ${CMAKE_BUILD_TOOL}) message(STATUS " CMake build tool: " ${CMAKE_BUILD_TOOL})
if (MSVC) if (MSVC)
message(STATUS " MSVC: " ${MSVC_VERSION}) message(STATUS " MSVC: " ${MSVC_VERSION})
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ZLIB_WINAPI)
endif () endif ()
if (CMAKE_GENERATOR MATCHES Xcode) if (CMAKE_GENERATOR MATCHES Xcode)
message(STATUS " Xcode: " ${XCODE_VERSION}) message(STATUS " Xcode: " ${XCODE_VERSION})
...@@ -127,6 +128,52 @@ message(STATUS "") ...@@ -127,6 +128,52 @@ message(STATUS "")
# message( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} ) # message( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )
# message( STATUS "CMAKE_VERBOSE_MAKEFILE: " ${CMAKE_VERBOSE_MAKEFILE} ) # message( STATUS "CMAKE_VERBOSE_MAKEFILE: " ${CMAKE_VERBOSE_MAKEFILE} )
find_package(Git REQUIRED) # no need for this msg. It comes from cmake.findgit()
find_program(GIT_SCM git DOC "Git version control")
mark_as_advanced(GIT_SCM)
find_file(GITDIR NAMES .git PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
if (GIT_SCM AND GITDIR)
# the commit's SHA1, and whether the building workspace was dirty or not
# describe --match=NeVeRmAtCh --always --tags --abbrev=40 --dirty
execute_process(COMMAND
"${GIT_EXECUTABLE}" --no-pager describe --tags --always --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# branch
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# the date of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%ad --date=local
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# the subject of the commit
execute_process(COMMAND
"${GIT_EXECUTABLE}" log -1 --format=%s
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_SUBJECT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
add_definitions("-DGIT_COMMIT_HASH=\"${GIT_SHA1}\"")
add_definitions("-DGIT_COMMIT_DATE=\"${GIT_DATE}\"")
add_definitions("-DGIT_COMMIT_SUBJECT=\"${GIT_COMMIT_SUBJECT}\"")
add_definitions("-DGIT_BRANCH=\"${GIT_BRANCH}\"")
else()
message(STATUS "Not in a git repo")
endif()
# add a target to generate API documentation with Doxygen # add a target to generate API documentation with Doxygen
find_package(Doxygen) find_package(Doxygen)
if (DOXYGEN_FOUND) if (DOXYGEN_FOUND)
......
...@@ -45,6 +45,41 @@ ...@@ -45,6 +45,41 @@
#include "../routing/ai_router/AIRouter.h" #include "../routing/ai_router/AIRouter.h"
#include "../routing/ff_router/ffRouter.h" #include "../routing/ff_router/ffRouter.h"
/* https://stackoverflow.com/questions/38530981/output-compiler-version-in-a-c-program#38531037 */
std::string ver_string(int a, int b, int c) {
std::ostringstream ss;
ss << a << '.' << b << '.' << c;
return ss.str();
}
//https://sourceforge.net/p/predef/wiki/Compilers/
std::string true_cxx =
#ifdef __clang__
"clang++";
#elif defined(__GNU__)
"g++";
#elif defined(__MINGW32__)
"MinGW";
#elif defined(_MSC_VER)
"Visual Studio";
#else
"Compiler not identified";
#endif
std::string true_cxx_ver =
#ifdef __clang__
ver_string(__clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__GNU__)
ver_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif defined(__MINGW32__)
ver_string(__MINGW32__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
#elif defined( _MSC_VER)
ver_string(_MSC_VER, _MSC_FULL_VER,_MSC_BUILD);
#else
"";
#endif
IniFileParser::IniFileParser(Configuration* config) IniFileParser::IniFileParser(Configuration* config)
{ {
_config = config; _config = config;
...@@ -97,6 +132,25 @@ bool IniFileParser::Parse(std::string iniFile) ...@@ -97,6 +132,25 @@ bool IniFileParser::Parse(std::string iniFile)
Log->Write("ERROR:\t Wrong header version. Only version greater than %s is supported.", JPS_OLD_VERSION); Log->Write("ERROR:\t Wrong header version. Only version greater than %s is supported.", JPS_OLD_VERSION);
return false; return false;
} }
//logfile
if (xMainNode->FirstChild("logfile")) {
_config->SetErrorLogFile(
_config->GetProjectRootDir()+xMainNode->FirstChild("logfile")->FirstChild()->Value());
_config->SetLog(2);
Log->Write("INFO:\tlogfile <%s>", _config->GetErrorLogFile().c_str());
}
Log->Write("----\nJuPedSim - JPScore\n");
Log->Write("Current date : %s %s", __DATE__, __TIME__);
Log->Write("Version : %s", JPSCORE_VERSION);
Log->Write("Compiler : %s (%s)", true_cxx.c_str(), true_cxx_ver.c_str());
Log->Write("Commit hash : %s", GIT_COMMIT_HASH);
Log->Write("Commit date : %s", GIT_COMMIT_DATE);
Log->Write("Branch : %s\n----\n", GIT_BRANCH);
//seed //seed
if (xMainNode->FirstChild("seed")) { if (xMainNode->FirstChild("seed")) {
TiXmlNode* seedNode = xMainNode->FirstChild("seed")->FirstChild(); TiXmlNode* seedNode = xMainNode->FirstChild("seed")->FirstChild();
...@@ -149,13 +203,6 @@ bool IniFileParser::Parse(std::string iniFile) ...@@ -149,13 +203,6 @@ bool IniFileParser::Parse(std::string iniFile)
_config->SetMaxOpenMPThreads(omp_get_max_threads()); _config->SetMaxOpenMPThreads(omp_get_max_threads());
Log->Write("INFO:\tUsing num_threads <%d> threads (%d available)", _config->GetMaxOpenMPThreads(), max_threads); Log->Write("INFO:\tUsing num_threads <%d> threads (%d available)", _config->GetMaxOpenMPThreads(), max_threads);
//logfile
if (xMainNode->FirstChild("logfile")) {
_config->SetErrorLogFile(
_config->GetProjectRootDir()+xMainNode->FirstChild("logfile")->FirstChild()->Value());
_config->SetLog(2);
Log->Write("INFO:\tlogfile <%s>", _config->GetErrorLogFile().c_str());
}
//display statistics //display statistics
if (xMainNode->FirstChild("show_statistics")) { if (xMainNode->FirstChild("show_statistics")) {
std::string value = xMainNode->FirstChild("show_statistics")->FirstChild()->Value(); std::string value = xMainNode->FirstChild("show_statistics")->FirstChild()->Value();
......
...@@ -95,7 +95,7 @@ bool Simulation::InitArgs() ...@@ -95,7 +95,7 @@ bool Simulation::InitArgs()
} }
case 2: { case 2: {
char name[CLENGTH] = ""; char name[CLENGTH] = "";
sprintf(name, "%s.P0.dat", _config->GetErrorLogFile().c_str()); sprintf(name, "%s.txt", _config->GetErrorLogFile().c_str());
if (Log) if (Log)
delete Log; delete Log;
Log = new FileHandler(name); Log = new FileHandler(name);
...@@ -346,7 +346,7 @@ void Simulation::UpdateRoutesAndLocations() ...@@ -346,7 +346,7 @@ void Simulation::UpdateRoutesAndLocations()
//exit(EXIT_FAILURE); //exit(EXIT_FAILURE);
#pragma omp critical(Simulation_Update_pedsToRemove) #pragma omp critical(Simulation_Update_pedsToRemove)
{ {
pedsToRemove.push_back(ped); pedsToRemove.insert(ped);
Log->incrementDeletedAgents(); Log->incrementDeletedAgents();
} }
} }
......
...@@ -49,14 +49,15 @@ ...@@ -49,14 +49,15 @@
using namespace std; using namespace std;
void ArgumentParser::Usage(const std::string file) void ArgumentParser::Usage(const std::string file)
{ {
fprintf(stderr, "\n\nYou are actually using JuPedsim version %s \n\n", JPS_VERSION);
fprintf(stderr, "Usages: \n"); fprintf(stderr, "Usages: \n");
fprintf(stderr, " %s <path to file> start the simulation with the specified file.\n", file.c_str()); fprintf(stderr, " %s <path to file> start the simulation with the specified file.\n", file.c_str());
fprintf(stderr, " %s search and use the file ini.xml in the current directory.\n", fprintf(stderr, " %s search and use the file ini.xml in the current directory.\n",
file.c_str()); file.c_str());
fprintf(stderr, " %s -v/--version display the current version.\n", file.c_str());
fprintf(stderr, " %s -h/--help display this text.\n", file.c_str()); fprintf(stderr, " %s -h/--help display this text.\n", file.c_str());
#ifdef _JPS_AS_A_SERVICE #ifdef _JPS_AS_A_SERVICE
fprintf(stderr, " %s --as-a-service -p <port nr> runs jps as a service at port <port nr>.\n", file.c_str()); fprintf(stderr, " %s --as-a-service -p <port nr> runs jps as a service at port <port nr>.\n", file.c_str());
...@@ -77,6 +78,15 @@ bool ArgumentParser::ParseArgs(int argc, char** argv) ...@@ -77,6 +78,15 @@ bool ArgumentParser::ParseArgs(int argc, char** argv)
if (argc==1) { if (argc==1) {
Log->Write( Log->Write(
"INFO: \tTrying to load the default configuration from the file <ini.xml>"); "INFO: \tTrying to load the default configuration from the file <ini.xml>");
// first logs will go to stdout
Log->Write("----\nJuPedSim - JPScore\n");
Log->Write("Current date : %s %s", __DATE__, __TIME__);
Log->Write("Version : %s", JPSCORE_VERSION);
// Log->Write("Compiler : %s (%s)", true_cxx.c_str(), true_cxx_ver.c_str());
Log->Write("Commit hash : %s", GIT_COMMIT_HASH);
Log->Write("Commit date : %s", GIT_COMMIT_DATE);
Log->Write("Branch : %s\n----\n", GIT_BRANCH);
IniFileParser* p = new IniFileParser(_config); IniFileParser* p = new IniFileParser(_config);
if (!p->Parse("ini.xml")) { if (!p->Parse("ini.xml")) {
Usage(argv[0]); Usage(argv[0]);
...@@ -90,10 +100,6 @@ bool ArgumentParser::ParseArgs(int argc, char** argv) ...@@ -90,10 +100,6 @@ bool ArgumentParser::ParseArgs(int argc, char** argv)
Usage(argv[0]); Usage(argv[0]);
return false; return false;
} }
else if (argument=="-v" || argument=="--version") {
fprintf(stderr, "You are actually using JuPedsim/jpscore version %s \n\n", JPS_VERSION);
return false;
}
// other special case where a single configuration file is submitted // other special case where a single configuration file is submitted
//check if inifile options are given //check if inifile options are given
...@@ -161,4 +167,3 @@ bool ArgumentParser::ParseArgs(int argc, char** argv) ...@@ -161,4 +167,3 @@ bool ArgumentParser::ParseArgs(int argc, char** argv)
Usage(argv[0]); Usage(argv[0]);
return false; return false;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment