Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate WMI Query Handling from Util #728

Merged
merged 18 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
4.0.0 (in progress)
================
* [#728](https://github.com/oshi/oshi/pull/728): Separate WMI Query Handling from Util. - [@retomerz](https://github.com/retomerz).
* [#731](https://github.com/oshi/oshi/pull/731): Switch to MIT License, JNA 5.2.0. - [@dbwiddis](https://github.com/dbwiddis).
* Your contribution here.

3.12.1 (12/31/18)
3.12.1 (12/31/2018)
================
* [#730](https://github.com/oshi/oshi/pull/730): Fix Windows process token handle leak. - [@dbwiddis](https://github.com/dbwiddis).

3.12.0 (12/16/18)
3.12.0 (12/16/2018)
================
* [#694](https://github.com/oshi/oshi/pull/694): ComputerIdentifier Util Method - [@Aashishthakur10](https://github.com/Aashishthakur10).
* [#699](https://github.com/oshi/oshi/pull/699): Fix PerfData error handling - [@dbwiddis](https://github.com/dbwiddis).
* [#703](https://github.com/oshi/oshi/pull/703): Remove deprecated CentralProcessor serialNumber method - [@dbwiddis](https://github.com/dbwiddis).
* [#704](https://github.com/oshi/oshi/pull/704): Check for Virtual Machine - [@haidong](https://github.com/haidong).
* [#724](https://github.com/oshi/oshi/pull/724): Refactor unsigned long bitmasking - [@LiborB] (https://github.com/LiborB).

3.11.0 (11/21/18)
3.11.0 (11/21/2018)
================
* [#685](https://github.com/oshi/oshi/pull/685): Get Linux HZ from system config - [@dbwiddis](https://github.com/dbwiddis).
* [#686](https://github.com/oshi/oshi/pull/686): JNA 5.1.0 - [@dbwiddis](https://github.com/dbwiddis).
Expand All @@ -24,14 +25,14 @@
* [#690](https://github.com/oshi/oshi/pull/690): Prioritize system-release for Fedora and CentOS version - [@dbwiddis](https://github.com/dbwiddis).
* [#691](https://github.com/oshi/oshi/pull/691): Cache OSProcesses on Linux - [@dbwiddis](https://github.com/dbwiddis).

3.10.0 (11/03/18)
3.10.0 (11/03/2018)
================
* [#656](https://github.com/oshi/oshi/pull/656): JNA 5.0.0. - [@dbwiddis](https://github.com/dbwiddis).
* [#659](https://github.com/oshi/oshi/pull/659): Add free/total inode counts. - [@Space2Man](https://github.com/Space2Man).
* [#666](https://github.com/oshi/oshi/pull/666): Recreate counter handles when invalid - [@dbwiddis](https://github.com/dbwiddis).
* [#675](https://github.com/oshi/oshi/pull/675): Solaris 10 network stats compatibility fix - [@dbwiddis](https://github.com/dbwiddis).

3.9.1 (10/14/18)
3.9.1 (10/14/2018)
================
* [#647](https://github.com/oshi/oshi/pull/647): Fix Windows idle counter calculation. - [@dbwiddis](https://github.com/dbwiddis).
* [#653](https://github.com/oshi/oshi/pull/653): Fix transferTime in WindowsDisks by using 1-%Idle - [@Space2Man](https://github.com/Space2Man).
Expand Down Expand Up @@ -81,7 +82,7 @@
* [#567](https://github.com/oshi/oshi/pull/567): Cache USB devices. - [@dbwiddis](https://github.com/dbwiddis).
* [#569](https://github.com/oshi/oshi/pull/569): Remove threetenbp dependency. - [@dbwiddis](https://github.com/dbwiddis).

3.6.1 (6/28/2018), 3.6.2 (7/10/18)
3.6.1 (6/28/2018), 3.6.2 (7/10/2018)
================
* [#527](https://github.com/oshi/oshi/pull/527): Correct process information caching and command line retrieval under Windows - [@dustin-johnson](https://github.com/dustin-johnson).
* [#533](https://github.com/oshi/oshi/pull/533): Filter to CPU zone if multiple Windows Thermal sensors. - [@dbwiddis](https://github.com/dbwiddis).
Expand All @@ -98,15 +99,15 @@
* [#509](https://github.com/oshi/oshi/pull/509): Add pages swapped in/out to paging/swap file. - [@dbwiddis](https://github.com/dbwiddis).
* [#518](https://github.com/oshi/oshi/pull/518): Add OS bitness. - [@dbwiddis](https://github.com/dbwiddis).

3.5.0 (4/15/18)
3.5.0 (4/15/2018)
================
* [#446](https://github.com/oshi/oshi/pull/446): Add getChildProcesses to OperatingSystem. - [@jsimomaa](https://github.com/jsimomaa)
* [#447](https://github.com/oshi/oshi/pull/447), [#471](https://github.com/oshi/oshi/pull/471): Added context switches and interrupts - [@jpbempel](https://github.com/jpbempel), [@dbwiddis](https://github.com/dbwiddis).
* [#476](https://github.com/dblock/oshi/pull/476): Count CPU Packages - [@dbwiddis](https://github.com/dbwiddis).
* [#478](https://github.com/dblock/oshi/pull/478): Windows RSS now reports Private Working Set, matching Task Manager - [@dbwiddis](https://github.com/dbwiddis).
* Updated to JNA 4.5.1

3.4.5 (4/11/18)
3.4.5 (4/11/2018)
================
* [#433](https://github.com/oshi/oshi/pull/433): Performance improvements for getProcesses() on Linux - [@bildechinger](https://github.com/bildechinger).
* [#455](https://github.com/oshi/oshi/pull/455): Open files/handles support - [@spyhunter99](https://github.com/spyhunter99).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;

import oshi.hardware.common.AbstractBaseboard;
import oshi.util.platform.windows.WmiQueryHandler;
import oshi.util.platform.windows.WmiUtil;

/**
Expand All @@ -48,7 +49,7 @@ enum BaseboardProperty {

private void init() {
WmiQuery<BaseboardProperty> baseboardQuery = new WmiQuery<>("Win32_BaseBoard", BaseboardProperty.class);
WmiResult<BaseboardProperty> win32BaseBoard = WmiUtil.queryWMI(baseboardQuery);
WmiResult<BaseboardProperty> win32BaseBoard = WmiQueryHandler.getInstance().queryWMI(baseboardQuery);
if (win32BaseBoard.getResultCount() > 0) {
setManufacturer(WmiUtil.getString(win32BaseBoard, BaseboardProperty.MANUFACTURER, 0));
setModel(WmiUtil.getString(win32BaseBoard, BaseboardProperty.MODEL, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import oshi.hardware.common.AbstractCentralProcessor;
import oshi.util.platform.windows.PerfDataUtil;
import oshi.util.platform.windows.PerfDataUtil.PerfCounter;
import oshi.util.platform.windows.WmiQueryHandler;
import oshi.util.platform.windows.WmiUtil;

/**
Expand Down Expand Up @@ -174,7 +175,7 @@ private void initVars() {
}

WmiQuery<ProcessorProperty> processorIdQuery = new WmiQuery<>("Win32_Processor", ProcessorProperty.class);
WmiResult<ProcessorProperty> processorId = WmiUtil.queryWMI(processorIdQuery);
WmiResult<ProcessorProperty> processorId = WmiQueryHandler.getInstance().queryWMI(processorIdQuery);
if (processorId.getResultCount() > 0) {
setProcessorID(WmiUtil.getString(processorId, ProcessorProperty.PROCESSORID, 0));
}
Expand Down Expand Up @@ -334,7 +335,8 @@ public long[] getSystemCpuLoadTicks() {
ticks[TickType.IRQ.getIndex()] = PerfDataUtil.queryCounter(this.irqTickCounter) / 10_000L;
ticks[TickType.SOFTIRQ.getIndex()] = PerfDataUtil.queryCounter(this.softIrqTickCounter) / 10_000L;
} else {
WmiResult<SystemTickCountProperty> result = WmiUtil.queryWMI(this.systemTickCountQuery);
WmiResult<SystemTickCountProperty> result = WmiQueryHandler.getInstance()
.queryWMI(this.systemTickCountQuery);
if (result.getResultCount() > 0) {
ticks[TickType.IRQ.getIndex()] = WmiUtil.getUint64(result, SystemTickCountProperty.PERCENTINTERRUPTTIME,
0) / 10_000L;
Expand Down Expand Up @@ -386,7 +388,8 @@ public long[][] getProcessorCpuLoadTicks() {
}
} else {
ticks = new long[this.logicalProcessorCount][TickType.values().length];
WmiResult<ProcessorTickCountProperty> result = WmiUtil.queryWMI(this.processorTickCountQuery);
WmiResult<ProcessorTickCountProperty> result = WmiQueryHandler.getInstance()
.queryWMI(this.processorTickCountQuery);
for (int cpu = 0; cpu < result.getResultCount() && cpu < this.logicalProcessorCount; cpu++) {
ticks[cpu][TickType.SYSTEM.getIndex()] = WmiUtil.getUint64(result,
ProcessorTickCountProperty.PERCENTPRIVILEGEDTIME, cpu);
Expand Down Expand Up @@ -443,7 +446,7 @@ public long getContextSwitches() {
PerfDataUtil.updateQuery(this.contextSwitchesPerSecCounter);
return PerfDataUtil.queryCounter(this.contextSwitchesPerSecCounter);
}
WmiResult<ContextSwitchProperty> result = WmiUtil.queryWMI(this.contextSwitchQuery);
WmiResult<ContextSwitchProperty> result = WmiQueryHandler.getInstance().queryWMI(this.contextSwitchQuery);
if (result.getResultCount() > 0) {
return WmiUtil.getUint32(result, ContextSwitchProperty.CONTEXTSWITCHESPERSEC, 0);
}
Expand All @@ -459,7 +462,7 @@ public long getInterrupts() {
refreshTickCounters();
return PerfDataUtil.queryCounter(this.interruptsPerSecCounter);
}
WmiResult<InterruptsProperty> result = WmiUtil.queryWMI(this.interruptsQuery);
WmiResult<InterruptsProperty> result = WmiQueryHandler.getInstance().queryWMI(this.interruptsQuery);
if (result.getResultCount() > 0) {
return WmiUtil.getUint32(result, InterruptsProperty.INTERRUPTSPERSEC, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;

import oshi.hardware.common.AbstractComputerSystem;
import oshi.util.platform.windows.WmiQueryHandler;
import oshi.util.platform.windows.WmiUtil;

/**
Expand Down Expand Up @@ -63,7 +64,8 @@ enum ComputerSystemProductProperty {
private void init() {
WmiQuery<ComputerSystemProperty> computerSystemQuery = new WmiQuery<>("Win32_ComputerSystem",
ComputerSystemProperty.class);
WmiResult<ComputerSystemProperty> win32ComputerSystem = WmiUtil.queryWMI(computerSystemQuery);
WmiResult<ComputerSystemProperty> win32ComputerSystem = WmiQueryHandler.getInstance()
.queryWMI(computerSystemQuery);
if (win32ComputerSystem.getResultCount() > 0) {
setManufacturer(WmiUtil.getString(win32ComputerSystem, ComputerSystemProperty.MANUFACTURER, 0));
setModel(WmiUtil.getString(win32ComputerSystem, ComputerSystemProperty.MODEL, 0));
Expand All @@ -81,13 +83,14 @@ private String getSystemSerialNumber() {
// This should always work
WmiQuery<BiosProperty> serialNumberQuery = new WmiQuery<>("Win32_BIOS where PrimaryBIOS=true",
BiosProperty.class);
WmiResult<BiosProperty> serialNumber = WmiUtil.queryWMI(serialNumberQuery);
WmiResult<BiosProperty> serialNumber = WmiQueryHandler.getInstance().queryWMI(serialNumberQuery);
if (serialNumber.getResultCount() > 0) {
this.systemSerialNumber = WmiUtil.getString(serialNumber, BiosProperty.SERIALNUMBER, 0);
}
// If the above doesn't work, this might
if ("".equals(this.systemSerialNumber)) {
WmiResult<ComputerSystemProductProperty> identifyingNumber = WmiUtil.queryWMI(IDENTIFYINGNUMBER_QUERY);
WmiResult<ComputerSystemProductProperty> identifyingNumber = WmiQueryHandler.getInstance()
.queryWMI(IDENTIFYINGNUMBER_QUERY);
if (identifyingNumber.getResultCount() > 0) {
this.systemSerialNumber = WmiUtil.getString(identifyingNumber,
ComputerSystemProductProperty.IDENTIFYINGNUMBER, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import oshi.util.ParseUtil;
import oshi.util.platform.windows.PerfDataUtil;
import oshi.util.platform.windows.PerfDataUtil.PerfCounter;
import oshi.util.platform.windows.WmiQueryHandler;
import oshi.util.platform.windows.WmiUtil;

/**
Expand Down Expand Up @@ -236,7 +237,7 @@ public HWDiskStore[] getDisks() {
populateReadWriteMaps(null);
populatePartitionMaps();

WmiResult<DiskDriveProperty> vals = WmiUtil.queryWMI(DISK_DRIVE_QUERY);
WmiResult<DiskDriveProperty> vals = WmiQueryHandler.getInstance().queryWMI(DISK_DRIVE_QUERY);

for (int i = 0; i < vals.getResultCount(); i++) {
HWDiskStore ds = new HWDiskStore();
Expand Down Expand Up @@ -291,7 +292,7 @@ private static void populateReadWriteMaps(String index) {
}
// If WMI query is not null, don't use counters
if (physicalDiskQuery != null) {
WmiResult<PhysicalDiskProperty> result = WmiUtil.queryWMI(physicalDiskQuery);
WmiResult<PhysicalDiskProperty> result = WmiQueryHandler.getInstance().queryWMI(physicalDiskQuery);
for (int i = 0; i < result.getResultCount(); i++) {
String name = getIndexFromName(WmiUtil.getString(result, PhysicalDiskProperty.NAME, i));
if (index != null && !index.equals(name) || TOTAL_INSTANCE.equals(name)) {
Expand Down Expand Up @@ -421,7 +422,8 @@ private void populatePartitionMaps() {
Matcher mDep;

// Map drives to partitions
WmiResult<DriveToPartitionProperty> drivePartitionMap = WmiUtil.queryWMI(DRIVE_TO_PARTITION_QUERY);
WmiResult<DriveToPartitionProperty> drivePartitionMap = WmiQueryHandler.getInstance()
.queryWMI(DRIVE_TO_PARTITION_QUERY);
for (int i = 0; i < drivePartitionMap.getResultCount(); i++) {
mAnt = DEVICE_ID.matcher(WmiUtil.getRefString(drivePartitionMap, DriveToPartitionProperty.ANTECEDENT, i));
mDep = DEVICE_ID.matcher(WmiUtil.getRefString(drivePartitionMap, DriveToPartitionProperty.DEPENDENT, i));
Expand All @@ -432,7 +434,8 @@ private void populatePartitionMaps() {
}

// Map partitions to logical disks
WmiResult<DriveToPartitionProperty> diskPartitionMap = WmiUtil.queryWMI(DISK_TO_PARTITION_QUERY);
WmiResult<DriveToPartitionProperty> diskPartitionMap = WmiQueryHandler.getInstance()
.queryWMI(DISK_TO_PARTITION_QUERY);
for (int i = 0; i < diskPartitionMap.getResultCount(); i++) {
mAnt = DEVICE_ID.matcher(WmiUtil.getRefString(diskPartitionMap, DriveToPartitionProperty.ANTECEDENT, i));
mDep = DEVICE_ID.matcher(WmiUtil.getRefString(diskPartitionMap, DriveToPartitionProperty.DEPENDENT, i));
Expand All @@ -442,7 +445,7 @@ private void populatePartitionMaps() {
}

// Next, get all partitions and create objects
WmiResult<DiskPartitionProperty> hwPartitionQueryMap = WmiUtil.queryWMI(PARTITION_QUERY);
WmiResult<DiskPartitionProperty> hwPartitionQueryMap = WmiQueryHandler.getInstance().queryWMI(PARTITION_QUERY);
for (int i = 0; i < hwPartitionQueryMap.getResultCount(); i++) {
String deviceID = WmiUtil.getString(hwPartitionQueryMap, DiskPartitionProperty.DEVICEID, i);
String logicalDrive = MapUtil.getOrDefault(partitionToLogicalDriveMap, deviceID, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.jna.platform.win32.COM.WbemcliUtil.WmiResult;

import oshi.hardware.common.AbstractFirmware;
import oshi.util.platform.windows.WmiQueryHandler;
import oshi.util.platform.windows.WmiUtil;

/**
Expand All @@ -49,7 +50,7 @@ enum BiosProperty {
private void init() {
WmiQuery<BiosProperty> biosQuery = new WmiQuery<>("Win32_BIOS where PrimaryBIOS=true", BiosProperty.class);

WmiResult<BiosProperty> win32BIOS = WmiUtil.queryWMI(biosQuery);
WmiResult<BiosProperty> win32BIOS = WmiQueryHandler.getInstance().queryWMI(biosQuery);
if (win32BIOS.getResultCount() > 0) {
setManufacturer(WmiUtil.getString(win32BIOS, BiosProperty.MANUFACTURER, 0));
setName(WmiUtil.getString(win32BIOS, BiosProperty.NAME, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import oshi.hardware.common.AbstractGlobalMemory;
import oshi.util.platform.windows.PerfDataUtil;
import oshi.util.platform.windows.PerfDataUtil.PerfCounter;
import oshi.util.platform.windows.WmiQueryHandler;
import oshi.util.platform.windows.WmiUtil;

/**
Expand Down Expand Up @@ -145,7 +146,7 @@ protected void updateMeminfo() {
}
}
if (this.pageSwapsQuery != null) {
WmiResult<PageSwapProperty> result = WmiUtil.queryWMI(this.pageSwapsQuery);
WmiResult<PageSwapProperty> result = WmiQueryHandler.getInstance().queryWMI(this.pageSwapsQuery);
if (result.getResultCount() > 0) {
this.swapPagesIn = WmiUtil.getUint32(result, PageSwapProperty.PAGESINPUTPERSEC, 0);
this.swapPagesOut = WmiUtil.getUint32(result, PageSwapProperty.PAGESOUTPUTPERSEC, 0);
Expand Down Expand Up @@ -174,7 +175,8 @@ protected void updateSwap() {
}
}
if (this.pagingPercentQuery != null) {
WmiResult<PagingPercentProperty> result = WmiUtil.queryWMI(this.pagingPercentQuery);
WmiResult<PagingPercentProperty> result = WmiQueryHandler.getInstance()
.queryWMI(this.pagingPercentQuery);
if (result.getResultCount() > 0) {
this.swapUsed = WmiUtil.getUint32(result, PagingPercentProperty.PERCENTUSAGE, 0) * this.pageSize;
}
Expand Down
Loading