Add more functions
This commit is contained in:
45
src/main/java/SBC/ProcessorStatus.java
Normal file
45
src/main/java/SBC/ProcessorStatus.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package SBC;
|
||||
|
||||
public class ProcessorStatus {
|
||||
public String name;
|
||||
public int user;
|
||||
public int nice;
|
||||
public int system;
|
||||
public int idle;
|
||||
public int iowait;
|
||||
public int irq;
|
||||
public int softirq;
|
||||
public int steal;
|
||||
public int guest;
|
||||
public int guest_nice;
|
||||
|
||||
/**
|
||||
* Calculate total CPU time
|
||||
* @return Total CPU time
|
||||
*/
|
||||
public int total_time(){
|
||||
return user + nice + system + idle + iowait + irq + softirq + steal + guest + guest_nice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate idle CPU time
|
||||
* @return Idle CPU time
|
||||
*/
|
||||
public int idle_time(){
|
||||
return idle + iowait;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate CPU usage percentage
|
||||
* @param prev Previous CPU information
|
||||
* @return CPU usage percentage 0 - 100
|
||||
*/
|
||||
public int cpu_usage(ProcessorStatus prev){
|
||||
if (prev!=null){
|
||||
int total_diff = total_time() - prev.total_time();
|
||||
int idle_diff = idle_time() - prev.idle_time();
|
||||
return (int)(100.0 * (total_diff - idle_diff) / total_diff);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user