QtConcurrent::map uses 100% of CPU
-
Well, i have the function "executeAllActiveTasks" that takes a string as an argument and calls a function "requestandsaveData", this function does a snmp-get to an specific device and waits until the data is available and then saves the data in a file. The following is the code for "executeAllActiveTasks"
@void executeAllActiveTasks(QString tname)
{
// double val;
QDir path( "./databases/" );task *t = tasks.value(tname); RCDevice *d = devices.value(t->device_id()); if(t!=NULL || t->status()!=STARTED || d!=NULL) { Metrics.value(t->metricType())->requestAndSaveData(d,path.absolutePath()+ QString("/") +t->taskName()+QString(".rrd"),t->metricType(),t->metricParams(),0); }}@
I call that function with the following code, where "taskActivesByThread" it is a QStringList...
@watcher.setFuture(QtConcurrent::map(tasksActivesByThread,executeAllActiveTasks));
@ -
It is up to the size of the "taskActivesByThread" and the time to get the response of the devices, it could be one minute or even more. The application works fine, but I just want to know if any other alternative methods would produce 100% of CPU while the polling is active...
-
Well, yesss..they are waiting for the results to be ready, but just because a thread is in an active state will produce a huge increment in the cpu?
-
It is thread safe...the snmp get is really a "QProcess" calling the libraries of the net-snmp, so i need the wait until the "QProcess" finish to captutre the data...
-
It's something like this...
@
QProcess snmpGet;
snmpGet.start(program,params);if (snmpGet.waitForStarted())
{
if (!snmpGet.waitForFinished())
{
return INVALID_VALUE;
}
QString output(snmpGet.readAll());
//Then i have to parsing the data to obtain the data...}else{
return INVALID_VALUE
}@
-
Profile it and see where the profiler says the cpu is spending all of its time.