Skip to content

Commit

Permalink
Write the instance api profiling to a file instanceApiProfiling.txt (
Browse files Browse the repository at this point in the history
…#10443)

* Write the instance api profiling to a file `instanceApiProfiling.txt`

* Fix build
  • Loading branch information
adeas31 committed Mar 24, 2023
1 parent c84168c commit 3647dc1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
38 changes: 38 additions & 0 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -407,6 +407,27 @@ void MainWindow::setUpMainWindow(threadData_t *threadData)
}
}

/*!
* \brief MainWindow::setNewApiProfiling
* Sets the new api profiling flag.
* If flag is enabled then creates a file for it.
* \param newApiProfiling
*/
void MainWindow::setNewApiProfiling(bool newApiProfiling)
{
mNewApiProfiling = newApiProfiling;
if (mNewApiProfiling) {
QString& tmpPath = Utilities::tempDirectory();
/* create a file to write OMEdit communication log */
QString profilingFilePath = QString("%1instanceApiProfiling.txt").arg(tmpPath);
#ifdef Q_OS_WIN
mpNewApiProfilingFile = _wfopen((wchar_t*)profilingFilePath.utf16(), L"w");
#else
mpNewApiProfilingFile = fopen(profilingFilePath.toUtf8().constData(), "w");
#endif
}
}

#if !defined(WITHOUT_OSG)
/*!
* \brief MainWindow::isThreeDViewerInitialized
Expand Down Expand Up @@ -677,6 +698,10 @@ void MainWindow::beforeClosingMainWindow()
GitCommands::destroy();
// delete the searchwidget object to call the destructor, to cancel the search operation running on seperate thread
delete mpSearchWidget;
// if new api profiling file is open then close it.
if (mpNewApiProfilingFile) {
fclose(mpNewApiProfilingFile);
}
}

/*!
Expand Down Expand Up @@ -1539,6 +1564,19 @@ QString MainWindow::getLibraryIndexFilePath() const
return QString("%1/.openmodelica/libraries/index.json").arg(Helper::userHomeDirectory);
}

/*!
* \brief MainWindow::writeNewApiProfiling
* Writes to new api profiling file.
* \param str
*/
void MainWindow::writeNewApiProfiling(const QString &str)
{
if (mpNewApiProfilingFile) {
fputs(QString("%1\n").arg(str).toUtf8().constData(), mpNewApiProfilingFile);
fflush(mpNewApiProfilingFile);
}
}

/*!
* \brief MainWindow::showMessagesBrowser
* Slot activated when MessagesWidget::MessageAdded signal is raised.\n
Expand Down
4 changes: 3 additions & 1 deletion OMEdit/OMEditLIB/MainWindow.h
Expand Up @@ -109,7 +109,7 @@ class MainWindow : public QMainWindow
bool isNewApiCommandLine() const {return mNewApiCommandLine;}
void setNewApiCommandLine(bool newApiCommandLine) {mNewApiCommandLine = newApiCommandLine;}
bool isNewApiProfiling() const {return mNewApiProfiling;}
void setNewApiProfiling(bool newApiProfiling) {mNewApiProfiling = newApiProfiling;}
void setNewApiProfiling(bool newApiProfiling);
bool isTestsuiteRunning() const {return mTestsuiteRunning;}
void setTestsuiteRunning(bool testsuiteRunning) {mTestsuiteRunning = testsuiteRunning;}
OMCProxy* getOMCProxy() {return mpOMCProxy;}
Expand Down Expand Up @@ -261,6 +261,7 @@ class MainWindow : public QMainWindow
static void LoadModelCallbackFunction(void *p, const char* modelName);
void addSystemLibraries();
QString getLibraryIndexFilePath() const;
void writeNewApiProfiling(const QString &str);

QList<QString> mFMUDirectoriesList;
QList<QString> mMOLDirectoriesList;
Expand All @@ -269,6 +270,7 @@ class MainWindow : public QMainWindow
bool mNewApi;
bool mNewApiCommandLine;
bool mNewApiProfiling;
FILE *mpNewApiProfilingFile = nullptr;
bool mTestsuiteRunning;
OMCProxy *mpOMCProxy;
bool mExitApplicationStatus;
Expand Down
8 changes: 6 additions & 2 deletions OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -5814,21 +5814,25 @@ void ModelWidget::loadModelInstance(bool icon, const ModelInfo &modelInfo)
// save the current ModelInstance pointer so we can delete it later.
ModelInstance::Model *pOldModelInstance = mpModelInstance;
// call getModelInstance
MainWindow::instance()->writeNewApiProfiling(mpLibraryTreeItem->getNameStructure());
const QJsonObject jsonObject = MainWindow::instance()->getOMCProxy()->getModelInstance(mpLibraryTreeItem->getNameStructure(), "", false, icon);

QElapsedTimer timer;
timer.start();
// set the new ModelInstance
mpModelInstance = new ModelInstance::Model(jsonObject);
if (MainWindow::instance()->isNewApiProfiling()) {
qDebug() << "Time for parsing JSON" << (double)timer.elapsed() / 1000.0 << "secs";
double elapsed = (double)timer.elapsed() / 1000.0;
MainWindow::instance()->writeNewApiProfiling(QString("Time for parsing JSON %1 secs").arg(QString::number(elapsed, 'f', 6)));
}

timer.restart();
// drawing
drawModel(modelInfo);
if (MainWindow::instance()->isNewApiProfiling()) {
qDebug() << "Time for drawing graphical objects" << (double)timer.elapsed() / 1000.0 << "secs";
double elapsed = (double)timer.elapsed() / 1000.0;
MainWindow::instance()->writeNewApiProfiling(QString("Time for drawing graphical objects %1 secs").arg(QString::number(elapsed, 'f', 6)));
MainWindow::instance()->writeNewApiProfiling("\n");
}

// delete the old ModelInstance
Expand Down
6 changes: 4 additions & 2 deletions OMEdit/OMEditLIB/OMC/OMCProxy.cpp
Expand Up @@ -3428,7 +3428,8 @@ QJsonObject OMCProxy::getModelInstance(const QString &className, const QString &

if (MainWindow::instance()->isNewApiProfiling()) {
const QString api = icon ? "getModelInstanceIcon" : "getModelInstance";
qDebug() << "Time for" << QString("%1(%2)").arg(api, className) << (double)timer.elapsed() / 1000.0 << "secs";
double elapsed = (double)timer.elapsed() / 1000.0;
MainWindow::instance()->writeNewApiProfiling(QString("Time for %1 %2 secs").arg(api, QString::number(elapsed, 'f', 6)));
}

printMessagesStringInternal();
Expand All @@ -3443,7 +3444,8 @@ QJsonObject OMCProxy::getModelInstance(const QString &className, const QString &
Helper::scriptingKind, Helper::errorLevel));
}
if (MainWindow::instance()->isNewApiProfiling()) {
qDebug() << "Time for converting to JSON" << (double)timer.elapsed() / 1000.0 << "secs";
double elapsed = (double)timer.elapsed() / 1000.0;
MainWindow::instance()->writeNewApiProfiling(QString("Time for converting to JSON %1 secs").arg(QString::number(elapsed, 'f', 6)));
}
return doc.object();
}
Expand Down

0 comments on commit 3647dc1

Please sign in to comment.