From 334da7f45262cb119aa9464261d0ecb47a6c5f90 Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Fri, 13 Apr 2018 18:45:31 +0200 Subject: [PATCH] Hadrons: can trace which module is throwing an error --- extras/Hadrons/HadronsXmlRun.cc | 12 +++++++++++- extras/Hadrons/VirtualMachine.cc | 13 +++++++++++-- extras/Hadrons/VirtualMachine.hpp | 9 +++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/extras/Hadrons/HadronsXmlRun.cc b/extras/Hadrons/HadronsXmlRun.cc index 4fcfabf2..26e56f7d 100644 --- a/extras/Hadrons/HadronsXmlRun.cc +++ b/extras/Hadrons/HadronsXmlRun.cc @@ -69,7 +69,17 @@ int main(int argc, char *argv[]) } catch (const std::exception& e) { - LOG(Error) << "FATAL ERROR -- Exception " << typeName(&typeid(e)) << std::endl; + auto &vm = VirtualMachine::getInstance(); + int mod = vm.getCurrentModule(); + + LOG(Error) << "FATAL ERROR -- Exception " << typeName(&typeid(e)) + << std::endl; + if (mod >= 0) + { + LOG(Error) << "During execution of module '" + << vm.getModuleName(mod) << "' (address " << mod << ")" + << std::endl; + } LOG(Error) << e.what() << std::endl; LOG(Error) << "Aborting program" << std::endl; Grid_finalize(); diff --git a/extras/Hadrons/VirtualMachine.cc b/extras/Hadrons/VirtualMachine.cc index 2b7f9620..a96df622 100644 --- a/extras/Hadrons/VirtualMachine.cc +++ b/extras/Hadrons/VirtualMachine.cc @@ -250,6 +250,11 @@ std::string VirtualMachine::getModuleNamespace(const std::string name) const return getModuleNamespace(getModuleAddress(name)); } +int VirtualMachine::getCurrentModule(void) const +{ + return currentModule_; +} + bool VirtualMachine::hasModule(const unsigned int address) const { return (address < module_.size()); @@ -468,7 +473,9 @@ void VirtualMachine::memoryProfile(const unsigned int address) << "' (" << address << ")..." << std::endl; try { + currentModule_ = address; m->setup(); + currentModule_ = -1; updateProfile(address); } catch (Exceptions::Definition &) @@ -622,7 +629,7 @@ VirtualMachine::Program VirtualMachine::schedule(const GeneticPar &par) #define SEP "---------------" #define MEM_MSG(size) sizeString(size) -void VirtualMachine::executeProgram(const Program &p) const +void VirtualMachine::executeProgram(const Program &p) { Size memPeak = 0, sizeBefore, sizeAfter; GarbageSchedule freeProg; @@ -650,7 +657,9 @@ void VirtualMachine::executeProgram(const Program &p) const LOG(Message) << SEP << " Measurement step " << i + 1 << "/" << p.size() << " (module '" << module_[p[i]].name << "') " << SEP << std::endl; + currentModule_ = p[i]; (*module_[p[i]].data)(); + currentModule_ = -1; sizeBefore = env().getTotalSize(); // print used memory after execution LOG(Message) << "Allocated objects: " << MEM_MSG(sizeBefore) @@ -679,7 +688,7 @@ void VirtualMachine::executeProgram(const Program &p) const } } -void VirtualMachine::executeProgram(const std::vector &p) const +void VirtualMachine::executeProgram(const std::vector &p) { Program pAddress; diff --git a/extras/Hadrons/VirtualMachine.hpp b/extras/Hadrons/VirtualMachine.hpp index 68eeb0c0..153f8d70 100644 --- a/extras/Hadrons/VirtualMachine.hpp +++ b/extras/Hadrons/VirtualMachine.hpp @@ -114,6 +114,7 @@ public: std::string getModuleType(const std::string name) const; std::string getModuleNamespace(const unsigned int address) const; std::string getModuleNamespace(const std::string name) const; + int getCurrentModule(void) const; bool hasModule(const unsigned int address) const; bool hasModule(const std::string name) const; // print VM content @@ -133,8 +134,8 @@ public: // genetic scheduler Program schedule(const GeneticPar &par); // general execution - void executeProgram(const Program &p) const; - void executeProgram(const std::vector &p) const; + void executeProgram(const Program &p); + void executeProgram(const std::vector &p); private: // environment shortcut DEFINE_ENV_ALIAS; @@ -154,13 +155,13 @@ private: // module and related maps std::vector module_; std::map moduleAddress_; - std::string currentModule_{""}; + int currentModule_{-1}; // module graph bool graphOutdated_{true}; Graph graph_; // memory profile bool memoryProfileOutdated_{true}; - MemoryProfile profile_; + MemoryProfile profile_; }; /******************************************************************************