1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-14 03:35:37 +02:00

speedtest improved

This commit is contained in:
Michael Scharf 2007-10-04 23:56:38 +00:00
parent 5adbff1e78
commit 5453da9558
3 changed files with 66 additions and 27 deletions

View file

@ -10,8 +10,11 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.speedtest; package org.eclipse.tm.internal.terminal.speedtest;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
@ -33,7 +36,7 @@ public class SpeedTestConnection extends Thread {
fControl.setState(TerminalState.CONNECTED); fControl.setState(TerminalState.CONNECTED);
try { try {
readDataForever(fInputStream); readDataForever(fInputStream,fControl.getRemoteToTerminalOutputStream());
} catch (IOException e) { } catch (IOException e) {
connectFailed(e.getMessage(),e.getMessage()); connectFailed(e.getMessage(),e.getMessage());
} }
@ -51,43 +54,58 @@ public class SpeedTestConnection extends Thread {
* @param in * @param in
* @throws IOException * @throws IOException
*/ */
private void readDataForever(InputStream in) throws IOException { private void readDataForever(InputStream in, OutputStream os) throws IOException {
long N=0; long N=0;
long T=0; long T=0;
long tDisplay=0; long tDisplay=0;
int NCalls=0; int NCalls=0;
int bufferSize=fSettings.getBufferSize();
int throttle=fSettings.getThrottle();
// read the data // read the data
byte bytes[]=new byte[fSettings.getBufferSize()]; BufferedReader reader = new BufferedReader(new InputStreamReader(in));
// read until the thread gets interrupted.... // read until the thread gets interrupted....
String info=""; String info="";
while(!isInterrupted()) { int n=0;
byte[] crnl="\r\n".getBytes("UTF-8");
long t0=System.currentTimeMillis();
String line=null;
do {
line=reader.readLine();
// read some bytes // read some bytes
int n; if(line==null) {
if((n=in.read(bytes))==-1) {
fControl.displayTextInTerminal("\033[2J\033c"+info); fControl.displayTextInTerminal("\033[2J\033c"+info);
// long rate=(1000*N)/T; } else {
// setTitle(rate+" baud DONE"); os.write(line.getBytes("UTF-8"));
// try { os.write(crnl);
// Thread.sleep(10000); n+=line.length();
// } catch (InterruptedException e) {
// // no need to catch it
// }
return;
} }
// we assume we get ASCII UTF8 bytes if(throttle>0)
long t0=System.currentTimeMillis(); sleep(throttle);
fControl.getRemoteToTerminalOutputStream().write(bytes,0,n); // process at least this number of characters to update the UI
long t=System.currentTimeMillis(); if(line==null || n>bufferSize) {
T+=t-t0; // we assume we get ASCII UTF8 bytes
N+=n; long t=System.currentTimeMillis();
NCalls++; T+=t-t0;
if(t-tDisplay>1000 && T>0) { N+=n;
long rate=(1000*N)/T; NCalls++;
info=rate+" byte/s = "+rate*8+" baud "+"bytes/call="+N/NCalls; if(t-tDisplay>1000 && T>0) {
info=rate+" byte/s with buffer size "+fSettings.getBufferSize(); long rate=(1000*N)/T;
setTitle(info); info=rate+" byte/s = "+rate*8+" baud "+"bytes/call="+N/NCalls;
tDisplay=System.currentTimeMillis(); info=rate+" byte/s with buffer size "+fSettings.getBufferSize();
setTitle(info);
tDisplay=System.currentTimeMillis();
}
n=0;
t0=System.currentTimeMillis();
} }
} while(line!=null);
}
private void sleep(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} }
} }
private void setTitle(final String title) { private void setTitle(final String title) {

View file

@ -16,6 +16,7 @@ import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
public class SpeedTestSettings { public class SpeedTestSettings {
String fInputFile=""; String fInputFile="";
String fBufferSize=""; String fBufferSize="";
String fThrottle;
String getInputFile() { String getInputFile() {
return fInputFile; return fInputFile;
} }
@ -38,8 +39,24 @@ public class SpeedTestSettings {
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fInputFile=store.get("inputFile"); fInputFile=store.get("inputFile");
fBufferSize=store.get("bufferSize"); fBufferSize=store.get("bufferSize");
fThrottle=store.get("throttle");
} }
public void save(ISettingsStore store) { public void save(ISettingsStore store) {
store.put("inputFile", fInputFile); store.put("inputFile", fInputFile);
store.put("bufferSize", fBufferSize);
store.put("throttle", fInputFile);
}
public String getThrottleString() {
return fThrottle;
}
public int getThrottle() {
try {
return Integer.parseInt(fThrottle);
} catch(RuntimeException e) {
return 1024;
}
}
public void setThrottleString(String throttle) {
fThrottle = throttle;
} }
} }

View file

@ -22,6 +22,7 @@ public class SpeedTestSettingsPage implements ISettingsPage {
final SpeedTestSettings fSettings; final SpeedTestSettings fSettings;
Text fInputFile; Text fInputFile;
Text fBufferSize; Text fBufferSize;
private Text fThrottle;
SpeedTestSettingsPage(SpeedTestSettings settings) { SpeedTestSettingsPage(SpeedTestSettings settings) {
fSettings=settings; fSettings=settings;
} }
@ -33,6 +34,7 @@ public class SpeedTestSettingsPage implements ISettingsPage {
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fInputFile=createTextField(composite, "Input File:");//$NON-NLS-1$ fInputFile=createTextField(composite, "Input File:");//$NON-NLS-1$
fBufferSize=createTextField(composite, "Buffer Size:");//$NON-NLS-1$ fBufferSize=createTextField(composite, "Buffer Size:");//$NON-NLS-1$
fThrottle=createTextField(composite, "Throttle:");//$NON-NLS-1$
loadSettings(); loadSettings();
} }
private Text createTextField(Composite composite, String label) { private Text createTextField(Composite composite, String label) {
@ -45,6 +47,7 @@ public class SpeedTestSettingsPage implements ISettingsPage {
public void loadSettings() { public void loadSettings() {
setText(fInputFile, fSettings.getInputFile()); setText(fInputFile, fSettings.getInputFile());
setText(fBufferSize, fSettings.getBufferSizeString()); setText(fBufferSize, fSettings.getBufferSizeString());
setText(fThrottle, fSettings.getThrottleString());
} }
private void setText(Text text, String value) { private void setText(Text text, String value) {
if(value==null) if(value==null)
@ -55,6 +58,7 @@ public class SpeedTestSettingsPage implements ISettingsPage {
public void saveSettings() { public void saveSettings() {
fSettings.setInputFile(fInputFile.getText()); fSettings.setInputFile(fInputFile.getText());
fSettings.setBufferSizeString(fBufferSize.getText()); fSettings.setBufferSizeString(fBufferSize.getText());
fSettings.setThrottleString(fThrottle.getText());
} }
public boolean validateSettings() { public boolean validateSettings() {