Diagnostic Tools Plugin for Qt Creator
Good day. Recently I got the idea to write a simple but functional plug-in for the Qt Creator development environment, designed to visualize data on RAM usage and load the CPU by the currently running process. As an inspiration for me, the "Diagnostic Tools" toolkit, which is present in Visual Studio, served. Below I will talk about the main development details.
Since the topic of creating plugins for Qt Creator is already described in detail on the Haber, for example, in the article System of Extensions Qt Creator , so I will not dwell on general information and go straight to the description of the plugin.
Actually, in order to get information about any process running in the operating system, first you need to find out its identifier (PID). The issue of getting the PID of the process launched through Qt Creator was what I dealt with first of all. After unsuccessful googling on this topic, I went on to study the source code of Qt Creator, during which I discovered that it was not difficult to find the required data. To do this, you need to catch the following signals emitted by a static instance of ProjectExplorer :: ProjectExplorerPlugin :: instance ():
Having received the runControlStarted signal (ProjectExplorer :: RunControl * rc), we remember to point m_runControlPtr to the ProjectExplorer :: RunControl * rc object and then run the data request using the applicationProcessHandleChanged signal.
The following tasks were trivial. In the Windows operating system, information about the memory used by the process and CPU loading was obtained through WinApi, in Linux - by analyzing the contents of the / proc / pid / stat and / proc / stat files.
The final touch is the visualization of the collected information. The first thought was to use the Qt module for plotting Qt Charts, but since this component is not part of Qt Creator out of the box and because of the simplicity of the task I am solving, it was finally decided to implement my own class for drawing graphs. Having finished working with the GUI, I began to think about where to place the created graphic form. On the one hand, it would be logical to place it below with the other output panels, on the other hand, I would like to see both the application output and information about the computer resources used by it. Therefore, a strong-willed (possibly unsuccessful) decision was made to place the graphic form on the left side panel. And so, what happened in the end:
Conclusion
The article described what has been done so far. Next, it is planned to create a version for Mac OS and add a settings window in which there will be the opportunity to set the polling interval, step on the graph, color, etc. Maybe someone will throw other ideas for improvement. View the source code and download the plugin here .
Thank you all for your attention.
UPD The
article was edited taking into account comments by the Krepver
Since the topic of creating plugins for Qt Creator is already described in detail on the Haber, for example, in the article System of Extensions Qt Creator , so I will not dwell on general information and go straight to the description of the plugin.
Actually, in order to get information about any process running in the operating system, first you need to find out its identifier (PID). The issue of getting the PID of the process launched through Qt Creator was what I dealt with first of all. After unsuccessful googling on this topic, I went on to study the source code of Qt Creator, during which I discovered that it was not difficult to find the required data. To do this, you need to catch the following signals emitted by a static instance of ProjectExplorer :: ProjectExplorerPlugin :: instance ():
void runControlStarted (ProjectExplorer :: RunControl * rc);
void runControlFinished (ProjectExplorer :: RunControl * rc);
// connects
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
&ProjectExplorer::ProjectExplorerPlugin::runControlStarted,
this, &DiagnosticToolsPlugin::onRunControlStarted);
connect(ProjectExplorer::ProjectExplorerPlugin::instance(),
&ProjectExplorer::ProjectExplorerPlugin::runControlFinished,
this, &DiagnosticToolsPlugin::onRunControlFinished);
// slots
void DiagnosticToolsPlugin::onRunControlStarted(ProjectExplorer::RunControl *rc){
m_runControlPtr = rc;
connect(m_runControlPtr,
&ProjectExplorer::RunControl::applicationProcessHandleChanged,
this, &DiagnosticToolsPlugin::onApplicationHandleChanged);
}
void DiagnosticToolsPlugin::onRunControlFinished(ProjectExplorer::RunControl *rc){
Q_UNUSED(rc)
m_runControlPtr = NULL;
m_dataQueryEngine->stopDataQuery();
}
void DiagnosticToolsPlugin::onApplicationHandleChanged(){
if (m_runControlPtr->applicationProcessHandle().isValid()){
m_dataQueryEngine->setPid(m_runControlPtr->applicationProcessHandle().pid());
m_dataQueryEngine->startDataQuery();
} else {
qDebug() << "Process handle is invalid";
}
}
Having received the runControlStarted signal (ProjectExplorer :: RunControl * rc), we remember to point m_runControlPtr to the ProjectExplorer :: RunControl * rc object and then run the data request using the applicationProcessHandleChanged signal.
The following tasks were trivial. In the Windows operating system, information about the memory used by the process and CPU loading was obtained through WinApi, in Linux - by analyzing the contents of the / proc / pid / stat and / proc / stat files.
The final touch is the visualization of the collected information. The first thought was to use the Qt module for plotting Qt Charts, but since this component is not part of Qt Creator out of the box and because of the simplicity of the task I am solving, it was finally decided to implement my own class for drawing graphs. Having finished working with the GUI, I began to think about where to place the created graphic form. On the one hand, it would be logical to place it below with the other output panels, on the other hand, I would like to see both the application output and information about the computer resources used by it. Therefore, a strong-willed (possibly unsuccessful) decision was made to place the graphic form on the left side panel. And so, what happened in the end:
Conclusion
The article described what has been done so far. Next, it is planned to create a version for Mac OS and add a settings window in which there will be the opportunity to set the polling interval, step on the graph, color, etc. Maybe someone will throw other ideas for improvement. View the source code and download the plugin here .
Thank you all for your attention.
UPD The
article was edited taking into account comments by the Krepver