PDA

View Full Version : file access increasing cpu percentage



mania
28th January 2015, 08:55
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.

jefftee
28th January 2015, 09:07
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.

wysota
28th January 2015, 09:53
Use QFileSystemWatcher instead of spinning a busy loop.

mania
29th January 2015, 06:54
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.

wysota
29th January 2015, 07:32
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.

jefftee
29th January 2015, 07:32
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.

mania
29th January 2015, 10:50
Hi all,

Below is the sample code which i have used:


void run()
{

if(nBatteryCount==100)
{
QString status1,status2,status3;
status1="5";
status2="5";
status3="5";
QFile charger_status_file("/sys/class/gpio/gpio51/value");
if(charger_status_file.open(QIODevice::ReadOnly))
{
status1=charger_status_file.readAll();
}
else
{

}
charger_status_file.close();
status1=status1.trimmed();

QFile file1("/sys/class/gpio/gpio22/value");
QFile file2("/sys/class/gpio/gpio50/value");

if(file1.open(QIODevice::ReadWrite))
{
status2=file1.readAll();
}

if(file2.open(QIODevice::ReadWrite))
{
status3=file2.readAll();
}
file1.close();
file2.close();
status2=status2.trimmed();
status3=status3.trimmed();

if(status1 =="0" && status2 =="1" && status3=="1" && i1==0)
{
/** with charger with battery**/
emit batteryChargeStatus(eChargeStatus_CHARGING);
i1=1;
i2=0;
i3=0;
i4=0;
i5=0;
}
else if(status2 =="0" && status3=="1" && i2==0)
{
/** battery full **/
emit batteryChargeStatus(eChargeStatus_FULL);
i1=0;
i2=1;
i3=0;
i4=0;
i5=0;
}
else if(status1 =="0" && status2 =="0" && status3=="0" && i3==0)
{
/** Invalid charger/battery not available **/
emit batteryChargeStatus(eChargeStatus_NONE);
i1=0;
i2=0;
i3=1;
i4=0;
i5=0;
}
else if(status1 =="0" && status2 =="1" && status3=="0" && i4==0)
{
if(charger_count==10)
{
/** charging **/
emit batteryChargeStatus(eChargeStatus_CHARGING);
i1=0;
i2=0;
i3=0;
i4=1;
i5=0;
charger_count=0;
}
else
{
charger_count++;
}
}
else if(status1 =="1" && status2 =="1" && status3=="1")
{
/** ADC **/
if(i5==0)
{
emit batteryChargeStatus(eChargerStatus_NONE);
}
float adc;
batteryvoltage(adc);
i1=0;
i2=0;
i3=0;
i4=0;
i5=1;
}
nBatteryCount=0;
}
else
{
nBatteryCount++;
}

}

wysota
29th January 2015, 11:02
Hi all,

Below is the sample code which i have used:


Yeah... and?

mania
29th January 2015, 11:24
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.

Lesiok
29th January 2015, 13:21
What is the meaning of non-stop checking the status of battery ? It is sufficient for example 10 times per second.

anda_skoa
29th January 2015, 14:26
void run() function will continuously run and assessing the file repeatedly

How does it do that? There is on loop in there.



How to reduce cpu % by assessing those files?

By not continuously running without pause? Like several people already said?

Cheers,
_