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;
 
   48 @SuppressWarnings(
"PMD.SingularField") 
 
   55         super((JFrame) WindowManager.getDefault().getMainWindow(),
 
   56                 NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.title"), 
true);
 
   65     @SuppressWarnings(
"unchecked")
 
   67     private 
void initComponents() {
 
   69         jLabel1 = 
new javax.swing.JLabel();
 
   70         imgReadLabel = 
new javax.swing.JLabel();
 
   71         jLabel2 = 
new javax.swing.JLabel();
 
   72         dbReadLabel = 
new javax.swing.JLabel();
 
   73         jLabel4 = 
new javax.swing.JLabel();
 
   74         fileReadLabel = 
new javax.swing.JLabel();
 
   75         jLabel3 = 
new javax.swing.JLabel();
 
   76         cpuTimeLabel = 
new javax.swing.JLabel();
 
   77         startButton = 
new javax.swing.JButton();
 
   78         statusLabel = 
new javax.swing.JLabel();
 
   79         jLabel5 = 
new javax.swing.JLabel();
 
   81         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 
   83         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel1.text")); 
 
   85         org.openide.awt.Mnemonics.setLocalizedText(imgReadLabel, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.imgReadLabel.text")); 
 
   87         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel2.text")); 
 
   89         org.openide.awt.Mnemonics.setLocalizedText(dbReadLabel, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.dbReadLabel.text")); 
 
   91         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel4.text")); 
 
   93         org.openide.awt.Mnemonics.setLocalizedText(fileReadLabel, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.fileReadLabel.text")); 
 
   95         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel3.text")); 
 
   97         org.openide.awt.Mnemonics.setLocalizedText(cpuTimeLabel, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.cpuTimeLabel.text")); 
 
   99         org.openide.awt.Mnemonics.setLocalizedText(startButton, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.startButton.text")); 
 
  100         startButton.addActionListener(
new java.awt.event.ActionListener() {
 
  101             public void actionPerformed(java.awt.event.ActionEvent evt) {
 
  102                 startButtonActionPerformed(evt);
 
  106         org.openide.awt.Mnemonics.setLocalizedText(statusLabel, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.statusLabel.text")); 
 
  108         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, 
org.openide.util.NbBundle.getMessage(
PerformancePanel.class, 
"PerformancePanel.jLabel5.text")); 
 
  110         javax.swing.GroupLayout layout = 
new javax.swing.GroupLayout(getContentPane());
 
  111         getContentPane().setLayout(layout);
 
  112         layout.setHorizontalGroup(
 
  113             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  114             .addGroup(layout.createSequentialGroup()
 
  116                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  117                     .addGroup(layout.createSequentialGroup()
 
  119                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  120                             .addGroup(layout.createSequentialGroup()
 
  121                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  122                                     .addComponent(jLabel1)
 
  123                                     .addComponent(jLabel2)
 
  124                                     .addComponent(jLabel3))
 
  126                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  127                                     .addComponent(fileReadLabel)
 
  128                                     .addComponent(dbReadLabel)
 
  129                                     .addComponent(cpuTimeLabel)
 
  130                                     .addComponent(imgReadLabel))
 
  131                                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  132                             .addGroup(layout.createSequentialGroup()
 
  133                                 .addComponent(jLabel4)
 
  134                                 .addGap(0, 0, Short.MAX_VALUE))))
 
  135                     .addGroup(layout.createSequentialGroup()
 
  136                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  137                             .addComponent(startButton)
 
  138                             .addComponent(jLabel5))
 
  139                         .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  140                     .addGroup(layout.createSequentialGroup()
 
  141                         .addComponent(statusLabel)
 
  142                         .addGap(0, 0, Short.MAX_VALUE))))
 
  144         layout.setVerticalGroup(
 
  145             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  146             .addGroup(layout.createSequentialGroup()
 
  148                 .addComponent(jLabel5)
 
  149                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 
  150                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  151                     .addComponent(jLabel3)
 
  152                     .addComponent(cpuTimeLabel))
 
  154                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 
  155                     .addComponent(imgReadLabel)
 
  156                     .addComponent(jLabel1))
 
  158                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  159                     .addComponent(jLabel4)
 
  160                     .addComponent(fileReadLabel))
 
  162                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 
  163                     .addComponent(jLabel2)
 
  164                     .addComponent(dbReadLabel))
 
  166                 .addComponent(statusLabel)
 
  168                 .addComponent(startButton)
 
  169                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 
  177         startButton.setEnabled(
false);
 
  178         SwingWorker<?, ?> worker = 
new PerformanceTestWorker();
 
  197     class PerformanceTestWorker 
extends SwingWorker<Void, Void> {
 
  199         private long cpuStats;
 
  200         private long imgReadStats;
 
  201         private long dbStats;
 
  202         private long fileReadStats;
 
  205         protected Void doInBackground() 
throws Exception {
 
  209             setFileReadLabel(
"");
 
  219         private void setCpuLabel(
final String msg) {
 
  220             SwingUtilities.invokeLater(
new Runnable() {
 
  223                     cpuTimeLabel.setText(msg);
 
  228         private void setImgLabel(
final String msg) {
 
  229             SwingUtilities.invokeLater(
new Runnable() {
 
  232                     imgReadLabel.setText(msg);
 
  237         private void setFileReadLabel(
final String msg) {
 
  238             SwingUtilities.invokeLater(
new Runnable() {
 
  241                     fileReadLabel.setText(msg);
 
  246         private void setDbLabel(
final String msg) {
 
  247             SwingUtilities.invokeLater(
new Runnable() {
 
  250                     dbReadLabel.setText(msg);
 
  255         private void setStatusMsg(
final String msg) {
 
  256             SwingUtilities.invokeLater(
new Runnable() {
 
  259                     statusLabel.setText(msg);
 
  264         private void doCpuTest() {
 
  265             final String msg = NbBundle.getMessage(this.getClass(), 
"PerformancePanel.cpuTest.basemsg");
 
  268             long start = 
new Date().getTime();
 
  270                 md = MessageDigest.getInstance(
"MD5"); 
 
  271             } 
catch (NoSuchAlgorithmException ex) {
 
  273                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.cpuTest.cpuLabel.md5AlgNotFound.text"));
 
  277             byte[] buf = 
new byte[256 * 1024];
 
  279             for (
int a = 0; a < 50; a++) {
 
  281                     setStatusMsg(msg + 
" " + a * 100 / 50 + 
"%");
 
  283                 for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
 
  286                     bytesRead += buf.length;
 
  291             long end = 
new Date().getTime();
 
  292             cpuStats = (bytesRead / (1024 * 1024)) / ((end - start) / 1000);
 
  294             setCpuLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.cpuTest.cpuLabel.MBHashedPerSec.text",
 
  299         private void doImgTest() {
 
  302                     NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.imgTest.statusMsg.runningImgReadTest.text"));
 
  307             } 
catch (Exception e) {
 
  308                 setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.caseNotOpen.text"));
 
  313             List<Content> dataSources;
 
  316             } 
catch (TskCoreException ex) {
 
  317                 setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  322             for (Content c : dataSources) {
 
  323                 if (c instanceof Image) {
 
  328                 setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  333             long start = 
new Date().getTime();
 
  335             byte[] buf = 
new byte[4096];
 
  339             Random rand = 
new Random();
 
  340             long curOffset = rand.nextLong();
 
  344             curOffset = curOffset % (image.getSize() / 2);
 
  345             curOffset = 512 * ((curOffset + 511) / 512);
 
  348             while (bytesRead < 1000 * 1024 * 1024) {
 
  351                     read = image.read(buf, curOffset, buf.length);
 
  352                 } 
catch (TskCoreException ex) {
 
  361             long end = 
new Date().getTime();
 
  362             long elapsed = (end - start) / 1000;
 
  364                 imgReadStats = (bytesRead / (1024 * 1024)) / elapsed;
 
  368             setImgLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.ImgTest.imgLabel.MBReadPerSec.text",
 
  369                     imgReadStats, bytesRead));
 
  373         private void doFileReadTest() {
 
  379                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.FileReadTest.fileReadLabel.skipped.text"));
 
  382             setStatusMsg(NbBundle.getMessage(
this.getClass(),
 
  383                     "PerformancePanel.FileReadTest.statusMsg.runningFileReadTest.text"));
 
  388             } 
catch (Exception e) {
 
  390                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.caseNotOpen.text"));
 
  395             List<Content> dataSources;
 
  398             } 
catch (TskCoreException ex) {
 
  400                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  405             for (Content c : dataSources) {
 
  406                 if (c instanceof Image) {
 
  412                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.noImgInCase.text"));
 
  417             File file = 
new File(image.getPaths()[0]);
 
  418             if (file.exists() == 
false) {
 
  420                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.fileReadLabel.imgPathNotExist.text"));
 
  425             FileReader fileReader;
 
  427                 fileReader = 
new FileReader(file);
 
  428             } 
catch (FileNotFoundException ex) {
 
  430                         NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.fileReadLabel.errMakeFileReader.text"));
 
  435             long start = 
new Date().getTime();
 
  446             char[] buf = 
new char[4096];
 
  448             while (bytesRead < 1000 * 1024 * 1024) {
 
  451                     read = fileReader.read(buf, 0, buf.length);
 
  452                 } 
catch (IOException ex) {
 
  460             long end = 
new Date().getTime();
 
  461             long elapsed = (end - start) / 1000;
 
  463                 fileReadStats = (bytesRead / (1024 * 1024)) / elapsed;
 
  468                     NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.ImgTest.fileReadLabel.MBReadPerSec.text",
 
  469                             fileReadStats, bytesRead));
 
  473         private void doDbTest() {
 
  475             setStatusMsg(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.dbTest.status.running"));
 
  480             } 
catch (Exception e) {
 
  481                 setDbLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.label.caseNotOpen.text"));
 
  487                 long start = 
new Date().getTime();
 
  489                 List<AbstractFile> files = tskCase.findAllFilesWhere(
"obj_id < 50000"); 
 
  491                 long end = 
new Date().getTime();
 
  492                 long elapsed = (end - start) / 1000;
 
  494                     dbStats = files.size() / elapsed;
 
  499                 setDbLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.dbTest.dbLabel.recordsPerSec.text",
 
  501             } 
catch (TskCoreException ex) {
 
  502                 setDbLabel(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.dbTest.dbLabel.errPerformQuery.text"));
 
  509         protected void done() {
 
  512             } 
catch (InterruptedException | ExecutionException ex) {
 
  513                 setStatusMsg(NbBundle.getMessage(
this.getClass(), 
"PerformancePanel.done.statusMsg.err.text",
 
  516             startButton.setEnabled(
true);
 
List< Content > getDataSources()
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()