19 package org.sleuthkit.autopsy.diagnostics;
 
   22 import java.io.FileNotFoundException;
 
   23 import java.io.FileReader;
 
   24 import java.io.IOException;
 
   25 import java.security.MessageDigest;
 
   26 import java.security.NoSuchAlgorithmException;
 
   27 import java.util.Arrays;
 
   28 import java.util.Date;
 
   29 import java.util.List;
 
   30 import java.util.Random;
 
   31 import java.util.concurrent.ExecutionException;
 
   32 import javax.swing.JFrame;
 
   33 import javax.swing.SwingUtilities;
 
   34 import javax.swing.SwingWorker;
 
   36 import org.openide.util.NbBundle;
 
   37 import org.openide.windows.WindowManager;
 
   51         super((JFrame) WindowManager.getDefault().getMainWindow(),
 
   52                 NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.title"), 
true);
 
   61     @SuppressWarnings(
"unchecked")
 
   65         jLabel1 = 
new javax.swing.JLabel();
 
   67         jLabel2 = 
new javax.swing.JLabel();
 
   69         jLabel4 = 
new javax.swing.JLabel();
 
   71         jLabel3 = 
new javax.swing.JLabel();
 
   75         jLabel5 = 
new javax.swing.JLabel();
 
   77         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
   79         org.openide.awt.Mnemonics.setLocalizedText(
jLabel1, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel1.text")); 
 
   83         org.openide.awt.Mnemonics.setLocalizedText(
jLabel2, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel2.text")); 
 
   87         org.openide.awt.Mnemonics.setLocalizedText(
jLabel4, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel4.text")); 
 
   91         org.openide.awt.Mnemonics.setLocalizedText(
jLabel3, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel3.text")); 
 
   96         startButton.addActionListener(
new java.awt.event.ActionListener() {
 
   97             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  104         org.openide.awt.Mnemonics.setLocalizedText(
jLabel5, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel5.text")); 
 
  106         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  107         getContentPane().setLayout(layout);
 
  108         layout.setHorizontalGroup(
 
  109             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  110             .addGroup(layout.createSequentialGroup()
 
  112                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  113                     .addGroup(layout.createSequentialGroup()
 
  115                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  116                             .addGroup(layout.createSequentialGroup()
 
  117                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  122                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  123                                     .addComponent(
fileReadLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  124                                     .addComponent(
dbReadLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  125                                     .addComponent(
cpuTimeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  126                                     .addComponent(
imgReadLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
 
  127                                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  128                             .addGroup(layout.createSequentialGroup()
 
  130                                 .addGap(0, 0, Short.MAX_VALUE))))
 
  131                     .addGroup(layout.createSequentialGroup()
 
  132                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  135                         .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  136                     .addGroup(layout.createSequentialGroup()
 
  137                         .addComponent(
statusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 508, javax.swing.GroupLayout.PREFERRED_SIZE)
 
  138                         .addGap(0, 0, Short.MAX_VALUE))))
 
  140         layout.setVerticalGroup(
 
  141             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  142             .addGroup(layout.createSequentialGroup()
 
  145                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
  146                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  150                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  154                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  158                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  165                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  174         SwingWorker<?, ?> worker = 
new PerformanceTestWorker();
 
  193     class PerformanceTestWorker 
extends SwingWorker<Void, Void> {
 
  195         private long cpuStats;
 
  196         private long imgReadStats;
 
  197         private long dbStats;
 
  198         private long fileReadStats;
 
  201         protected Void doInBackground() 
throws Exception {
 
  205             setFileReadLabel(
"");
 
  215         private void setCpuLabel(
final String msg) {
 
  216             SwingUtilities.invokeLater(
new Runnable() {
 
  224         private void setImgLabel(
final String msg) {
 
  225             SwingUtilities.invokeLater(
new Runnable() {
 
  233         private void setFileReadLabel(
final String msg) {
 
  234             SwingUtilities.invokeLater(
new Runnable() {
 
  242         private void setDbLabel(
final String msg) {
 
  243             SwingUtilities.invokeLater(
new Runnable() {
 
  251         private void setStatusMsg(
final String msg) {
 
  252             SwingUtilities.invokeLater(
new Runnable() {
 
  260         private void doCpuTest() {
 
  261             final String msg = NbBundle.getMessage(this.getClass(), 
"PerformancePanel.cpuTest.basemsg");
 
  264             long start = 
new Date().getTime();
 
  266                 md = MessageDigest.getInstance(
"MD5"); 
 
  267             } 
catch (NoSuchAlgorithmException ex) {
 
  269                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.cpuTest.cpuLabel.md5AlgNotFound.text"));
 
  273             byte[] buf = 
new byte[256 * 1024];
 
  275             for (
int a = 0; a < 50; a++) {
 
  277                     setStatusMsg(msg + 
" " + a * 100 / 50 + 
"%");
 
  279                 for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
 
  282                     bytesRead += buf.length;
 
  287             long end = 
new Date().getTime();
 
  288             cpuStats = (bytesRead / (1024 * 1024)) / ((end - start) / 1000);
 
  290             setCpuLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.cpuTest.cpuLabel.MBHashedPerSec.text",
 
  295         private void doImgTest() {
 
  298                     NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.imgTest.statusMsg.runningImgReadTest.text"));
 
  303             } 
catch (Exception e) {
 
  304                 setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.caseNotOpen.text"));
 
  309             List<Content> dataSources;
 
  312             } 
catch (TskCoreException ex) {
 
  313                 setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  318             for (Content c : dataSources) {
 
  319                 if (c instanceof Image) {
 
  324                 setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  329             long start = 
new Date().getTime();
 
  331             byte[] buf = 
new byte[4096];
 
  335             Random rand = 
new Random();
 
  336             long curOffset = rand.nextLong();
 
  340             curOffset = curOffset % (image.getSize() / 2);
 
  341             curOffset = 512 * ((curOffset + 511) / 512);
 
  344             while (bytesRead < 1000 * 1024 * 1024) {
 
  347                     read = image.read(buf, curOffset, buf.length);
 
  348                 } 
catch (TskCoreException ex) {
 
  357             long end = 
new Date().getTime();
 
  358             long elapsed = (end - start) / 1000;
 
  360                 imgReadStats = (bytesRead / (1024 * 1024)) / elapsed;
 
  364             setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.ImgTest.imgLabel.MBReadPerSec.text",
 
  365                     imgReadStats, bytesRead));
 
  369         private void doFileReadTest() {
 
  375                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.FileReadTest.fileReadLabel.skipped.text"));
 
  378             setStatusMsg(NbBundle.getMessage(
this.getClass(),
 
  379                     "PerformancePanel.FileReadTest.statusMsg.runningFileReadTest.text"));
 
  384             } 
catch (Exception e) {
 
  386                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.caseNotOpen.text"));
 
  391             List<Content> dataSources;
 
  394             } 
catch (TskCoreException ex) {
 
  396                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  401             for (Content c : dataSources) {
 
  402                 if (c instanceof Image) {
 
  408                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  413             File file = 
new File(image.getPaths()[0]);
 
  414             if (file.exists() == 
false) {
 
  416                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.fileReadLabel.imgPathNotExist.text"));
 
  421             FileReader fileReader;
 
  423                 fileReader = 
new FileReader(file);
 
  424             } 
catch (FileNotFoundException ex) {
 
  426                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.fileReadLabel.errMakeFileReader.text"));
 
  431             long start = 
new Date().getTime();
 
  442             char[] buf = 
new char[4096];
 
  444             while (bytesRead < 1000 * 1024 * 1024) {
 
  447                     read = fileReader.read(buf, 0, buf.length);
 
  448                 } 
catch (IOException ex) {
 
  456             long end = 
new Date().getTime();
 
  457             long elapsed = (end - start) / 1000;
 
  459                 fileReadStats = (bytesRead / (1024 * 1024)) / elapsed;
 
  464                     NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.ImgTest.fileReadLabel.MBReadPerSec.text",
 
  465                             fileReadStats, bytesRead));
 
  469         private void doDbTest() {
 
  471             setStatusMsg(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.dbTest.status.running"));
 
  476             } 
catch (Exception e) {
 
  477                 setDbLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.caseNotOpen.text"));
 
  483                 long start = 
new Date().getTime();
 
  485                 List<AbstractFile> files = tskCase.findAllFilesWhere(
"obj_id < 50000"); 
 
  487                 long end = 
new Date().getTime();
 
  488                 long elapsed = (end - start) / 1000;
 
  490                     dbStats = files.size() / elapsed;
 
  495                 setDbLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.dbTest.dbLabel.recordsPerSec.text",
 
  497             } 
catch (TskCoreException ex) {
 
  498                 setDbLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.dbTest.dbLabel.errPerformQuery.text"));
 
  505         protected void done() {
 
  508             } 
catch (InterruptedException | ExecutionException ex) {
 
  509                 setStatusMsg(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.done.statusMsg.err.text",
 
List< Content > getDataSources()
SleuthkitCase getSleuthkitCase()
static Case getCurrentCase()