MCPcopy
hub / github.com/oshi/oshi / printProcesses

Method printProcesses

oshi-core/src/test/java/oshi/SystemInfoTest.java:266–291  ·  view source on GitHub ↗
(OperatingSystem os, GlobalMemory memory)

Source from the content-addressed store, hash-verified

264 }
265
266 private static void printProcesses(OperatingSystem os, GlobalMemory memory) {
267 OSProcess myProc = os.getProcess(os.getProcessId());
268 // current process will never be null. Other code should check for null here
269 oshi.add(
270 "My PID: " + myProc.getProcessID() + " with affinity " + Long.toBinaryString(myProc.getAffinityMask()));
271 oshi.add("Processes: " + os.getProcessCount() + ", Threads: " + os.getThreadCount());
272 // Sort by highest CPU
273 List<OSProcess> procs = os.getProcesses(ProcessFiltering.ALL_PROCESSES, ProcessSorting.CPU_DESC, 5);
274 oshi.add(" PID %CPU %MEM VSZ RSS Name");
275 for (int i = 0; i < procs.size() && i < 5; i++) {
276 OSProcess p = procs.get(i);
277 oshi.add(String.format(" %5d %5.1f %4.1f %9s %9s %s", p.getProcessID(),
278 100d * (p.getKernelTime() + p.getUserTime()) / p.getUpTime(),
279 100d * p.getResidentSetSize() / memory.getTotal(), FormatUtil.formatBytes(p.getVirtualSize()),
280 FormatUtil.formatBytes(p.getResidentSetSize()), p.getName()));
281 }
282 OSProcess p = os.getProcess(os.getProcessId());
283 oshi.add("Current process arguments: ");
284 for (String s : p.getArguments()) {
285 oshi.add(" " + s);
286 }
287 oshi.add("Current process environment: ");
288 for (Entry<String, String> e : p.getEnvironmentVariables().entrySet()) {
289 oshi.add(" " + e.getKey() + "=" + e.getValue());
290 }
291 }
292
293 private static void printServices(OperatingSystem os) {
294 oshi.add("Services: ");

Callers 1

mainMethod · 0.95

Calls 15

getProcessIDMethod · 0.95
getAffinityMaskMethod · 0.95
getKernelTimeMethod · 0.95
getUserTimeMethod · 0.95
getUpTimeMethod · 0.95
getResidentSetSizeMethod · 0.95
formatBytesMethod · 0.95
getVirtualSizeMethod · 0.95
getNameMethod · 0.95
getArgumentsMethod · 0.95
getKeyMethod · 0.80

Tested by

no test coverage detected