Commit 937e4a58 authored by James's avatar James

- windows hard disk model via powershell query

parent c75e57c0
......@@ -38,16 +38,14 @@ v0.3
v0.4e
- updated eclipselink to 2.6 allows auto schema update
- improved gui initialization
- add path and drive type (usb, local) - works windows only
- windows hard disk model via powershell query
desired features
- hard drive specs, ie. manufacturer, model, capacity
- hard drive specs, ie. model
on linux: "hdparm -I /dev/sda"
https://www.cyberciti.biz/faq/linux-getting-scsi-ide-harddisk-information/
http://unix.stackexchange.com/questions/5085/how-to-see-disk-details-like-manufacturer-in-linux
on windows: "wmic diskdrive get name,size,model"
https://whatsonmypc.wordpress.com/2011/09/01/wmic/
https://sourceforge.net/projects/jacob-project/
- hard disk capacity and drive letter (windows)
- auto clear disk cache linux
- auto clear disk cache windows
......@@ -78,6 +78,7 @@
<target name="-post-jar">
<copy file="flushmem.exe" todir="dist"/>
<copy file="disk-model.ps1" todir="dist"/>
<antcall target="buildinfo"/>
<copy file="build.properties" todir="dist"/>
<mkdir dir="tmp"/>
......
# This powershell script is used to map drive letters to disk model numbers
# It is intended to be called by Runtime.getRuntime().exec(...)
Get-WmiObject Win32_DiskDrive | % {
$disk = $_
$partitions = "ASSOCIATORS OF " +
"{Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} " +
"WHERE AssocClass = Win32_DiskDriveToDiskPartition"
Get-WmiObject -Query $partitions | % {
$partition = $_
$drives = "ASSOCIATORS OF " +
"{Win32_DiskPartition.DeviceID='$($partition.DeviceID)'} " +
"WHERE AssocClass = Win32_LogicalDiskToPartition"
Get-WmiObject -Query $drives | % {
New-Object -Type PSCustomObject -Property @{
Disk = $disk.DeviceID
DiskSize = $disk.Size
DiskModel = $disk.Model
Partition = $partition.Name
RawSize = $partition.Size
DriveLetter = $_.DeviceID
VolumeName = $_.VolumeName
Size = $_.Size
FreeSpace = $_.FreeSpace
}
}
}
}
\ No newline at end of file
package jdiskmark;
import java.io.File;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.DecimalFormat;
......@@ -44,10 +43,7 @@ public class DiskRun implements Serializable {
// configuration
@Column
String dataPath = null;
@Column
String driveType = null;
// TODO: add drive manufacturer / model number info
String diskInfo = null;
@Column
IOMode ioMode;
@Column
......@@ -137,19 +133,12 @@ public class DiskRun implements Serializable {
public void setId(Long id) {
this.id = id;
}
public String getDriveType(String type) {
return this.driveType;
}
public void setDriveType(String type) {
driveType = type;
public String getDiskInfo() {
return diskInfo;
}
public String getDataPath() {
return this.dataPath;
public void setDiskInfo(String info) {
diskInfo = info;
}
public void setDataPath(String path) {
dataPath = path;
}
// utility methods for collection
......
......@@ -15,8 +15,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
......@@ -73,6 +71,7 @@ public class DiskWorker extends SwingWorker <Boolean, DiskMark> {
run.numBlocks = App.numOfBlocks;
run.blockSize = App.blockSizeKb;
run.txSize = App.targetTxSizeKb();
run.setDiskInfo(Util.getDiskInfo(dataDir));
if (App.multiFile == false) {
testFile = new File(dataDir.getAbsolutePath()+File.separator+"testdata.jdm");
......@@ -130,10 +129,6 @@ public class DiskWorker extends SwingWorker <Boolean, DiskMark> {
run.endTime = new Date();
}
run.setDataPath(dataDir.getAbsolutePath());
Path dataDirPath = Paths.get(dataDir.getAbsolutePath());
run.setDriveType(Util.getDriveType(dataDirPath.getRoot().toFile()));
EntityManager em = EM.getEntityManager();
em.getTransaction().begin();
em.persist(run);
......@@ -160,6 +155,8 @@ public class DiskWorker extends SwingWorker <Boolean, DiskMark> {
run.numBlocks = App.numOfBlocks;
run.blockSize = App.blockSizeKb;
run.txSize = App.targetTxSizeKb();
run.setDiskInfo(Util.getDiskInfo(dataDir));
for (int m=startFileNum; m<startFileNum+App.numOfMarks && !isCancelled(); m++) {
if (App.multiFile == true) {
......@@ -208,6 +205,12 @@ public class DiskWorker extends SwingWorker <Boolean, DiskMark> {
run.runAvg = rMark.cumAvg;
run.endTime = new Date();
}
EntityManager em = EM.getEntityManager();
em.getTransaction().begin();
em.persist(run);
em.getTransaction().commit();
Gui.runPanel.addRun(run);
}
App.nextMarkNumber += App.numOfMarks;
......
......@@ -45,7 +45,7 @@
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="12" rowCount="0">
<Column editable="false" title="Drive Type" type="java.lang.Object"/>
<Column editable="false" title="Disk Info" type="java.lang.Object"/>
<Column editable="false" title="IO Mode" type="java.lang.Object"/>
<Column editable="false" title="Block Order" type="java.lang.Object"/>
<Column editable="false" title="Marks" type="java.lang.Object"/>
......
......@@ -48,7 +48,7 @@ public class RunPanel extends javax.swing.JPanel {
},
new String [] {
"Drive Type", "IO Mode", "Block Order", "Marks", "Blocks", "B. Size", "Tx Size", "Start Time", "Duration", "Max (MB/s)", "Min (MB/s)", "Avg (MB/s)"
"Disk Info", "IO Mode", "Block Order", "Marks", "Blocks", "B. Size", "Tx Size", "Start Time", "Duration", "Max (MB/s)", "Min (MB/s)", "Avg (MB/s)"
}
) {
boolean[] canEdit = new boolean [] {
......@@ -103,7 +103,7 @@ public class RunPanel extends javax.swing.JPanel {
DefaultTableModel model = (DefaultTableModel) this.runTable.getModel();
model.addRow(
new Object[] {
run.driveType,
run.diskInfo,
run.ioMode,
run.blockOrder,
run.numMarks,
......
package jdiskmark;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Random;
......@@ -119,4 +123,62 @@ public class Util {
FileSystemView fsv = FileSystemView.getFileSystemView();
return fsv.getSystemTypeDescription(file);
}
/**
* Get OS specific disk info based on the drive the path is mapped to.
* @param dataDir the data directory being used in the run.
* @return Disk info if available.
*/
public static String getDiskInfo(File dataDir) {
Path dataDirPath = Paths.get(dataDir.getAbsolutePath());
if (System.getProperty("os.name").contains("Linux")) {
// get disk info for linux
return "implementation pending";
} else if (System.getProperty("os.name").contains("Windows")) {
// get disk info for windows
String driveLetter = dataDirPath.getRoot().toFile().toString().split(":")[0];
return Util.getModelFromLetter(driveLetter);
}
return "unknown";
}
/**
* Get the drive model description based on the windows drive letter.
* Uses the powershell script disk-model.ps1
*
* @param driveLetter The single character drive letter.
* @return Disk Drive Model description or empty string if not found.
*/
public static String getModelFromLetter(String driveLetter) {
try {
Process p = Runtime.getRuntime().exec("powershell -ExecutionPolicy ByPass -File disk-model.ps1");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
String curDriveLetter = null;
String curDiskModel = null;
while (line != null) {
System.out.println(line);
if (line.trim().isEmpty()) {
if (curDriveLetter != null && curDiskModel != null &&
curDriveLetter.equalsIgnoreCase(driveLetter)) {
return curDiskModel;
}
}
if (line.contains("DriveLetter : ")) {
curDriveLetter = line.split(" : ")[1].substring(0, 1);
System.out.println("current letter=" + curDriveLetter);
}
if (line.contains("DiskModel : ")) {
curDiskModel = line.split(" : ")[1];
System.out.println("current model="+curDiskModel);
}
line = reader.readLine();
}
}
catch(IOException | InterruptedException e) {}
return "";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment