当前位置: 首页>>代码示例>>Java>>正文


Java OSProcess类代码示例

本文整理汇总了Java中oshi.software.os.OSProcess的典型用法代码示例。如果您正苦于以下问题:Java OSProcess类的具体用法?Java OSProcess怎么用?Java OSProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OSProcess类属于oshi.software.os包,在下文中一共展示了OSProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
 
开发者ID:Frederikam,项目名称:Lavalink,代码行数:20,代码来源:StatsTask.java

示例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());
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:24,代码来源:Process.java

示例3: printProcesses

import oshi.software.os.OSProcess; //导入依赖的package包/类
/**
 * Prints the processes.
 *
 * @param os the os
 * @param memory the memory
 */
private static void printProcesses(OperatingSystem os, GlobalMemory memory) {
  oshi.add("Processes: " + os.getProcessCount() + ", Threads: " + os.getThreadCount());
  // Sort by highest CPU
  List<OSProcess> procs = Arrays.asList(os.getProcesses(5, ProcessSort.CPU));

  oshi.add("   PID  %CPU %MEM       VSZ       RSS Name");
  for (int i = 0; i < procs.size() && i < 5; i++) {
    OSProcess p = procs.get(i);
    oshi.add(String.format(" %5d %5.1f %4.1f %9s %9s %s%n", p.getProcessID(),
        100d * (p.getKernelTime() + p.getUserTime()) / p.getUpTime(),
        100d * p.getResidentSetSize() / memory.getTotal(),
        FormatUtil.formatBytes(p.getVirtualSize()),
        FormatUtil.formatBytes(p.getResidentSetSize()), p.getName()));
  }
}
 
开发者ID:psi-probe,项目名称:psi-probe,代码行数:22,代码来源:OshiController.java

示例4: update

import oshi.software.os.OSProcess; //导入依赖的package包/类
private void update() {
    List<OSProcess> procs = Arrays.asList(os.getProcesses(10, OperatingSystem.ProcessSort.CPU));
    for (OSProcess process : procs) {
        ProcessBean bean = null;
        if(processList.getItems().size() <= procs.indexOf(process)) {
            bean = beanManager.create(ProcessBean.class);
            processList.getItems().add(bean);
        } else {
            bean = processList.getItems().get(procs.indexOf(process));
        }
        bean.setProcessID(new Integer(process.getProcessID()).toString());
        bean.setCpuPercentage(format.format(100d * (process.getKernelTime() + process.getUserTime()) / process.getUpTime()));
        bean.setMemoryPercentage(format.format(100d * process.getResidentSetSize() / memory.getTotal()));
        bean.setName(process.getName());
    }
    asyncServerRunner.execute(new Runnable() {
        @Override
        public void run() {
            sessionExecutor.runLaterInClientSession(() -> update());
        }
    });
}
 
开发者ID:canoo,项目名称:dolphin-platform,代码行数:23,代码来源:ProcessMonitorController.java

示例5: getProcessResourceConsumptionInternal

import oshi.software.os.OSProcess; //导入依赖的package包/类
@Nullable
static ProcessResourceConsumption getProcessResourceConsumptionInternal(
    @Nullable OSProcess process) {
  if (process == null) {
    return null;
  }
  return ProcessResourceConsumption.builder()
      .setMemResident(process.getResidentSetSize())
      .setMemSize(process.getVirtualSize())
      .setCpuReal(process.getUpTime())
      .setCpuUser(process.getUserTime())
      .setCpuSys(process.getKernelTime())
      .setCpuTotal(process.getUserTime() + process.getKernelTime())
      .setIoBytesRead(process.getBytesRead())
      .setIoBytesWritten(process.getBytesWritten())
      .setIoTotal(process.getBytesRead() + process.getBytesWritten())
      .build();
}
 
开发者ID:facebook,项目名称:buck,代码行数:19,代码来源:ProcessHelper.java

示例6: setupDataUnix

import oshi.software.os.OSProcess; //导入依赖的package包/类
private void setupDataUnix(OperatingSystem.ProcessSort sort) {
    OSProcess[] processes = services.processorService.getProcessesList(sort);
    data = new String[processes.length][5];

    for(int i = 0; i < processes.length; i++) {
        // path, uptime, pid, name
        data[i][0] = processes[i].getName();
        data[i][1] = Integer.toString(processes[i].getProcessID());
        data[i][2] = Long.toString(processes[i].getResidentSetSize() / (1024 * 1024)) + " MB";
    }
}
 
开发者ID:ozankaraali,项目名称:SystemMonitor,代码行数:12,代码来源:ProcessesPanel.java

示例7: setUp

import oshi.software.os.OSProcess; //导入依赖的package包/类
@Before
public void setUp() {

    process = new Process(
            "name",
            "path",
            "commandLine",
            "user",
            "123",
            "group",
            "1233",
            OSProcess.State.RUNNING,
            100,
            99,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0);
}
 
开发者ID:Krillsson,项目名称:sys-api,代码行数:28,代码来源:ProcessesResourceTest.java

示例8: getProcess

import oshi.software.os.OSProcess; //导入依赖的package包/类
private OSProcess getProcess(int pid) throws DeviceNotFoundException {
    OSProcess process = operatingSystem.getProcess(pid);
    if (process == null) {
        throw new DeviceNotFoundException("Error while getting information for process with PID " + pid);
    }
    return process;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:8,代码来源:OshiSysteminfo.java

示例9: getProcessName

import oshi.software.os.OSProcess; //导入依赖的package包/类
@Override
public StringType getProcessName(int pid) throws DeviceNotFoundException {
    if (pid > 0) {
        OSProcess process = getProcess(pid);
        String name = process.getName();
        return new StringType(name);
    } else {
        return null;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java

示例10: 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;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:12,代码来源:OshiSysteminfo.java

示例11: getProcessMemoryUsage

import oshi.software.os.OSProcess; //导入依赖的package包/类
@Override
public DecimalType getProcessMemoryUsage(int pid) throws DeviceNotFoundException {
    if (pid > 0) {
        OSProcess process = getProcess(pid);
        long memortInBytes = process.getResidentSetSize();
        long memoryInMB = getSizeInMB(memortInBytes);
        return new DecimalType(memoryInMB);
    } else {
        return null;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:12,代码来源:OshiSysteminfo.java

示例12: getProcessPath

import oshi.software.os.OSProcess; //导入依赖的package包/类
@Override
public StringType getProcessPath(int pid) throws DeviceNotFoundException {
    if (pid > 0) {
        OSProcess process = getProcess(pid);
        String path = process.getPath();
        return new StringType(path);
    } else {
        return null;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java

示例13: getProcessThreads

import oshi.software.os.OSProcess; //导入依赖的package包/类
@Override
public DecimalType getProcessThreads(int pid) throws DeviceNotFoundException {
    if (pid > 0) {
        OSProcess process = getProcess(pid);
        int threadCount = process.getThreadCount();
        return new DecimalType(threadCount);
    } else {
        return null;
    }
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:11,代码来源:OshiSysteminfo.java

示例14: getProcessResourceConsumption

import oshi.software.os.OSProcess; //导入依赖的package包/类
/** Gets resource consumption of the process with the given pid. */
@Nullable
public ProcessResourceConsumption getProcessResourceConsumption(long pid) {
  try {
    OperatingSystem os = OSHI.getOperatingSystem();
    OSProcess process = os.getProcess((int) pid);
    return getProcessResourceConsumptionInternal(process);
  } catch (Exception ex) {
    // do nothing
    return null;
  }
}
 
开发者ID:facebook,项目名称:buck,代码行数:13,代码来源:ProcessHelper.java

示例15: add

import oshi.software.os.OSProcess; //导入依赖的package包/类
public Node add(OSProcess info) {
  Node node = getOrCreate(info.getProcessID());
  if (node.info == null) {
    node.info = info;
  }
  Node parent = getOrCreate(info.getParentProcessID());
  parent.addChild(node);
  return node;
}
 
开发者ID:facebook,项目名称:buck,代码行数:10,代码来源:ProcessHelper.java


注:本文中的oshi.software.os.OSProcess类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。