Skip to content
Snippets Groups Projects
Commit 1f49dfe4 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

-cpu command line option to report CPU/memory for all messages (same as in getdp)

parent 1f308839
Branches
Tags
No related merge requests found
...@@ -149,6 +149,7 @@ std::vector<std::pair<std::string, std::string> > GetUsage() ...@@ -149,6 +149,7 @@ std::vector<std::pair<std::string, std::string> > GetUsage()
s.push_back(mp("-setstring name value", "Set constant string name=value")); s.push_back(mp("-setstring name value", "Set constant string name=value"));
s.push_back(mp("-option file", "Parse option file at startup")); s.push_back(mp("-option file", "Parse option file at startup"));
s.push_back(mp("-convert files", "Convert files into latest binary formats, then exit")); s.push_back(mp("-convert files", "Convert files into latest binary formats, then exit"));
s.push_back(mp("-cpu", "Report CPU times for all operations"));
s.push_back(mp("-version", "Show version number")); s.push_back(mp("-version", "Show version number"));
s.push_back(mp("-info", "Show detailed version information")); s.push_back(mp("-info", "Show detailed version information"));
s.push_back(mp("-help", "Show command line usage")); s.push_back(mp("-help", "Show command line usage"));
...@@ -364,6 +365,10 @@ void GetOptions(int argc, char *argv[]) ...@@ -364,6 +365,10 @@ void GetOptions(int argc, char *argv[])
CTX::instance()->batch = 4; CTX::instance()->batch = 4;
i++; i++;
} }
else if(!strcmp(argv[i] + 1, "cpu")) {
Msg::SetInfoCpu(true);
i++;
}
else if(!strcmp(argv[i] + 1, "refine")) { else if(!strcmp(argv[i] + 1, "refine")) {
CTX::instance()->batch = 5; CTX::instance()->batch = 5;
i++; i++;
......
...@@ -51,6 +51,8 @@ int Msg::_verbosity = 5; ...@@ -51,6 +51,8 @@ int Msg::_verbosity = 5;
int Msg::_progressMeterStep = 20; int Msg::_progressMeterStep = 20;
int Msg::_progressMeterCurrent = 0; int Msg::_progressMeterCurrent = 0;
std::map<std::string, double> Msg::_timers; std::map<std::string, double> Msg::_timers;
bool Msg::_infoCpu = false;
double Msg::_startTime = 0.;
int Msg::_warningCount = 0; int Msg::_warningCount = 0;
int Msg::_errorCount = 0; int Msg::_errorCount = 0;
int Msg::_atLeastOneErrorInRun = 0; int Msg::_atLeastOneErrorInRun = 0;
...@@ -106,6 +108,7 @@ static void addGmshPathToEnvironmentVar(const std::string &name) ...@@ -106,6 +108,7 @@ static void addGmshPathToEnvironmentVar(const std::string &name)
void Msg::Init(int argc, char **argv) void Msg::Init(int argc, char **argv)
{ {
_startTime = TimeOfDay();
#if defined(HAVE_MPI) #if defined(HAVE_MPI)
int flag; int flag;
MPI_Initialized(&flag); MPI_Initialized(&flag);
...@@ -252,6 +255,52 @@ static int streamIsVT100(FILE* stream) ...@@ -252,6 +255,52 @@ static int streamIsVT100(FILE* stream)
return 1; return 1;
} }
std::string Msg::PrintResources(bool printDate, bool printWallTime,
bool printCpu, bool printMem)
{
long mem = GetMemoryUsage();
std::string pdate = "";
if(printDate){
time_t now;
time(&now);
pdate = ctime(&now);
pdate.resize(pdate.size() - 1);
if(printWallTime || printCpu || (printMem && mem))
pdate += ", ";
}
std::string pwall = "";
if(printWallTime){
char tmp[128];
sprintf(tmp, "Wall = %gs", TimeOfDay() - _startTime);
pwall = tmp;
if(printCpu || (printMem && mem))
pwall += ", ";
}
std::string pcpu = "";
if(printCpu){
char tmp[128];
sprintf(tmp, "CPU = %gs", Cpu());
pcpu = tmp;
if(printMem && mem)
pcpu += ", ";
}
std::string pmem = "";
if(mem && printMem){
char tmp[128];
sprintf(tmp, "Mem = %gMb", (double)mem / 1024. / 1024.);
pmem = tmp;
}
std::string str;
if(pdate.size() || pwall.size() || pcpu.size() || pmem.size())
str += " (" + pdate + pwall + pcpu + pmem + ")";
return str;
}
void Msg::Fatal(const char *fmt, ...) void Msg::Fatal(const char *fmt, ...)
{ {
_errorCount++; _errorCount++;
...@@ -388,6 +437,11 @@ void Msg::Info(const char *fmt, ...) ...@@ -388,6 +437,11 @@ void Msg::Info(const char *fmt, ...)
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_infoCpu){
std::string res = PrintResources(false, true, true, true);
strcat(str, res.c_str());
}
if(_callback) (*_callback)("Info", str); if(_callback) (*_callback)("Info", str);
if(_client) _client->Info(str); if(_client) _client->Info(str);
...@@ -468,6 +522,11 @@ void Msg::StatusBar(bool log, const char *fmt, ...) ...@@ -468,6 +522,11 @@ void Msg::StatusBar(bool log, const char *fmt, ...)
vsnprintf(str, sizeof(str), fmt, args); vsnprintf(str, sizeof(str), fmt, args);
va_end(args); va_end(args);
if(_infoCpu){
std::string res = PrintResources(false, true, true, true);
strcat(str, res.c_str());
}
if(_callback && log) (*_callback)("Info", str); if(_callback && log) (*_callback)("Info", str);
if(_client && log) _client->Info(str); if(_client && log) _client->Info(str);
......
...@@ -36,6 +36,10 @@ class Msg { ...@@ -36,6 +36,10 @@ class Msg {
static int _progressMeterStep, _progressMeterCurrent; static int _progressMeterStep, _progressMeterCurrent;
// timers // timers
static std::map<std::string, double> _timers; static std::map<std::string, double> _timers;
// report cpu time for each info message?
static bool _infoCpu;
// starting time (gettimeofday at startup)
static double _startTime;
// counters // counters
static int _warningCount, _errorCount, _atLeastOneErrorInRun; static int _warningCount, _errorCount, _atLeastOneErrorInRun;
static std::string _firstWarning, _firstError; static std::string _firstWarning, _firstError;
...@@ -80,6 +84,8 @@ class Msg { ...@@ -80,6 +84,8 @@ class Msg {
{ {
return _commandLineStrings; return _commandLineStrings;
} }
static std::string PrintResources(bool printDate, bool printWallTime,
bool printCpu, bool printMem);
static void Fatal(const char *fmt, ...); static void Fatal(const char *fmt, ...);
static void Error(const char *fmt, ...); static void Error(const char *fmt, ...);
static void Warning(const char *fmt, ...); static void Warning(const char *fmt, ...);
...@@ -94,6 +100,7 @@ class Msg { ...@@ -94,6 +100,7 @@ class Msg {
static void SetProgressMeterStep(int step){ _progressMeterStep = step; } static void SetProgressMeterStep(int step){ _progressMeterStep = step; }
static int GetProgressMeterStep(){ return _progressMeterStep; } static int GetProgressMeterStep(){ return _progressMeterStep; }
static void ResetProgressMeter(){ if(!_commRank) _progressMeterCurrent = 0; } static void ResetProgressMeter(){ if(!_commRank) _progressMeterCurrent = 0; }
static void SetInfoCpu(bool val){ _infoCpu = val; }
static double &Timer(std::string str){ return _timers[str]; } static double &Timer(std::string str){ return _timers[str]; }
static void PrintTimers(); static void PrintTimers();
static void ResetErrorCounter(); static void ResetErrorCounter();
......
...@@ -365,6 +365,19 @@ double TotalRam() ...@@ -365,6 +365,19 @@ double TotalRam()
return ram; return ram;
} }
double TimeOfDay()
{
#if defined(WIN32) && !defined(__CYGWIN__)
struct _timeb localTime;
_ftime(&localTime);
return localTime.time + 1.e-3 * localTime.millitm;
#else
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec + 1.e-6 * t.tv_usec;
#endif
}
long GetMemoryUsage() long GetMemoryUsage()
{ {
long mem = 0; long mem = 0;
......
...@@ -17,6 +17,7 @@ void SleepInSeconds(double s); ...@@ -17,6 +17,7 @@ void SleepInSeconds(double s);
void CheckResources(); void CheckResources();
double Cpu(); double Cpu();
double TotalRam(); double TotalRam();
double TimeOfDay();
long GetMemoryUsage(); long GetMemoryUsage();
int GetProcessId(); int GetProcessId();
std::string GetExecutableFileName(); std::string GetExecutableFileName();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment