#include "FairRunInfo.h" #include "FairLogger.h" #include "TSystem.h" #include "TList.h" #include "TH1.h" #include "TDirectory.h" #include #include #include #include using std::cout; using std::endl; using std::list; ClassImp(FairRunInfo) //_____________________________________________________________________________ FairRunInfo::FairRunInfo() :TObject(), fTimeStamp(), fCpuInfo(), fMemInfo(), fProcInfo(), fTimeDiff(), fResidentMemory(), fVirtualMemory(), fLogger(FairLogger::GetLogger()) { } FairRunInfo::~FairRunInfo() { } void FairRunInfo::StoreInfo() { // Extract the Information about the used memory from the system. // Stores this info together with the timedifference between now // and the last call in container arrays for later usage. // gSystem->GetCpuInfo(&cpuInfo, 10); // gSystem->GetMemInfo(&memInfo); GetInfo(); CalculateTimeDifference(); PrintInfo(); } void FairRunInfo::GetInfo() { // Set the TimeStamp to the actual time and store it fTimeStamp.Set(); // fTime.push_back(fTimeStamp.GetSec()); fTime.push_back(fTimeStamp.AsDouble()); gSystem->GetProcInfo(&fProcInfo); fResidentMemory.push_back(fProcInfo.fMemResident/1024); fVirtualMemory.push_back(fProcInfo.fMemVirtual/1024); } void FairRunInfo::CalculateTimeDifference() { // Calculates the time difference between now and the last call Int_t lastElement = fTime.size()-1; fTimeDiff.push_back( fTime.at(lastElement) - fTime.at(lastElement-1) ); } void FairRunInfo::PrintInfo() { fLogger->Info(MESSAGE_ORIGIN,"Time to execute 1 event: %f s", fTimeDiff.back()); fLogger->Info(MESSAGE_ORIGIN,"Used resident memory: %i MB", fResidentMemory.back()); fLogger->Info(MESSAGE_ORIGIN,"Used virtual memory: %i MB", fVirtualMemory.back()); } void FairRunInfo::WriteInfo() { TList* histoList = new TList(); CreateAndFillHistograms(histoList); // CreateAndFillHistograms(histoList); WriteHistosToFile(histoList); } void FairRunInfo::CreateAndFillHistograms(TList* histoList) { Int_t entries = fTime.size(); Int_t timePeriod = fTime.back()-fTime.front(); TH1F* ResidentMemoryVsEvent = new TH1F("ResidentMemoryVsEvent","Resident Memory as function of Eventnumber;Event;Memory [MB]",entries, 0, entries); TH1F* VirtualMemoryVsEvent = new TH1F("VirtualMemoryVsEvent","Virtual Memory as function of Eventnumber;Event;Memory [MB]",entries, 0, entries); TH1F* ResidentMemoryVsTime = new TH1F("ResidentMemoryVsTime","Resident memory as function of Runtime;Time [s];Memory [MB]",timePeriod*10, 0, timePeriod); TH1F* VirtualMemoryVsTime = new TH1F("VirtualMemoryVsTime","Virtual memory as function of Runtime;Time [s];Memory [MB]",timePeriod*10, 0, timePeriod); TH1F* EventtimeVsEvent = new TH1F("EventtimeVsEvent","Runtime per Event as function of Event number;Event;Time [s]",entries-1, 1, entries); std::vector timeDiffSorted(fTimeDiff); std::vector::iterator it; std::sort(timeDiffSorted.begin(), timeDiffSorted.end()); Int_t minTime = timeDiffSorted.front(); Int_t maxTime = timeDiffSorted.back(); timePeriod = maxTime - minTime; TH1F* TimePerEvent = new TH1F("TimePerEvent","Runtime;Time [s];Events",(timePeriod+20)*10, minTime-10, maxTime+10); Int_t counter = 0; std::vector::iterator lit; Double_t timeOffset = fTime.front()+1.; for(lit=fResidentMemory.begin(); litFill(counter, *lit); ResidentMemoryVsTime->Fill(fTime.at(counter)-timeOffset, *lit); counter++; } histoList->AddLast(ResidentMemoryVsEvent); histoList->AddLast(ResidentMemoryVsTime); counter = 0; for(lit=fVirtualMemory.begin(); litFill(counter, *lit); VirtualMemoryVsTime->Fill(fTime.at(counter)-timeOffset, *lit); counter++; } histoList->AddLast(VirtualMemoryVsEvent); histoList->AddLast(VirtualMemoryVsTime); counter = 1; for(it=fTimeDiff.begin(); itFill(*it); EventtimeVsEvent->Fill(counter, *it); counter++; } histoList->AddLast(TimePerEvent); histoList->AddLast(EventtimeVsEvent); } void FairRunInfo::WriteHistosToFile(TList* histoList) { // create a new subdirectory in the output file and // write all histograms TDirectory* currentDir = gDirectory; std::cout << "FairRunInfo:currentDir = \"" << currentDir->GetName() << "\"" << std::endl; // gDirectory->SetWritable(kTRUE); std::cout << "apparently current dir is " << gDirectory->GetPath() << " :/: " << gDirectory->GetName() << " and is" << (gDirectory->IsWritable()?"":" NOT") << " WRITABLE" << endl; gDirectory->cd(); gDirectory->mkdir("FairRunInfo"); gDirectory->cd("FairRunInfo"); std::cout << "apparently created dir, is it? " << gDirectory->GetPath() << " :/: " << gDirectory->GetName() << " and is" << (gDirectory->IsWritable()?"":" NOT") << " WRITABLE" << endl; TIterator* listIter=histoList->MakeIterator(); listIter->Reset(); TObject* obj = NULL; while((obj=listIter->Next())) { obj->Write(); } gDirectory=currentDir; std::cout << "FairRunInfo:currentDir = \"" << currentDir->GetName() << "\"" << std::endl; } void FairRunInfo::Reset() { GetInfo(); }