- Renamed a few classes in accordance with the model
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.tests / stubs / org / eclipse / linuxtools / tmf / CreateTestFiles.java
CommitLineData
d18dd09b
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
165c977c 10 * Francois Chouinard - Initial API and implementation
d18dd09b
ASL
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf;
14
15import java.io.BufferedOutputStream;
16import java.io.DataOutputStream;
165c977c 17import java.io.File;
d18dd09b
ASL
18import java.io.FileNotFoundException;
19import java.io.FileOutputStream;
20import java.io.IOException;
165c977c 21import java.util.Random;
d18dd09b
ASL
22
23/**
24 * <b><u>CreateTestFiles</u></b>
25 * <p>
26 * Create a number of event test files of various lengths.
27 * <p>
28 * Events have the following format:
29 * <ul>
30 * <li> [timestamp] [source] [type] [ref] [field]*
31 * <li> There are NB_SOURCES sources and NB_TYPES types.
32 * <li> The number of fields (0 .. NB_TYPES-1) depends on the event type.
33 * </ul>
34 */
35public class CreateTestFiles {
36
37 // ========================================================================
38 // Constants
39 // ========================================================================
40
165c977c
FC
41 private static final String FILE_NAMES[] = { "Test-10", "Test-1K", "Test-10K", "Test-100K", "Test-1M", "Test-10M" };
42 private static final int FILE_SIZES[] = { 10 , 1000 , 10000 , 100000 , 1000000 , 10000000 };
d18dd09b 43
165c977c
FC
44 private static final int NB_SOURCES = 15;
45 private static final int NB_TYPES = 7;
d18dd09b
ASL
46
47 // ========================================================================
48 // Constructors
49 // ========================================================================
50
51 /**
52 * @param args
53 */
54 public static void main(String[] args) {
165c977c
FC
55
56 try {
57 System.out.println("Creating test files in directory: " + new File(".").getCanonicalPath() + File.separator + "testfiles");
58 } catch (IOException e) {
59 e.printStackTrace();
60 }
61
d18dd09b
ASL
62 for (int i = 0; i < FILE_SIZES.length; i++) {
63 try {
165c977c
FC
64 createTestFile("testfiles" + File.separator + "M-" + FILE_NAMES[i], FILE_SIZES[i], true);
65 createTestFile("testfiles" + File.separator + "R-" + FILE_NAMES[i], FILE_SIZES[i], false);
d18dd09b
ASL
66 } catch (Exception e) {
67 }
68 }
165c977c
FC
69
70 System.out.println("Done.");
d18dd09b
ASL
71 }
72
73 // ========================================================================
74 // Operators
75 // ========================================================================
76
77 /**
78 * @param file
79 * @param size
165c977c 80 * @param monotonic
d18dd09b
ASL
81 * @throws FileNotFoundException
82 * @throws IOException
83 */
165c977c 84 private static void createTestFile(String file, int size, boolean monotonic) throws FileNotFoundException, IOException {
d18dd09b
ASL
85 DataOutputStream out;
86 System.out.println("Creating " + file);
87 out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
88
165c977c
FC
89 Random generator = new Random(19580427 + size);
90 long ts = 0;
d18dd09b 91 for (int i = 0; i < size; i++) {
165c977c 92 ts += monotonic ? 1 : generator.nextInt(10);
d18dd09b
ASL
93 int sourceIndex = i % NB_SOURCES;
94 int typeIndex = i % NB_TYPES;
165c977c 95 out.writeLong(ts); // Timestamp
d18dd09b
ASL
96 out.writeUTF("Source-" + sourceIndex); // Source
97 out.writeUTF("Type-" + typeIndex); // Type
165c977c 98 out.writeInt(i + 1); // Reference (event #)
d18dd09b
ASL
99 for (int j = 0; j < typeIndex; j++) {
100 out.writeUTF("Field-" + sourceIndex + "-" + j);
101 }
102 }
103 out.flush();
104 out.close();
105 }
165c977c 106
d18dd09b 107}
This page took 0.029089 seconds and 5 git commands to generate.