Results 1 to 11 of 11

Thread: file access increasing cpu percentage

  1. #1
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default file access increasing cpu percentage

    Hi all,

    I'm created one sample application in Qt using QThread with Linux(UBUNTU) . Continuously reading three file at the same time i have checked the CPU percentage in terminal window , i got 89% to 95% so my application was getting hanging .
    How to solve this issue . Any one help me.


    Thanks in advance.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: file access increasing cpu percentage

    Quote Originally Posted by mania View Post
    I'm created one sample application in Qt using QThread with Linux(UBUNTU) . Continuously reading three file at the same time i have checked the CPU percentage in terminal window , i got 89% to 95% so my application was getting hanging
    I suspect you aren't running the background work of reading the 3 files using separate threads if your app is hanging. Post a minimal example of what you're doing to create/run the background threads.

  3. #3
    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: file access increasing cpu percentage

    Use QFileSystemWatcher instead of spinning a busy loop.
    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.


  4. #4
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: file access increasing cpu percentage

    Hi all,

    We have creating application for accessing GPIO lines in beaglebone, before reading file cpu percentage is 15% to 30 5 but after reading file cpu percentage goes to 91 % to 95 % .
    Any one help me and give a solution .

    Thanks in advance.

  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: file access increasing cpu percentage

    As I said you are spinning a busy loop so the usage will always go near 100%. Remove the busy loop in favour of a better mechanism and the usage will drop.
    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 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: file access increasing cpu percentage

    Quote Originally Posted by mania View Post
    Any one help me and give a solution.
    Two of us have already tried to help and you ignored both posts. I can't help you, nor can anyone else if you just keep restating your problem without showing your code.

  7. #7
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: file access increasing cpu percentage

    Hi all,

    Below is the sample code which i have used:

    Qt Code:
    1. void run()
    2. {
    3.  
    4. if(nBatteryCount==100)
    5. {
    6. QString status1,status2,status3;
    7. status1="5";
    8. status2="5";
    9. status3="5";
    10. QFile charger_status_file("/sys/class/gpio/gpio51/value");
    11. if(charger_status_file.open(QIODevice::ReadOnly))
    12. {
    13. status1=charger_status_file.readAll();
    14. }
    15. else
    16. {
    17.  
    18. }
    19. charger_status_file.close();
    20. status1=status1.trimmed();
    21.  
    22. QFile file1("/sys/class/gpio/gpio22/value");
    23. QFile file2("/sys/class/gpio/gpio50/value");
    24.  
    25. if(file1.open(QIODevice::ReadWrite))
    26. {
    27. status2=file1.readAll();
    28. }
    29.  
    30. if(file2.open(QIODevice::ReadWrite))
    31. {
    32. status3=file2.readAll();
    33. }
    34. file1.close();
    35. file2.close();
    36. status2=status2.trimmed();
    37. status3=status3.trimmed();
    38.  
    39. if(status1 =="0" && status2 =="1" && status3=="1" && i1==0)
    40. {
    41. /** with charger with battery**/
    42. emit batteryChargeStatus(eChargeStatus_CHARGING);
    43. i1=1;
    44. i2=0;
    45. i3=0;
    46. i4=0;
    47. i5=0;
    48. }
    49. else if(status2 =="0" && status3=="1" && i2==0)
    50. {
    51. /** battery full **/
    52. emit batteryChargeStatus(eChargeStatus_FULL);
    53. i1=0;
    54. i2=1;
    55. i3=0;
    56. i4=0;
    57. i5=0;
    58. }
    59. else if(status1 =="0" && status2 =="0" && status3=="0" && i3==0)
    60. {
    61. /** Invalid charger/battery not available **/
    62. emit batteryChargeStatus(eChargeStatus_NONE);
    63. i1=0;
    64. i2=0;
    65. i3=1;
    66. i4=0;
    67. i5=0;
    68. }
    69. else if(status1 =="0" && status2 =="1" && status3=="0" && i4==0)
    70. {
    71. if(charger_count==10)
    72. {
    73. /** charging **/
    74. emit batteryChargeStatus(eChargeStatus_CHARGING);
    75. i1=0;
    76. i2=0;
    77. i3=0;
    78. i4=1;
    79. i5=0;
    80. charger_count=0;
    81. }
    82. else
    83. {
    84. charger_count++;
    85. }
    86. }
    87. else if(status1 =="1" && status2 =="1" && status3=="1")
    88. {
    89. /** ADC **/
    90. if(i5==0)
    91. {
    92. emit batteryChargeStatus(eChargerStatus_NONE);
    93. }
    94. float adc;
    95. batteryvoltage(adc);
    96. i1=0;
    97. i2=0;
    98. i3=0;
    99. i4=0;
    100. i5=1;
    101. }
    102. nBatteryCount=0;
    103. }
    104. else
    105. {
    106. nBatteryCount++;
    107. }
    108.  
    109. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 29th January 2015 at 11:01. Reason: missing [code] tags

  8. #8
    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: file access increasing cpu percentage

    Quote Originally Posted by mania View Post
    Hi all,

    Below is the sample code which i have used:
    Yeah... and?
    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.


  9. #9
    Join Date
    Nov 2012
    Location
    Coimbatore
    Posts
    53
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: file access increasing cpu percentage

    Hi,
    void run() function will continuously run and assessing the file repeatedly , so the cpu percentage will goes to nearly 91% . How to reduce cpu % by assessing those files?

    Thanks in advance.

  10. #10
    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: file access increasing cpu percentage

    What is the meaning of non-stop checking the status of battery ? It is sufficient for example 10 times per second.

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: file access increasing cpu percentage

    Quote Originally Posted by mania View Post
    void run() function will continuously run and assessing the file repeatedly
    How does it do that? There is on loop in there.

    Quote Originally Posted by mania View Post
    How to reduce cpu % by assessing those files?
    By not continuously running without pause? Like several people already said?

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 18th October 2013, 19:16
  2. how can i draw rectanglar percentage?
    By icapathos in forum Qt Programming
    Replies: 7
    Last Post: 22nd August 2013, 14:36
  3. Font size in percentage
    By pssss in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2011, 17:27
  4. QStyleSheet font-size as percentage?
    By dhalbert in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2010, 07:00
  5. QGridLayout - specific widh-hight by percentage
    By elcuco in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2010, 16:56

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.