diff --git a/logo.jpg b/logo.jpg new file mode 100644 index 0000000..ba5bc4f Binary files /dev/null and b/logo.jpg differ diff --git a/src/etl_to_csv/ExportCSV.form b/src/etl_to_csv/ExportCSV.form index 17da2b5..ef25999 100644 --- a/src/etl_to_csv/ExportCSV.form +++ b/src/etl_to_csv/ExportCSV.form @@ -7,7 +7,8 @@ - + + @@ -36,17 +37,20 @@ - - - - - + + + + + + + + - - + + @@ -61,7 +65,10 @@ - + + + + @@ -107,8 +114,8 @@ - - + + @@ -120,7 +127,7 @@ - + @@ -142,6 +149,9 @@ + + + @@ -151,14 +161,6 @@ - - - - - - - - @@ -211,6 +213,14 @@ + + + + + + + + @@ -222,19 +232,36 @@ + + + - +
+ + +
+ + + + + + + + + + + diff --git a/src/etl_to_csv/ExportCSV.java b/src/etl_to_csv/ExportCSV.java index ee3a5f8..492aaff 100644 --- a/src/etl_to_csv/ExportCSV.java +++ b/src/etl_to_csv/ExportCSV.java @@ -5,18 +5,29 @@ */ package etl_to_csv; +import java.awt.Color; +import java.awt.Component; +import java.awt.Desktop; +import java.awt.Font; +import java.awt.Image; +import java.awt.Toolkit; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.util.List; import java.util.concurrent.TimeUnit; +import javax.swing.ImageIcon; import javax.swing.JFileChooser; import javax.swing.JOptionPane; +import javax.swing.SwingWorker; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; /** * * @author Pubudu */ + public class ExportCSV extends javax.swing.JFrame { private String m_RootFolderPath = null; @@ -26,9 +37,13 @@ public class ExportCSV extends javax.swing.JFrame { private File[] m_ListOfFiles; + private int m_CurrentRow = -1; + private boolean m_RadioButtonSelectedFlag = false; + public ExportCSV() { initComponents(); - jLabelProcessing.setVisible(true); + Image icon = Toolkit.getDefaultToolkit().getImage("logo.jpg"); + this.setIconImage(icon); } private void RemoveTableRows( DefaultTableModel myTableModel ) @@ -40,7 +55,41 @@ private void RemoveTableRows( DefaultTableModel myTableModel ) } } } + + private void ShowExportedProfileNumber() + { + jLabelProcessedAmount.setText("Processed: " + (m_CurrentRow + 1) + " out of " + m_ListOfFiles.length); + } + + private void PopulateTableWithETLFiles() + { + File folder = new File( m_RootFolderPath ); + + FileFilter fileFilter = file -> !file.isDirectory() && file.getName().endsWith(".etl"); + + m_ListOfFiles = folder.listFiles( fileFilter ); + + DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel(); + RemoveTableRows( dtm ); + for( int i = 0; i < m_ListOfFiles.length; i++ ) + { + if( m_ListOfFiles[i].isFile() ) + { + dtm.addRow( new Object[]{ m_ListOfFiles[i].getName() } ); + } + else + { + JOptionPane.showMessageDialog( null, "Something Went Wrong!" ); + } + } + + if( m_ListOfFiles.length == 0 ) + { + JOptionPane.showMessageDialog( null, "No ETL file detected" ); + } + } + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -56,24 +105,42 @@ private void initComponents() { jLabel2 = new javax.swing.JLabel(); txtETLPath = new javax.swing.JTextField(); btnBrowse = new javax.swing.JButton(); - btnReadFileNames = new javax.swing.JButton(); jRadioButtonCPU = new javax.swing.JRadioButton(); jRadioButtonGPU = new javax.swing.JRadioButton(); jRadioButtonMemory = new javax.swing.JRadioButton(); jRadioButtonStorage = new javax.swing.JRadioButton(); btnExtractCSV = new javax.swing.JButton(); + btnOpenFileLocation = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); - jTable1 = new javax.swing.JTable(); + jTable1 = new javax.swing.JTable() + { + public Component prepareRenderer(TableCellRenderer renderer, int row, int column) + { + Component c = super.prepareRenderer(renderer, row, column); + + if (isRowSelected(row)) + c.setBackground(Color.GREEN); + else + c.setBackground(Color.WHITE); + + return c; + } + + }; jLabelProcessing = new javax.swing.JLabel(); + jLabelProcessedAmount = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setTitle("ETL to CSV Exporter"); + setTitle("ETL to CSV Exporter (UNO Network Lab)"); + setResizable(false); jLabel1.setFont(new java.awt.Font("Tahoma", 3, 12)); // NOI18N jLabel1.setText("Export ETL Traces as CSV"); jLabel2.setText("Path to ETL files:"); + txtETLPath.setEditable(false); + btnBrowse.setText("Browse"); btnBrowse.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -81,13 +148,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); - btnReadFileNames.setText("Get Files"); - btnReadFileNames.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnReadFileNamesActionPerformed(evt); - } - }); - buttonGroup1.add(jRadioButtonCPU); jRadioButtonCPU.setText("CPU"); jRadioButtonCPU.addActionListener(new java.awt.event.ActionListener() { @@ -127,6 +187,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + btnOpenFileLocation.setText("Open Location"); + btnOpenFileLocation.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnOpenFileLocationActionPerformed(evt); + } + }); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -151,8 +218,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(btnBrowse, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnExtractCSV, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)) .addGap(34, 34, 34) - .addComponent(btnReadFileNames, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(78, Short.MAX_VALUE)) + .addComponent(btnOpenFileLocation, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(41, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -162,7 +229,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(jLabel2) .addComponent(txtETLPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBrowse) - .addComponent(btnReadFileNames)) + .addComponent(btnOpenFileLocation)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jRadioButtonCPU) @@ -173,6 +240,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addContainerGap()) ); + jTable1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { @@ -180,11 +248,23 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { new String [] { "File Name" } - )); + ) { + boolean[] canEdit = new boolean [] { + false + }; + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); jScrollPane1.setViewportView(jTable1); + jLabelProcessing.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N jLabelProcessing.setText("Processing: Nothing....."); + jLabelProcessedAmount.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N + jLabelProcessedAmount.setText("Processed: None"); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( @@ -194,15 +274,17 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGroup(layout.createSequentialGroup() .addGap(320, 320, 320) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createSequentialGroup() - .addGap(50, 50, 50) - .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(66, 66, 66) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 716, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabelProcessing, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(35, 35, 35) + .addComponent(jLabelProcessedAmount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 716, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup() - .addGap(223, 223, 223) - .addComponent(jLabelProcessing, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGap(50, 50, 50) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( @@ -213,7 +295,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addGap(18, 18, 18) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE) - .addComponent(jLabelProcessing) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabelProcessing) + .addComponent(jLabelProcessedAmount)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) @@ -239,94 +323,57 @@ private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR } }//GEN-LAST:event_btnBrowseActionPerformed - private void btnReadFileNamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReadFileNamesActionPerformed - File folder = new File( m_RootFolderPath ); - - FileFilter fileFilter = file -> !file.isDirectory() && file.getName().endsWith(".etl"); - - m_ListOfFiles = folder.listFiles( fileFilter ); - - DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel(); - RemoveTableRows( dtm ); - - for( int i = 0; i < m_ListOfFiles.length; i++ ) - { - if( m_ListOfFiles[i].isFile() ) - { - dtm.addRow( new Object[]{ m_ListOfFiles[i].getName() } ); - } - else - { - JOptionPane.showMessageDialog( null, "Something Went Wrong!" ); - } - } - - if( m_ListOfFiles.length == 0 ) - { - JOptionPane.showMessageDialog( null, "No ETL file detected" ); - } - }//GEN-LAST:event_btnReadFileNamesActionPerformed - private void jRadioButtonCPUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonCPUActionPerformed m_ProfileDirectory = "CPU_Profile"; - m_WPRProfile = System.getProperty("user.dir") + "\\wprProfiles\\CPUProfile.wpaProfile"; - System.out.println(m_WPRProfile); + m_WPRProfile = m_ProfilePath + "CPUProfile.wpaProfile"; + m_RadioButtonSelectedFlag = true; }//GEN-LAST:event_jRadioButtonCPUActionPerformed private void jRadioButtonGPUActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonGPUActionPerformed m_ProfileDirectory = "GPU_Profile"; + m_WPRProfile = m_ProfilePath + "GPUProfile.wpaProfile"; + m_RadioButtonSelectedFlag = true; }//GEN-LAST:event_jRadioButtonGPUActionPerformed private void jRadioButtonMemoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMemoryActionPerformed m_ProfileDirectory = "Memory_Profile"; + m_WPRProfile = m_ProfilePath + "MemoryProfile.wpaProfile"; + m_RadioButtonSelectedFlag = true; }//GEN-LAST:event_jRadioButtonMemoryActionPerformed private void jRadioButtonStorageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonStorageActionPerformed m_ProfileDirectory = "Storage_Profile"; + m_WPRProfile = m_ProfilePath + "StorageProfile.wpaProfile"; + m_RadioButtonSelectedFlag = true; }//GEN-LAST:event_jRadioButtonStorageActionPerformed private void btnExtractCSVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExtractCSVActionPerformed - - File profileDirectory = new File( m_RootFolderPath + m_ProfileDirectory ); - - String outputFolder = m_RootFolderPath + m_ProfileDirectory + "\\"; - - if( profileDirectory.exists() == false ) - { - profileDirectory.mkdirs(); - } - - for( int i = 0; i < m_ListOfFiles.length; i++ ) - { - String fileName = m_ListOfFiles[i].getName(); - String command = "wpaexporter " + fileName + " -profile " + m_WPRProfile + " -outputfolder " + outputFolder + " -prefix " + fileName; - System.out.println(command); - ProcessBuilder builder = new ProcessBuilder( "cmd.exe", "/c", command ); - builder = builder.directory( new File( m_RootFolderPath ) ); - - try + PopulateTableWithETLFiles(); + runBackgroundTask(); + }//GEN-LAST:event_btnExtractCSVActionPerformed + + private void btnOpenFileLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOpenFileLocationActionPerformed + try + { + if( txtETLPath.getText().isEmpty()) { - builder.redirectErrorStream(true); - Process process = builder.start(); - jLabelProcessing.setText("Processing " + fileName ); - jLabelProcessing.setVisible(true); - - process.waitFor(300, TimeUnit.SECONDS); - process.destroyForcibly(); - process.waitFor(); - - } - catch (IOException ex) - { - JOptionPane.showMessageDialog(null, "Failed to run cmd command "+ex); - } - catch (InterruptedException ex) + JOptionPane.showMessageDialog( null, "Please enter a valid path to textfield."); + return; + } + + if( m_RadioButtonSelectedFlag == false ) { - JOptionPane.showMessageDialog(null, "Command Line Thread "+ex); - } + JOptionPane.showMessageDialog( null, "Please check one of the radio buttons."); + return; + } + + Desktop.getDesktop().open( new File( m_RootFolderPath + m_ProfileDirectory ) ); + } + catch (IOException ex) + { + JOptionPane.showMessageDialog( null, "Unable to Open File Location " + ex ); } - }//GEN-LAST:event_btnExtractCSVActionPerformed - + }//GEN-LAST:event_btnOpenFileLocationActionPerformed /** * @param args the command line arguments */ @@ -365,10 +412,11 @@ public void run() { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBrowse; private javax.swing.JButton btnExtractCSV; - private javax.swing.JButton btnReadFileNames; + private javax.swing.JButton btnOpenFileLocation; private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabelProcessedAmount; private javax.swing.JLabel jLabelProcessing; private javax.swing.JPanel jPanel1; private javax.swing.JRadioButton jRadioButtonCPU; @@ -379,4 +427,75 @@ public void run() { private javax.swing.JTable jTable1; private javax.swing.JTextField txtETLPath; // End of variables declaration//GEN-END:variables +private void runBackgroundTask() +{ + new SwingWorker() + { + + // Called on background thread + protected Void doInBackground() throws Exception + { + + File profileDirectory = new File( m_RootFolderPath + m_ProfileDirectory ); + + String outputFolder = m_RootFolderPath + m_ProfileDirectory + "\\"; + + if( profileDirectory.exists() == false ) + { + profileDirectory.mkdirs(); + } + + for( int i = 0; i < m_ListOfFiles.length; i++ ) + { + String fileName = m_ListOfFiles[i].getName(); + String command = "wpaexporter " + fileName + " -profile " + m_WPRProfile + " -outputfolder " + outputFolder + " -prefix " + fileName; + System.out.println(command); + ProcessBuilder builder = new ProcessBuilder( "cmd.exe", "/c", command ); + builder = builder.directory( new File( m_RootFolderPath ) ); + publish(i); + try + { + builder.redirectErrorStream(true); + Process process = builder.start(); + jLabelProcessing.setForeground(Color.magenta); + jLabelProcessing.setText("Processing: " + fileName ); + + process.waitFor(300, TimeUnit.SECONDS); + process.destroyForcibly(); + process.waitFor(); + + } + catch (IOException ex) + { + JOptionPane.showMessageDialog(null, "Failed to run cmd command "+ex); + } + catch (InterruptedException ex) + { + JOptionPane.showMessageDialog(null, "Command Line Thread "+ex); + } + } + return null; + } + + protected void process(List chunks) + { + for( int number : chunks ) + { + m_CurrentRow = number; + System.out.println(m_CurrentRow); + ShowExportedProfileNumber(); + jTable1.setRowSelectionInterval(0, number); + } + } + + protected void done() + { + Font font = new Font("Tahoma", Font.BOLD,11); + jLabelProcessing.setFont(font); + jLabelProcessing.setForeground(Color.GREEN); + jLabelProcessing.setText("Processing: Done" ); + } + }.execute(); +} + } diff --git a/wprProfiles/GPUProfile.wpaProfile b/wprProfiles/GPUProfile.wpaProfile new file mode 100644 index 0000000..7544d32 --- /dev/null +++ b/wprProfiles/GPUProfile.wpaProfile @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + \ No newline at end of file diff --git a/wprProfiles/MemoryProfile.wpaProfile b/wprProfiles/MemoryProfile.wpaProfile new file mode 100644 index 0000000..bd39ede --- /dev/null +++ b/wprProfiles/MemoryProfile.wpaProfile @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/wprProfiles/StorageProfile.wpaProfile b/wprProfiles/StorageProfile.wpaProfile new file mode 100644 index 0000000..68b72af --- /dev/null +++ b/wprProfiles/StorageProfile.wpaProfile @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + \ No newline at end of file