21 package org.sleuthkit.autopsy.diagnostics;
24 import java.io.FileNotFoundException;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.security.MessageDigest;
28 import java.security.NoSuchAlgorithmException;
29 import java.util.Arrays;
30 import java.util.Date;
31 import java.util.List;
32 import java.util.Random;
33 import java.util.concurrent.ExecutionException;
34 import javax.swing.JFrame;
35 import javax.swing.SwingUtilities;
36 import javax.swing.SwingWorker;
38 import org.openide.util.NbBundle;
39 import org.openide.windows.WindowManager;
53 super((JFrame) WindowManager.getDefault().getMainWindow(),
54 NbBundle.getMessage(
PerformancePanel.class,
"PerformancePanel.title"),
true);
63 @SuppressWarnings(
"unchecked")
67 jLabel1 =
new javax.swing.JLabel();
69 jLabel2 =
new javax.swing.JLabel();
71 jLabel4 =
new javax.swing.JLabel();
73 jLabel3 =
new javax.swing.JLabel();
77 jLabel5 =
new javax.swing.JLabel();
79 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
81 org.openide.awt.Mnemonics.setLocalizedText(
jLabel1,
org.openide.util.NbBundle.getMessage(
PerformancePanel.class,
"PerformancePanel.jLabel1.text"));
85 org.openide.awt.Mnemonics.setLocalizedText(
jLabel2,
org.openide.util.NbBundle.getMessage(
PerformancePanel.class,
"PerformancePanel.jLabel2.text"));
89 org.openide.awt.Mnemonics.setLocalizedText(
jLabel4,
org.openide.util.NbBundle.getMessage(
PerformancePanel.class,
"PerformancePanel.jLabel4.text"));
93 org.openide.awt.Mnemonics.setLocalizedText(
jLabel3,
org.openide.util.NbBundle.getMessage(
PerformancePanel.class,
"PerformancePanel.jLabel3.text"));
98 startButton.addActionListener(
new java.awt.event.ActionListener() {
99 public void actionPerformed(java.awt.event.ActionEvent evt) {
106 org.openide.awt.Mnemonics.setLocalizedText(
jLabel5,
org.openide.util.NbBundle.getMessage(
PerformancePanel.class,
"PerformancePanel.jLabel5.text"));
108 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
109 getContentPane().setLayout(layout);
110 layout.setHorizontalGroup(
111 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112 .addGroup(layout.createSequentialGroup()
114 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
115 .addGroup(layout.createSequentialGroup()
117 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118 .addGroup(layout.createSequentialGroup()
119 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
124 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
125 .addComponent(
fileReadLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
126 .addComponent(
dbReadLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
127 .addComponent(
cpuTimeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
128 .addComponent(
imgReadLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
129 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
130 .addGroup(layout.createSequentialGroup()
132 .addGap(0, 0, Short.MAX_VALUE))))
133 .addGroup(layout.createSequentialGroup()
134 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
138 .addGroup(layout.createSequentialGroup()
139 .addComponent(
statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE)
140 .addGap(0, 0, Short.MAX_VALUE))))
142 layout.setVerticalGroup(
143 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144 .addGroup(layout.createSequentialGroup()
147 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
148 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
152 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
160 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
176 SwingWorker<?,?> worker =
new PerformanceTestWorker();
196 class PerformanceTestWorker
extends SwingWorker<Void, Void> {
197 private long cpuStats;
198 private long imgReadStats;
199 private long dbStats;
200 private long fileReadStats;
203 protected Void doInBackground()
throws Exception {
207 setFileReadLabel(
"");
217 private void setCpuLabel(
final String msg) {
218 SwingUtilities.invokeLater(
new Runnable() {
226 private void setImgLabel(
final String msg) {
227 SwingUtilities.invokeLater(
new Runnable() {
235 private void setFileReadLabel(
final String msg) {
236 SwingUtilities.invokeLater(
new Runnable() {
244 private void setDbLabel(
final String msg) {
245 SwingUtilities.invokeLater(
new Runnable() {
253 private void setStatusMsg(
final String msg) {
254 SwingUtilities.invokeLater(
new Runnable() {
263 private void doCpuTest() {
264 final String msg = NbBundle.getMessage(this.getClass(),
"PerformancePanel.cpuTest.basemsg");
267 long start =
new Date().getTime();
269 md = MessageDigest.getInstance(
"MD5");
270 }
catch (NoSuchAlgorithmException ex) {
272 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.cpuTest.cpuLabel.md5AlgNotFound.text"));
276 byte[] buf =
new byte[256 * 1024];
278 for (
int a = 0; a < 50; a++) {
280 setStatusMsg(msg +
" " + a * 100 / 50 +
"%");
281 for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
284 bytesRead += buf.length;
289 long end =
new Date().getTime();
290 cpuStats = (bytesRead / (1024 * 1024)) / ((end - start) / 1000);
292 setCpuLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.cpuTest.cpuLabel.MBHashedPerSec.text",
297 private void doImgTest() {
300 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.imgTest.statusMsg.runningImgReadTest.text"));
306 catch (Exception e) {
307 setImgLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.caseNotOpen.text"));
312 List<Content> dataSources;
316 setImgLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.noImgInCase.text"));
321 for (
Content c : dataSources) {
322 if (c instanceof
Image) {
327 setImgLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.noImgInCase.text"));
332 long start =
new Date().getTime();
334 byte[] buf =
new byte[4096];
338 Random rand =
new Random();
339 long curOffset = rand.nextLong();
343 curOffset = curOffset % (image.
getSize() / 2);
344 curOffset = 512 * ((curOffset + 511) / 512);
347 while (bytesRead < 1000 * 1024 * 1024 ) {
350 read = image.
read(buf, curOffset, buf.length);
359 long end =
new Date().getTime();
360 long elapsed = (end - start) / 1000;
362 imgReadStats = (bytesRead / (1024 * 1024)) / elapsed;
365 setImgLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.ImgTest.imgLabel.MBReadPerSec.text",
366 imgReadStats, bytesRead));
370 private void doFileReadTest() {
376 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.FileReadTest.fileReadLabel.skipped.text"));
379 setStatusMsg(NbBundle.getMessage(
this.getClass(),
380 "PerformancePanel.FileReadTest.statusMsg.runningFileReadTest.text"));
386 catch (Exception e) {
388 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.caseNotOpen.text"));
393 List<Content> dataSources;
398 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.noImgInCase.text"));
403 for (
Content c : dataSources) {
404 if (c instanceof
Image) {
410 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.noImgInCase.text"));
415 File file =
new File(image.
getPaths()[0]);
416 if (file.exists() ==
false) {
418 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.fileReadLabel.imgPathNotExist.text"));
423 FileReader fileReader;
425 fileReader =
new FileReader(file);
426 }
catch (FileNotFoundException ex) {
428 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.fileReadLabel.errMakeFileReader.text"));
433 long start =
new Date().getTime();
450 char[] buf =
new char[4096];
452 while (bytesRead < 1000 * 1024 * 1024 ) {
455 read = fileReader.read(buf, 0, buf.length);
456 }
catch (IOException ex) {
463 long end =
new Date().getTime();
464 long elapsed = (end - start) / 1000;
466 fileReadStats = (bytesRead / (1024 * 1024)) / elapsed;
470 NbBundle.getMessage(
this.getClass(),
"PerformancePanel.ImgTest.fileReadLabel.MBReadPerSec.text",
471 fileReadStats, bytesRead));
475 private void doDbTest() {
477 setStatusMsg(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.dbTest.status.running"));
483 catch (Exception e) {
484 setDbLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.label.caseNotOpen.text"));
490 long start =
new Date().getTime();
494 long end =
new Date().getTime();
495 long elapsed = (end - start) / 1000;
497 dbStats = files.size() / elapsed;
501 setDbLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.dbTest.dbLabel.recordsPerSec.text",
504 setDbLabel(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.dbTest.dbLabel.errPerformQuery.text"));
511 protected void done() {
514 }
catch (InterruptedException | ExecutionException ex) {
515 setStatusMsg(NbBundle.getMessage(
this.getClass(),
"PerformancePanel.done.statusMsg.err.text",
List< Content > getDataSources()
int read(byte[] buf, long offset, long len)
SleuthkitCase getSleuthkitCase()
List< AbstractFile > findAllFilesWhere(String sqlWhereClause)
static Case getCurrentCase()