Skip to content

Commit

Permalink
Merge pull request #32 from robbr48/performance_improvements
Browse files Browse the repository at this point in the history
Various performance improvements
  • Loading branch information
robbr48 authored Nov 24, 2017
2 parents 2770227 + 88a5f45 commit 24ed1c5
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 12 deletions.
16 changes: 12 additions & 4 deletions FMIWrapper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ void initializeLogging() {
logStream.open(LOG_FILE_NAME);
if(logStream.is_open()) {
std::regex exp(simConfig.variableFilter);
logStreamOpen = true;
logStream << "\"time\"";
fmi2_import_variable_list_t *list = fmi2_import_get_variable_list(fmu,0);
size_t nVar = fmi2_import_get_variable_list_size(list);
for(size_t i=0; i<nVar; ++i) {
Expand All @@ -116,8 +114,16 @@ void initializeLogging() {
logVariables.push_back(fmi2_import_get_variable_vr(var));
}
}
if(logVariables.empty()) {
logStreamOpen = false;
logStream.close();
return;
}
}

logStreamOpen = true;
logStream << "\"time\"";

for(size_t i=0; i<logVariables.size(); ++i) {
fmi2_value_reference_t vr = logVariables[i];
fmi2_import_variable_t* var = fmi2_import_get_variable_by_vr(fmu,fmi2_base_type_real,vr);
Expand Down Expand Up @@ -1297,8 +1303,8 @@ void createAndClearTempDirectory(std::string path)

int main(int argc, char* argv[])
{
TLMErrorLog::SetNormalErrorLogOn(true);
TLMErrorLog::SetWarningOut(true);
TLMErrorLog::SetNormalErrorLogOn(false);
TLMErrorLog::SetWarningOut(false);

if(argc < 2) {
cout << "Too few arguments." << endl << endl;
Expand Down Expand Up @@ -1337,6 +1343,8 @@ int main(int argc, char* argv[])
simConfig.solver = IDA;
else if(!strcmp(argv[i],"-d")) {
TLMErrorLog::SetDebugOut(true);
TLMErrorLog::SetNormalErrorLogOn(true);
TLMErrorLog::SetWarningOut(true);
cout << "Activating debug output" << endl;
}
else if(!strcmp(argv[i],"-l") && argc > i+1) {
Expand Down
10 changes: 7 additions & 3 deletions common/Communication/ManagerCommHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,10 @@ void ManagerCommHandler::ForwardToMonitor(TLMMessage& message) {
pos != monitorInterfaceMap.upper_bound(TLMInterfaceID);
pos++) {

TLMErrorLog::Log("Forwarding to monitor, interface " + TLMErrorLog::ToStdStr(TLMInterfaceID)
+ " on socket " + TLMErrorLog::ToStdStr(pos->second));
if(TLMErrorLog::IsNormalErrorLogOn()) {
TLMErrorLog::Log("Forwarding to monitor, interface " + TLMErrorLog::ToStdStr(TLMInterfaceID)
+ " on socket " + TLMErrorLog::ToStdStr(pos->second));
}

int hdl = pos->second;

Expand All @@ -792,7 +794,9 @@ void ManagerCommHandler::ForwardToMonitor(TLMMessage& message) {
}
}
else {
TLMErrorLog::Log("Nothing to forward for monitor interface " + TLMErrorLog::ToStdStr(TLMInterfaceID));
if(TLMErrorLog::IsNormalErrorLogOn()) {
TLMErrorLog::Log("Nothing to forward for monitor interface " + TLMErrorLog::ToStdStr(TLMInterfaceID));
}
}
monitorMapLock.unlock();
}
Expand Down
4 changes: 3 additions & 1 deletion common/Communication/TLMClientComm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ void TLMClientComm::UnpackTimeDataMessageSignal(TLMMessage &mess, std::deque<TLM
TLMCommUtil::ByteSwap(Next, sizeof(double), mess.Header.DataSize/sizeof(double));

for(unsigned i = 0; i < mess.Header.DataSize/sizeof(TLMTimeDataSignal); i++, Next++) {
TLMErrorLog::Log(" RECV for time= " + TLMErrorLog::ToStdStr(Next->time));
if(TLMErrorLog::IsNormalErrorLogOn()) {
TLMErrorLog::Log(" RECV for time= " + TLMErrorLog::ToStdStr(Next->time));
}
Data.push_back(*Next);
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/CompositeModels/CompositeModel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void TLMComponentProxy::StartComponent(SimulationParams& SimParams, double MaxSt
if(StartCommand != "none") {
string startTime = SimParams.GetStartTimeStr();
string endTime = SimParams.GetEndTimeStr();
string strMaxStep = TLMErrorLog::ToStdStr(MaxStep);
string strMaxStep = std::to_string(MaxStep);
string serverName = SimParams.GetServerName();

#if defined(WIN32)
Expand Down
6 changes: 6 additions & 0 deletions common/Logging/TLMErrorLog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ void TLMErrorLog::Log(const std::string& mess) {

// A utility function often used to log numerical information
std::string TLMErrorLog::ToStdStr(double val) {
if(!NormalErrorLogOn) {
return "";
}
char buf[30];

sprintf(buf, "%.10f", val);
Expand All @@ -131,6 +134,9 @@ std::string TLMErrorLog::ToStdStr(double val) {

// A utility function often used to log numerical information
std::string TLMErrorLog::ToStdStr(int val) {
if(!NormalErrorLogOn) {
return "";
}
char buf[30];

sprintf(buf, "%d", val);
Expand Down
2 changes: 2 additions & 0 deletions common/Logging/TLMErrorLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class TLMErrorLog {
//! Input: if Enable is true - output is on, othewise - off.
static void SetNormalErrorLogOn(bool Enable) { NormalErrorLogOn = Enable; }

static bool IsNormalErrorLogOn() { return NormalErrorLogOn; }

//! This function enables/disables warning messages
//! Input: if Enable is true - output is on, othewise - off.
static void SetWarningOut(bool Enable) { WarningOn = Enable; }
Expand Down
4 changes: 3 additions & 1 deletion common/MonitorMain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ void MonitorTimeStep(TLMPlugin* TLMlink,
int dimensions = interfaceProxy.GetDimensions();
string causality = interfaceProxy.GetCausality();

TLMErrorLog::Log("Data request for " + interfaceProxy.GetName() + " for time " + ToStr(SimTime) + ", id: " + ToStr(interfaceID));
if(TLMErrorLog::IsNormalErrorLogOn()) {
TLMErrorLog::Log("Data request for " + interfaceProxy.GetName() + " for time " + ToStr(SimTime) + ", id: " + ToStr(interfaceID));
}

if(connectionID >= 0) {
#define LOGGEDFORCEFIX
Expand Down
6 changes: 4 additions & 2 deletions common/Plugin/MonitoringPluginImplementer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ void MonitoringPluginImplementer::ReceiveTimeData(TLMInterface* reqIfc, double t
ifc->UnpackTimeData(Message);

// Received data
TLMErrorLog::Log(string("Interface ") + ifc->GetName() + " got data until time= "
+ TLMErrorLog::ToStdStr(ifc->GetNextRecvTime()));
if(TLMErrorLog::IsNormalErrorLogOn()) {
TLMErrorLog::Log(string("Interface ") + ifc->GetName() + " got data until time= "
+ TLMErrorLog::ToStdStr(ifc->GetNextRecvTime()));
}

} while(ifc != reqIfc); // loop until a message for this interface arrives

Expand Down

0 comments on commit 24ed1c5

Please sign in to comment.