*
* Contributors:
* Matthew Khouzam - Initial API and implementation
+ * Marc-Andre Laperle - Move generation to traces folder
*******************************************************************************/
package org.eclipse.linuxtools.ctf.core.tests.synthetictraces;
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;
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
*
private final long fDuration;
private final long fNbEvents;
private final int fNbChans;
- private File fPath;
private static final String[] sfProcesses = {
"IDLE",
};
- 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
* 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));
}
/**
* @return the name of the trace
*/
public static String getName() {
- return DIRECTORY_NAME;
+ return TRACE_NAME;
}
/**
* @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);
}
/**
/**
* 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) {
}