files used for all paper numbers
[IRC.git] / Robust / src / Benchmarks / SingleTM / MicroBenchmarks / readFromFile.java
1 /** readFromFile 
2  ** This file is associated with the output generated from file SingleObjectMod.java
3  ** This file reads the contents of the output files such as test_0, test_1 ...test_N
4  ** generated by running the SingleObjectMod.java file
5  **
6  ** First execute SingleObjectMod.java in the following manner
7  **./STATSSingleObjectModNoLockBase.bin -t 8 -size 1 -l 100000 -l1 10000 -l2 10000 -p 90
8  ** 
9  ** build:
10  ** javac readFromFile.java
11  **
12  **
13  ** run :
14  ** java readFromFile <filename> > log_filename
15  ** for e.g. java readFromFile test_0 > log_test_0
16  **
17  **/
18
19 import java.io.*;
20
21
22 public class readFromFile {
23   public static void main(String[] args) {
24     for (int i = 0; i < args.length; i++)
25       System.out.println(args[i]);
26     File file = new File(args[0]);
27     try {
28       FileInputStream fin = new FileInputStream(file);
29       byte[] b1 = new byte[4];
30       byte[] b2 = new byte[8];
31       int start = 0;
32       int stop = 12500; //  Note: l/NUMTHREADS (number of iterations (-l) / num of threads)
33       for(int i = 0;i<(7*(stop-start))+3; i++) {
34         fin.read(b1);
35         int event = convertToInt(b1);
36         System.out.print("Event= " + event + " ");
37         fin.read(b2);
38         long time = convertToLong(b2);
39         System.out.println("Time= " + time);
40       }
41       fin.close();
42     } catch(FileNotFoundException e) {
43       System.out.println("File " + file.getAbsolutePath() +
44           " could not be found on filesystem");
45     } catch(IOException ioe)
46     {
47       System.out.println("Exception while reading the file" + ioe);
48     }
49   }
50
51   static int convertToInt(byte[] b) {
52     int value = 0;
53     for (int i = 0; i < 4; i++) {
54       int shift = (4 - 1 - i) * 8;
55       value += (b[i] & 0x000000FF) << shift;
56     }
57     return value;
58   }
59
60   static long convertToLong (byte[] buf)
61   {
62     return (((long)(buf [0] & 0xff) << 56) |
63         ((long)(buf [1] & 0xff) << 48) |
64         ((long)(buf [2] & 0xff) << 40) |
65         ((long)(buf [3] & 0xff) << 32) |
66         ((long)(buf [4] & 0xff) << 24) |
67         ((long)(buf [5] & 0xff) << 16) |
68         ((long)(buf [6] & 0xff) <<  8) |
69         ((long)(buf [7] & 0xff)));
70   }
71 }