ctf: Generate synthetic trace in test traces folder instead of temp dir
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 12 Dec 2013 06:26:53 +0000 (01:26 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 12 Dec 2013 19:58:56 +0000 (14:58 -0500)
I was having problems with the synthetic trace now that the Luna branch
is merged into master because the index files got generated into the
synthetic trace folder and the folder would not get deleted on exit
because of that. Then the next test run, the trace would not get
generated because the folder already exists. I think it makes sense to
move the trace to the test traces folder and only generate it once.

Change-Id: I03e815c50e22adf2d5355856b8031cc7a8b4c9b1
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/19680
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
org.eclipse.linuxtools.ctf.core.tests/pom.xml
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/synthetictraces/LttngKernelTraceGenerator.java
org.eclipse.linuxtools.ctf.core.tests/traces/.gitignore

index 51ebba5192fd7dbb2c39bcd46ab73fdb5b058ed8..0309c9354912500842aeec25af061ccf4576cf9c 100644 (file)
@@ -94,6 +94,7 @@
                 <fileset><directory>traces/kernel</directory></fileset>
                 <fileset><directory>traces/kernel_vm</directory></fileset>
                 <fileset><directory>traces/synctraces</directory></fileset>
+                <fileset><directory>traces/synthetic-trace</directory></fileset>
                 <fileset><directory>traces/trace2</directory></fileset>
               </filesets>
             </configuration>
index d3599b3ef3151d1ebc40a0b7986fc118338e2a08..cdef752359e9a5744f5d241e5013e78dcfd964a8 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Matthew Khouzam - Initial API and implementation
+ *   Marc-Andre Laperle - Move generation to traces folder
  *******************************************************************************/
 
 package org.eclipse.linuxtools.ctf.core.tests.synthetictraces;
@@ -16,6 +17,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.channels.FileChannel;
@@ -23,6 +25,11 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
 
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.ctf.core.tests.CtfCoreTestPlugin;
+
 /**
  * Generate a kernel trace
  *
@@ -148,7 +155,6 @@ public class LttngKernelTraceGenerator {
     private final long fDuration;
     private final long fNbEvents;
     private final int fNbChans;
-    private File fPath;
 
     private static final String[] sfProcesses = {
             "IDLE",
@@ -163,9 +169,8 @@ public class LttngKernelTraceGenerator {
     };
 
 
-    private static final String DIRECTORY_NAME = "synthetic-trace";
-    // not using createTempFile as this is a directory
-    private static final String PATH = System.getProperty("java.io.tmpdir") + File.separator + DIRECTORY_NAME;
+    private static final String TRACES_DIRECTORY = "traces";
+    private static final String TRACE_NAME = "synthetic-trace";
 
     /**
      * Main, not always needed
@@ -174,7 +179,9 @@ public class LttngKernelTraceGenerator {
      *            args
      */
     public static void main(String[] args) {
-        generateLttngKernelTrace();
+        // not using createTempFile as this is a directory
+        String path = System.getProperty("java.io.tmpdir") + File.separator + TRACE_NAME;
+        generateLttngKernelTrace(new File(path));
     }
 
     /**
@@ -183,7 +190,7 @@ public class LttngKernelTraceGenerator {
      * @return the name of the trace
      */
     public static String getName() {
-        return DIRECTORY_NAME;
+        return TRACE_NAME;
     }
 
     /**
@@ -192,20 +199,32 @@ public class LttngKernelTraceGenerator {
      * @return the path
      */
     public static String getPath() {
-        final File file = new File(PATH);
+        URL location = FileLocator.find(CtfCoreTestPlugin.getDefault().getBundle(), new Path(TRACES_DIRECTORY), null);
+        File file = null;
+        try {
+            IPath path = new Path(FileLocator.toFileURL(location).getPath()).append(TRACE_NAME);
+            file = path.toFile();
+        } catch (IOException e) {
+            // Shouldn't happen but at least throw something to get the test to fail early
+            throw new IllegalStateException();
+        }
+
         if (!file.exists()) {
-            generateLttngKernelTrace();
+            generateLttngKernelTrace(file);
         }
         return file.getAbsolutePath();
     }
 
     /**
      * Generate a trace
+     *
+     * @param file
+     *            the file to write the trace to
      */
-    public static void generateLttngKernelTrace() {
+    public static void generateLttngKernelTrace(File file) {
         final int cpus = 25;
         LttngKernelTraceGenerator gt = new LttngKernelTraceGenerator(2l * Integer.MAX_VALUE - 100, 500000, cpus);
-        gt.writeTrace(PATH);
+        gt.writeTrace(file);
     }
 
     /**
@@ -228,39 +247,35 @@ public class LttngKernelTraceGenerator {
     /**
      * Write the trace to a file
      *
-     * @param path
-     *            the path to write the trace to
+     * @param file
+     *            the file to write the trace to
      */
-    public void writeTrace(String path) {
-        fPath = new File(path);
+    public void writeTrace(File file) {
 
-        if (!fPath.exists()) {
-            fPath.mkdir();
+        if (!file.exists()) {
+            file.mkdir();
         } else {
-            if (fPath.isFile()) {
-                fPath.delete();
-                fPath.mkdir();
+            if (file.isFile()) {
+                file.delete();
+                file.mkdir();
             } else {
                 // the ctf parser doesn't recurse, so we don't need to.
-                final File[] listFiles = fPath.listFiles();
+                final File[] listFiles = file.listFiles();
                 for (File child : listFiles) {
                     child.delete();
                 }
             }
         }
 
-        fPath.deleteOnExit();
-        File metadataFile = new File(fPath.getPath() + File.separator + "metadata");
-        metadataFile.deleteOnExit();
+        File metadataFile = new File(file.getPath() + File.separator + "metadata");
         File[] streams = new File[fNbChans];
         FileChannel[] channels = new FileChannel[fNbChans];
         FileOutputStream fos = null;
 
         try {
             for (int i = 0; i < fNbChans; i++) {
-                streams[i] = new File(fPath.getPath() + File.separator + "channel" + i);
+                streams[i] = new File(file.getPath() + File.separator + "channel" + i);
                 channels[i] = new FileOutputStream(streams[i]).getChannel();
-                streams[i].deleteOnExit();
             }
         } catch (FileNotFoundException e) {
         }
index 8c38765e662657c68d680f904908311fd0102021..08483e1aa3df17ba1ee0be016289d3fbb1c210eb 100644 (file)
@@ -9,5 +9,5 @@
 /kernel
 /kernel_vm
 /synctraces
+/synthetic-trace
 /trace2
-
This page took 0.029575 seconds and 5 git commands to generate.