-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathThroughputTestUsingProcess.java
More file actions
133 lines (112 loc) · 3.67 KB
/
Copy pathThroughputTestUsingProcess.java
File metadata and controls
133 lines (112 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.shimmerresearch.javacsharp.throughput;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
//steps
//1.change the executablePath to the path to the exe file of the c# application
//2.make sure the period and IsSendDataFromJavaToCSharp are the same in both c# and java application
//3.run the ThroughputTestUsingProcess.java
public class ThroughputTestUsingProcess {
static Process p;
static String executablePath = "C:\\Users\\weiwe\\source\\repos\\ShimmerCSharpBLEAPI\\ThroughputTestUsingProcess\\bin\\Debug\\netcoreapp3.1\\ThroughputTestUsingProcess.exe";
BufferedWriter writer;
static int bytePerLine = 20;
static boolean IsSendDataFromJavaToCSharp = true;
static int period = 5;
static Timer writeDataTimer;
static String unixTimeStampWhenSend;
static long unixTimeStampWhenReceive;
int maximumThroughput = 0;
String writeToCSharpString = null;
public ThroughputTestUsingProcess() {
}
public void ReadDataUsingProcess() {
try {
int count = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
count ++;
System.out.println(line);
if(line.length() == 1) {
writeToCSharpString = line;
}
}
System.out.println("Total kilobytes received in " + period + " seconds = " + count * bytePerLine / 1000);
maximumThroughput = (((count * bytePerLine) / 1000) / period);
System.out.println("Maximum throughput = " + maximumThroughput + "kb per second");
Long delay = unixTimeStampWhenReceive - Long.parseLong(unixTimeStampWhenSend);
System.out.println("Latency = " + delay + " milliseconds");
}
catch (IOException e) {
e.printStackTrace();
}
}
public void MeasureLatency() {
//long unixTime = Instant.now().getEpochSecond();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
unixTimeStampWhenSend = line;
unixTimeStampWhenReceive = Calendar.getInstance().getTime().getTime();
break;
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public void WriteDataUsingProcess() {
final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
writeDataTimer = new Timer();
writeDataTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
writer.write("a", 0, 1);
writer.newLine();
writer.flush();
} catch (IOException e)
{
writeDataTimer.cancel();
writeDataTimer.purge();
System.out.println("Disconnected");
}
}
}, 0, 1000);
}
public void InitializeProcess() {
Runtime runTime = Runtime.getRuntime();
try {
p = runTime.exec(executablePath);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
final ThroughputTestUsingProcess test = new ThroughputTestUsingProcess();
//run the c sharp exe file
test.InitializeProcess();
test.MeasureLatency();
Thread ReadDataUsingProcess = new Thread(){
public void run(){
test.ReadDataUsingProcess();
}
};
ReadDataUsingProcess.start();
if(IsSendDataFromJavaToCSharp) {
Thread WriteDataUsingProcess = new Thread(){
public void run(){
test.WriteDataUsingProcess();
}
};
WriteDataUsingProcess.start();
}
}
}