本文整理汇总了Java中oshi.software.os.OSProcess.getUserTime方法的典型用法代码示例。如果您正苦于以下问题:Java OSProcess.getUserTime方法的具体用法?Java OSProcess.getUserTime怎么用?Java OSProcess.getUserTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oshi.software.os.OSProcess
的用法示例。
在下文中一共展示了OSProcess.getUserTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProcessRecentCpuUsage
import oshi.software.os.OSProcess; //导入方法依赖的package包/类
private double getProcessRecentCpuUsage() {
double output = 0d;
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
OSProcess p = os.getProcess(os.getProcessId());
if (cpuTime != 0) {
double uptimeDiff = p.getUpTime() - uptime;
double cpuDiff = (p.getKernelTime() + p.getUserTime()) - cpuTime;
output = cpuDiff / uptimeDiff;
} else {
output = ((double) (p.getKernelTime() + p.getUserTime())) / (double) p.getUserTime();
}
// Record for next invocation
uptime = p.getUpTime();
cpuTime = p.getKernelTime() + p.getUserTime();
return output / hal.getProcessor().getLogicalProcessorCount();
}
示例2: create
import oshi.software.os.OSProcess; //导入方法依赖的package包/类
public static Process create(OSProcess process, GlobalMemory memory) {
return new Process(process.getName(),
process.getPath(),
process.getCommandLine(),
process.getUser(),
process.getUserID(),
process.getGroup(),
process.getGroupID(),
process.getState(),
process.getProcessID(),
process.getParentProcessID(),
process.getThreadCount(),
process.getPriority(),
process.getVirtualSize(),
process.getResidentSetSize(),
100d * process.getResidentSetSize() / memory.getTotal(),
process.getKernelTime(), process.getUserTime(),
process.getUpTime(),
100d * (process.getKernelTime() + process.getUserTime()) / process.getUpTime(),
process.getStartTime(),
process.getBytesRead(),
process.getBytesWritten());
}
示例3: getProcessCpuUsage
import oshi.software.os.OSProcess; //导入方法依赖的package包/类
@Override
public DecimalType getProcessCpuUsage(int pid) throws DeviceNotFoundException {
if (pid > 0) {
OSProcess process = getProcess(pid);
double cpuUsageRaw = (process.getKernelTime() + process.getUserTime()) / process.getUpTime();
BigDecimal cpuUsage = getPercentsValue(cpuUsageRaw);
return new DecimalType(cpuUsage);
} else {
return null;
}
}