📄 cputime.java
字号:
package fr.umlv.projet.procfs;import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;/** * This class is used to load or change Cpu time. * @author MA Xiao Jun & HUANG Wei */public class CpuTime { private String cpuName; private float user; private float nice; private float system; private float idle; /** * Load the cpu time by read the file "/proc/stat".And evaluate the corresponding value. */ public void loadCpuTime(){ try { Scanner sc = new Scanner(new File("/proc/stat")); this.cpuName = sc.next(); this.user = Float.parseFloat(sc.next()); this.nice = Float.parseFloat(sc.next()); this.system = Float.parseFloat(sc.next()); this.idle = Float.parseFloat(sc.next()); } catch (FileNotFoundException e) { e.printStackTrace(); } } /** * Return the name of cpu. * @return the name of cpu. */ public String getCpuNameTime() { return cpuName; } /** * Return the idle time of cpu. * @return value of idle time. */ public float getIdleTime() { return idle; } /** * Return the NiceTime of cpu. * @return value of NiceTime. */ public float getNiceTime() { return nice; } /** * Return the system time of cpu. * @return value of SystemTime. */ public float getSystemTime() { return system; } /** * Return the UserTime of cpu * @return value of UserTime. */ public float getUserTime() { return user; } /** * Return the total time of cpu * @return sum of user time,nice time,system time and idle time . */ public float getTotalTime(){ return user + nice + system + idle; } /** * Change the value of cputime. * @param cputime the new cputime. */ public void setTime(CpuTime cputime){ this.user = cputime.user; this.nice = cputime.nice; this.system = cputime.system; this.idle = cputime.idle; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -