Skip to content

Commit 5aba6e5

Browse files
authored
Measure the time performance of instance api (#10439)
Added a command line argument `--NAPIProfiling=true`. Prints the time measurement to the console for each call to `getModelInstance`
1 parent d06ba1f commit 5aba6e5

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

OMEdit/OMEditGUI/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ void signalHandler(int signalNumber)
132132
void printOMEditUsage()
133133
{
134134
printf("Usage: OMEdit --Debug=true|false] [files]\n");
135-
printf(" --Debug=[true|false] Enables the debugging features like QUndoView, diffModelicaFileListings view. Default is false.\n");
136-
printf(" --NAPI=[true|false] Enables the use of new json based api.\n");
135+
printf(" --Debug=[true|false] Enables the debugging features like QUndoView, diffModelicaFileListings view. Default is false.\n");
136+
printf(" --NAPI=[true|false] Enables the use of new json based api.\n");
137+
printf(" --NAPIProfiling=[true|false] Enables the profiling of new json based api.\n");
137138
printf(" files List of Modelica files(*.mo) to open.\n");
138139
}
139140

OMEdit/OMEditLIB/MainWindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ class MainWindow : public QMainWindow
108108
void setNewApi(bool newApi) {mNewApi = newApi;}
109109
bool isNewApiCommandLine() const {return mNewApiCommandLine;}
110110
void setNewApiCommandLine(bool newApiCommandLine) {mNewApiCommandLine = newApiCommandLine;}
111+
bool isNewApiProfiling() const {return mNewApiProfiling;}
112+
void setNewApiProfiling(bool newApiProfiling) {mNewApiProfiling = newApiProfiling;}
111113
bool isTestsuiteRunning() const {return mTestsuiteRunning;}
112114
void setTestsuiteRunning(bool testsuiteRunning) {mTestsuiteRunning = testsuiteRunning;}
113115
OMCProxy* getOMCProxy() {return mpOMCProxy;}
@@ -266,6 +268,7 @@ class MainWindow : public QMainWindow
266268
bool mDebug;
267269
bool mNewApi;
268270
bool mNewApiCommandLine;
271+
bool mNewApiProfiling;
269272
bool mTestsuiteRunning;
270273
OMCProxy *mpOMCProxy;
271274
bool mExitApplicationStatus;

OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,10 @@ bool GraphicsView::addComponent(QString className, QPointF position)
956956
ModelInstance::Component *pComponent = new ModelInstance::Component(pModelInstance);
957957
pComponent->setName(name);
958958
pComponent->setType(pLibraryTreeItem->getNameStructure());
959-
pComponent->setModel(new ModelInstance::Model(MainWindow::instance()->getOMCProxy()->getModelInstance(pLibraryTreeItem->getNameStructure())));
959+
/* We use getModelInstanceIcon here for bettter performance
960+
* This model will be updated right after this so it doesn't matter if the Component has complete model or not.
961+
*/
962+
pComponent->setModel(new ModelInstance::Model(MainWindow::instance()->getOMCProxy()->getModelInstance(pLibraryTreeItem->getNameStructure(), false, true)));
960963
pModelInstance->addElement(pComponent);
961964
ModelInfo oldModelInfo = mpModelWidget->createModelInfo();
962965
addElementToView(pComponent, false, true, true, position);
@@ -5810,9 +5813,24 @@ void ModelWidget::loadModelInstance(bool icon, const ModelInfo &modelInfo)
58105813
{
58115814
// save the current ModelInstance pointer so we can delete it later.
58125815
ModelInstance::Model *pOldModelInstance = mpModelInstance;
5816+
// call getModelInstance
5817+
const QJsonObject jsonObject = MainWindow::instance()->getOMCProxy()->getModelInstance(mpLibraryTreeItem->getNameStructure(), false, icon);
5818+
5819+
QElapsedTimer timer;
5820+
timer.start();
58135821
// set the new ModelInstance
5814-
mpModelInstance = new ModelInstance::Model(MainWindow::instance()->getOMCProxy()->getModelInstance(mpLibraryTreeItem->getNameStructure(), false, icon));
5822+
mpModelInstance = new ModelInstance::Model(jsonObject);
5823+
if (MainWindow::instance()->isNewApiProfiling()) {
5824+
qDebug() << "Time for parsing JSON" << (double)timer.elapsed() / 1000.0 << "secs";
5825+
}
5826+
5827+
timer.restart();
5828+
// drawing
58155829
drawModel(modelInfo);
5830+
if (MainWindow::instance()->isNewApiProfiling()) {
5831+
qDebug() << "Time for drawing graphical objects" << (double)timer.elapsed() / 1000.0 << "secs";
5832+
}
5833+
58165834
// delete the old ModelInstance
58175835
if (pOldModelInstance) {
58185836
delete pOldModelInstance;

OMEdit/OMEditLIB/OMC/OMCProxy.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,6 +3405,9 @@ QList<QString> OMCProxy::getAvailablePackageConversionsFrom(const QString &pkg,
34053405
*/
34063406
QJsonObject OMCProxy::getModelInstance(const QString &className, bool prettyPrint, bool icon)
34073407
{
3408+
QElapsedTimer timer;
3409+
timer.start();
3410+
34083411
QString modelInstanceJson = "";
34093412
if (icon) {
34103413
modelInstanceJson = mpOMCInterface->getModelInstanceIcon(className, prettyPrint);
@@ -3422,8 +3425,15 @@ QJsonObject OMCProxy::getModelInstance(const QString &className, bool prettyPrin
34223425
} else {
34233426
modelInstanceJson = mpOMCInterface->getModelInstance(className, QString(), prettyPrint);
34243427
}
3428+
3429+
if (MainWindow::instance()->isNewApiProfiling()) {
3430+
const QString api = icon ? "getModelInstanceIcon" : "getModelInstance";
3431+
qDebug() << "Time for" << QString("%1(%2)").arg(api, className) << (double)timer.elapsed() / 1000.0 << "secs";
3432+
}
3433+
34253434
printMessagesStringInternal();
34263435
if (!modelInstanceJson.isEmpty()) {
3436+
timer.restart();
34273437
QJsonParseError jsonParserError;
34283438
QJsonDocument doc = QJsonDocument::fromJson(modelInstanceJson.toUtf8(), &jsonParserError);
34293439
if (doc.isNull()) {
@@ -3432,6 +3442,9 @@ QJsonObject OMCProxy::getModelInstance(const QString &className, bool prettyPrin
34323442
.arg(className, jsonParserError.errorString()),
34333443
Helper::scriptingKind, Helper::errorLevel));
34343444
}
3445+
if (MainWindow::instance()->isNewApiProfiling()) {
3446+
qDebug() << "Time for converting to JSON" << (double)timer.elapsed() / 1000.0 << "secs";
3447+
}
34353448
return doc.object();
34363449
}
34373450
return QJsonObject();

OMEdit/OMEditLIB/OMEditApplication.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ OMEditApplication::OMEditApplication(int &argc, char **argv, threadData_t* threa
109109
// if user has requested to open the file by passing it in argument then,
110110
bool debug = false;
111111
bool newApi = false;
112+
bool newApiProfiling = false;
112113
bool newApiCommandLine = false;
113114
QString fileName = "";
114115
QStringList fileNames, invalidFlags;
@@ -127,6 +128,12 @@ OMEditApplication::OMEditApplication(int &argc, char **argv, threadData_t* threa
127128
if (0 == strcmp("true", napiArg.toUtf8().constData())) {
128129
newApi = true;
129130
}
131+
} else if (strncmp(arguments().at(i).toUtf8().constData(), "--NAPIProfiling=",16) == 0) {
132+
QString napiProfilingArg = arguments().at(i);
133+
napiProfilingArg.remove("--NAPIProfiling=");
134+
if (0 == strcmp("true", napiProfilingArg.toUtf8().constData())) {
135+
newApiProfiling = true;
136+
}
130137
} else {
131138
fileName = arguments().at(i);
132139
if (!fileName.isEmpty()) {
@@ -151,6 +158,7 @@ OMEditApplication::OMEditApplication(int &argc, char **argv, threadData_t* threa
151158
pMainwindow->setDebug(debug);
152159
pMainwindow->setNewApi(newApi);
153160
pMainwindow->setNewApiCommandLine(newApiCommandLine);
161+
pMainwindow->setNewApiProfiling(newApiProfiling);
154162
pMainwindow->setTestsuiteRunning(testsuiteRunning);
155163
pMainwindow->setUpMainWindow(threadData);
156164
if (pMainwindow->getExitApplicationStatus()) { // if there is some issue in running the application.

0 commit comments

Comments
 (0)