PDA

View Full Version : increase microprocessor



hassinoss
13th February 2014, 17:25
Hi,

is there a method to slow the loop without blocking the window.

here is my code:


while(m_pSocketUDP->hasPendingDatagrams())
{
T_Buffer *pBuffer=NULL;
Sleep(1);///////// i'm using Sleep() but it block the window
pBuffer = m_pBufferCirculaire->GetNextBuffer();

if(m_pSocketUDP)
m_pSocketUDP->readDatagram((char*)pBuffer->cData,MAX_SIZE_PACKET,&QHostAddress(m_pConnectionRTAS->szAddress),&quiPort);

sReveivevalidate = *((unsigned short*) &pBuffer->cData);
sSizePacketReceive = *((unsigned short*) &pBuffer->cData[POSITION_SIZE_PACKET]);
sDeadValue = *((unsigned short*) &pBuffer->cData[sSizePacketReceive - SIZE_END_PACKET]);

if(sReveivevalidate == KEY_SECURITY_RTAS && sDeadValue == END_PACKET)
pBuffer->cStatut = VALID_MSG;

if(m_pBufferCirculaire)
m_pBufferCirculaire->EnWriteOnNextBuffer();

}

thank you in advance

^NyAw^
13th February 2014, 17:50
Hi,

Use the SIGNAL SLOT mechanism provided by Qt. You will get a slot called every time the socket receives a packet.

Cruz
13th February 2014, 18:02
You could put the UDP communication process into a separate thread using QThread. But then it would also make sense to use waitForReadyRead() instead of just sleeping for 1 second.

hassinoss
13th February 2014, 18:38
i used the mechanism SIGNAL SLOT but there is always an increase microprocessor.

here is my code:



connect(m_pSocketUDP, SIGNAL(readyRead()), this, SLOT(MainTreatement()));


void CAcquisition::MainTreatement()
{

quint16 quiPort = m_iPort;
unsigned short sReveivevalidate = 0;
unsigned short sSizePacketReceive = 0;
unsigned short sDeadValue = 0;
T_Buffer *pBuffer=NULL;

while(m_pSocketUDP->hasPendingDatagrams())
{
T_Buffer *pBuffer=NULL;

pBuffer = m_pBufferCirculaire->GetNextBuffer();

if(m_pSocketUDP)
m_pSocketUDP->readDatagram((char*)pBuffer->cData,MAX_SIZE_PACKET,&QHostAddress(m_pConnectionRTAS->szAddress),&quiPort);

sReveivevalidate = *((unsigned short*) &pBuffer->cData);
sSizePacketReceive = *((unsigned short*) &pBuffer->cData[POSITION_SIZE_PACKET]);
sDeadValue = *((unsigned short*) &pBuffer->cData[sSizePacketReceive - SIZE_END_PACKET]);

if(sReveivevalidate == KEY_SECURITY_RTAS && sDeadValue == END_PACKET)
pBuffer->cStatut = VALID_MSG;

if(m_pBufferCirculaire)
m_pBufferCirculaire->EnWriteOnNextBuffer();

}
}

wysota
14th February 2014, 09:33
Use a profiler to check where your program spends the most time.

hassinoss
17th February 2014, 11:54
Can you help me to know how i can use profiler or other programme to analyse performance. now i use vs2012

Lesiok
17th February 2014, 13:01
You can find all informations here (http://lmgtfy.com/?q=visual+studio+2012+profiler+c%2B%2B)

hassinoss
27th August 2014, 17:00
how can I know the function that caused the increase of the microprocessor.

wysota
28th August 2014, 08:10
See post #5 in this thread.

hassinoss
28th August 2014, 10:53
i used profiler, i saw that my program spend the most time in the function "drawLines( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to ) const", and there is an increase of microprocessor until 20 %. Please how i can resolve this problem.

wysota
28th August 2014, 11:36
Don't draw as much :) And seriously trace back to your code which is effectively responsible for calling drawLines and see if you can optimize there. And by the way, looking at percentage of time your CPU spends in the process makes no sense. If system is idle and your process is doing any computing, the CPU will spend 100% of time there which isn't anything bad. You should monitor percepted latency or absolute time (or number of cycles) it takes for your process to do its job.

hassinoss
28th August 2014, 12:09
Thank you for your answer,

Firstly i'm sur that darwlines is responsible for increase microprocessor, because whene i comment it, there is no increase. secondly i can't optimise fucntion which call darwlines it's a function of qwt.

I don't understand what do you want to say by number of cycle?

wysota
28th August 2014, 13:03
Firstly i'm sur that darwlines is responsible for increase microprocessor, because whene i comment it, there is no increase. secondly i can't optimise fucntion which call darwlines it's a function of qwt.
Read my post again, especially the sentence starting with "Trace back to your code".


I don't understand what do you want to say by number of cycle?
I want to say that if some job makes the CPU execute 1000 instructions to complete and with a different algorithm it takes only 100 instructions then the second algorithm is more optimal than the first one.

d_stranz
29th August 2014, 00:18
secondly i can't optimise fucntion which call darwlines it's a function of qwt.

OK, so finally you have given us the first real clue about what is actually going on. Your performance problem is not in reading datagram packets from your socket, it is what you are doing with the data after you read them.

Apparently you are plotting this data using Qwt. When you run into a performance problem with Qwt, it almost always means you are trying to plot too much or plot it too frequently. Your processor gets completely tied up just drawing things.

In that case, don't do it whatever way you are trying to plot data. If you are causing Qwt to replot with every new point, then don't do that. Each time you change the data Qwt is plotting, it will redraw all of the data. Plot the data in larger chunks, or set up a QTimer that causes Qwt to update the plot only once very second or every 1/2 second. In almost every case, you don't need real time updates, but you can get by with frequent updates instead.