Results 1 to 14 of 14

Thread: increase microprocessor

  1. #1
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default increase microprocessor

    Hi,

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

    here is my code:
    Qt Code:
    1. while(m_pSocketUDP->hasPendingDatagrams())
    2. {
    3. T_Buffer *pBuffer=NULL;
    4. Sleep(1);///////// i'm using Sleep() but it block the window
    5. pBuffer = m_pBufferCirculaire->GetNextBuffer();
    6.  
    7. if(m_pSocketUDP)
    8. m_pSocketUDP->readDatagram((char*)pBuffer->cData,MAX_SIZE_PACKET,&QHostAddress(m_pConnectionRTAS->szAddress),&quiPort);
    9.  
    10. sReveivevalidate = *((unsigned short*) &pBuffer->cData);
    11. sSizePacketReceive = *((unsigned short*) &pBuffer->cData[POSITION_SIZE_PACKET]);
    12. sDeadValue = *((unsigned short*) &pBuffer->cData[sSizePacketReceive - SIZE_END_PACKET]);
    13.  
    14. if(sReveivevalidate == KEY_SECURITY_RTAS && sDeadValue == END_PACKET)
    15. pBuffer->cStatut = VALID_MSG;
    16.  
    17. if(m_pBufferCirculaire)
    18. m_pBufferCirculaire->EnWriteOnNextBuffer();
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    thank you in advance
    Last edited by anda_skoa; 13th February 2014 at 20:38. Reason: Added code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    Hi,

    Use the SIGNAL SLOT mechanism provided by Qt. You will get a slot called every time the socket receives a packet.
    Òscar Llarch i Galán

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    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.

  4. #4
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    i used the mechanism SIGNAL SLOT but there is always an increase microprocessor.

    here is my code:

    Qt Code:
    1. connect(m_pSocketUDP, SIGNAL(readyRead()), this, SLOT(MainTreatement()));
    2.  
    3.  
    4. void CAcquisition::MainTreatement()
    5. {
    6.  
    7. quint16 quiPort = m_iPort;
    8. unsigned short sReveivevalidate = 0;
    9. unsigned short sSizePacketReceive = 0;
    10. unsigned short sDeadValue = 0;
    11. T_Buffer *pBuffer=NULL;
    12.  
    13. while(m_pSocketUDP->hasPendingDatagrams())
    14. {
    15. T_Buffer *pBuffer=NULL;
    16.  
    17. pBuffer = m_pBufferCirculaire->GetNextBuffer();
    18.  
    19. if(m_pSocketUDP)
    20. m_pSocketUDP->readDatagram((char*)pBuffer->cData,MAX_SIZE_PACKET,&QHostAddress(m_pConnectionRTAS->szAddress),&quiPort);
    21.  
    22. sReveivevalidate = *((unsigned short*) &pBuffer->cData);
    23. sSizePacketReceive = *((unsigned short*) &pBuffer->cData[POSITION_SIZE_PACKET]);
    24. sDeadValue = *((unsigned short*) &pBuffer->cData[sSizePacketReceive - SIZE_END_PACKET]);
    25.  
    26. if(sReveivevalidate == KEY_SECURITY_RTAS && sDeadValue == END_PACKET)
    27. pBuffer->cStatut = VALID_MSG;
    28.  
    29. if(m_pBufferCirculaire)
    30. m_pBufferCirculaire->EnWriteOnNextBuffer();
    31.  
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 13th February 2014 at 20:40. Reason: Added code tags

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: increase microprocessor

    Use a profiler to check where your program spends the most time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    Can you help me to know how i can use profiler or other programme to analyse performance. now i use vs2012

  7. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    You can find all informations here

  8. #8
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    how can I know the function that caused the increase of the microprocessor.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: increase microprocessor

    See post #5 in this thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    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.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: increase microprocessor

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Dec 2013
    Location
    Jerada, Morroco
    Posts
    106
    Thanks
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: increase microprocessor

    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?

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: increase microprocessor

    Quote Originally Posted by hassinoss View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: increase microprocessor

    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.

Similar Threads

  1. How to increase progress bar
    By shivendra46d in forum Newbie
    Replies: 7
    Last Post: 11th September 2013, 14:07
  2. memory increase when use PageStack
    By jindoniit in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 13th October 2011, 12:23
  3. QSystemTrayIcon increase width
    By sagirahmed in forum General Programming
    Replies: 1
    Last Post: 28th September 2011, 16:33
  4. How to increase available RAM for Qt Creator?
    By fezvez in forum Qt Tools
    Replies: 4
    Last Post: 19th April 2011, 22:37
  5. Increase the height of titlebar, ...
    By vql in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2008, 12:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.