mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
speedtest added
This commit is contained in:
parent
576da581b6
commit
5adbff1e78
7 changed files with 344 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: org.eclipse.tm.terminal.test
|
||||
Bundle-SymbolicName: org.eclipse.tm.terminal.test;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Vendor: %providerName
|
||||
Bundle-Localization: plugin
|
||||
|
@ -10,3 +10,4 @@ Require-Bundle: org.junit,
|
|||
org.eclipse.swt,
|
||||
org.eclipse.jface
|
||||
Bundle-RequiredExecutionEnvironment: J2SE-1.4
|
||||
Export-Package: org.eclipse.tm.internal.terminal.speedtest
|
||||
|
|
21
org.eclipse.tm.terminal.test/plugin.xml
Normal file
21
org.eclipse.tm.terminal.test/plugin.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.2"?>
|
||||
<!--
|
||||
# Copyright (c) 2006 Wind River Systems, Inc. and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# Michael Scharf (Wind River) - initial API and implementation
|
||||
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||
-->
|
||||
<plugin>
|
||||
<extension
|
||||
point="org.eclipse.tm.terminal.terminalConnector">
|
||||
<connector name="Speed Test"
|
||||
id="org.eclipse.tm.internal.terminal.speedtest.SpeedTestConnector"
|
||||
class="org.eclipse.tm.internal.terminal.speedtest.SpeedTestConnector"/>
|
||||
</extension>
|
||||
</plugin>
|
|
@ -0,0 +1,100 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.speedtest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
||||
|
||||
public class SpeedTestConnection extends Thread {
|
||||
private static int fgNo;
|
||||
private final ITerminalControl fControl;
|
||||
private final InputStream fInputStream;
|
||||
private final SpeedTestSettings fSettings;
|
||||
protected SpeedTestConnection(InputStream inputStream, SpeedTestSettings settings,ITerminalControl control) {
|
||||
super("SpeedTestConnection-"+fgNo++);
|
||||
fControl = control;
|
||||
fInputStream=inputStream;
|
||||
fSettings=settings;
|
||||
}
|
||||
public void run() {
|
||||
fControl.setState(TerminalState.CONNECTED);
|
||||
|
||||
try {
|
||||
readDataForever(fInputStream);
|
||||
} catch (IOException e) {
|
||||
connectFailed(e.getMessage(),e.getMessage());
|
||||
}
|
||||
// when reading is done, we set the state to closed
|
||||
fControl.setState(TerminalState.CLOSED);
|
||||
}
|
||||
private void connectFailed(String terminalText, String msg) {
|
||||
Logger.log(terminalText);
|
||||
fControl.displayTextInTerminal(terminalText);
|
||||
fControl.setState(TerminalState.CLOSED);
|
||||
fControl.setMsg(msg);
|
||||
}
|
||||
/**
|
||||
* Read the data from the input file and display it in the terminal.
|
||||
* @param in
|
||||
* @throws IOException
|
||||
*/
|
||||
private void readDataForever(InputStream in) throws IOException {
|
||||
long N=0;
|
||||
long T=0;
|
||||
long tDisplay=0;
|
||||
int NCalls=0;
|
||||
// read the data
|
||||
byte bytes[]=new byte[fSettings.getBufferSize()];
|
||||
// read until the thread gets interrupted....
|
||||
String info="";
|
||||
while(!isInterrupted()) {
|
||||
// read some bytes
|
||||
int n;
|
||||
if((n=in.read(bytes))==-1) {
|
||||
fControl.displayTextInTerminal("\033[2J\033c"+info);
|
||||
// long rate=(1000*N)/T;
|
||||
// setTitle(rate+" baud DONE");
|
||||
// try {
|
||||
// Thread.sleep(10000);
|
||||
// } catch (InterruptedException e) {
|
||||
// // no need to catch it
|
||||
// }
|
||||
return;
|
||||
}
|
||||
// we assume we get ASCII UTF8 bytes
|
||||
long t0=System.currentTimeMillis();
|
||||
fControl.getRemoteToTerminalOutputStream().write(bytes,0,n);
|
||||
long t=System.currentTimeMillis();
|
||||
T+=t-t0;
|
||||
N+=n;
|
||||
NCalls++;
|
||||
if(t-tDisplay>1000 && T>0) {
|
||||
long rate=(1000*N)/T;
|
||||
info=rate+" byte/s = "+rate*8+" baud "+"bytes/call="+N/NCalls;
|
||||
info=rate+" byte/s with buffer size "+fSettings.getBufferSize();
|
||||
setTitle(info);
|
||||
tDisplay=System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
}
|
||||
private void setTitle(final String title) {
|
||||
Display.getDefault().asyncExec(new Runnable(){
|
||||
public void run() {
|
||||
fControl.setTerminalTitle(title);
|
||||
}});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.speedtest;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
||||
|
||||
public class SpeedTestConnector implements ITerminalConnector {
|
||||
final SpeedTestSettings fSettings=new SpeedTestSettings();
|
||||
InputStream fInputStream;
|
||||
OutputStream fOutputStream;
|
||||
ITerminalControl fControl;
|
||||
SpeedTestConnection fConnection;
|
||||
public SpeedTestConnector() {
|
||||
}
|
||||
synchronized public void connect(ITerminalControl control) {
|
||||
fControl=control;
|
||||
fControl.setState(TerminalState.CONNECTING);
|
||||
String file=fSettings.getInputFile();
|
||||
try {
|
||||
fInputStream=new BufferedInputStream(new FileInputStream(file));
|
||||
} catch (FileNotFoundException e) {
|
||||
disconnect();
|
||||
fControl.setMsg(file+": "+e.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
fOutputStream=System.out;
|
||||
fControl.setTerminalTitle(fSettings.getInputFile());
|
||||
fConnection=new SpeedTestConnection(fInputStream,fSettings,fControl);
|
||||
fConnection.start();
|
||||
}
|
||||
|
||||
synchronized public void disconnect() {
|
||||
if(fConnection!=null){
|
||||
fConnection.interrupt();
|
||||
fConnection=null;
|
||||
}
|
||||
if (fInputStream != null) {
|
||||
try {
|
||||
fInputStream.close();
|
||||
} catch (Exception exception) {
|
||||
Logger.logException(exception);
|
||||
}
|
||||
}
|
||||
fInputStream=null;
|
||||
if (fOutputStream != null) {
|
||||
try {
|
||||
fOutputStream.close();
|
||||
} catch (Exception exception) {
|
||||
Logger.logException(exception);
|
||||
}
|
||||
}
|
||||
fOutputStream=null;
|
||||
fControl.setState(TerminalState.CLOSED);
|
||||
}
|
||||
synchronized public InputStream getInputStream() {
|
||||
return fInputStream;
|
||||
}
|
||||
|
||||
synchronized public OutputStream getOutputStream() {
|
||||
return fOutputStream;
|
||||
}
|
||||
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getInputFile();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
//throw new RuntimeException("XXX problems\nSpeedTest\nXXX!");
|
||||
}
|
||||
|
||||
public boolean isLocalEcho() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
|
||||
}
|
||||
|
||||
public ISettingsPage makeSettingsPage() {
|
||||
return new SpeedTestSettingsPage(fSettings);
|
||||
}
|
||||
|
||||
public void save(ISettingsStore store) {
|
||||
fSettings.save(store);
|
||||
|
||||
}
|
||||
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.speedtest;
|
||||
|
||||
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
|
||||
|
||||
public class SpeedTestSettings {
|
||||
String fInputFile="";
|
||||
String fBufferSize="";
|
||||
String getInputFile() {
|
||||
return fInputFile;
|
||||
}
|
||||
public String getBufferSizeString() {
|
||||
return getBufferSize()+"";
|
||||
}
|
||||
public void setBufferSizeString(String bufferSize) {
|
||||
fBufferSize = bufferSize;
|
||||
}
|
||||
public int getBufferSize() {
|
||||
try {
|
||||
return Integer.parseInt(fBufferSize);
|
||||
} catch(RuntimeException e) {
|
||||
return 1024;
|
||||
}
|
||||
}
|
||||
void setInputFile(String testFile) {
|
||||
fInputFile = testFile;
|
||||
}
|
||||
public void load(ISettingsStore store) {
|
||||
fInputFile=store.get("inputFile");
|
||||
fBufferSize=store.get("bufferSize");
|
||||
}
|
||||
public void save(ISettingsStore store) {
|
||||
store.put("inputFile", fInputFile);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Michael Scharf (Wind River) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.speedtest;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
|
||||
|
||||
public class SpeedTestSettingsPage implements ISettingsPage {
|
||||
final SpeedTestSettings fSettings;
|
||||
Text fInputFile;
|
||||
Text fBufferSize;
|
||||
SpeedTestSettingsPage(SpeedTestSettings settings) {
|
||||
fSettings=settings;
|
||||
}
|
||||
public void createControl(Composite parent) {
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
GridLayout gridLayout = new GridLayout(2, false);
|
||||
|
||||
composite.setLayout(gridLayout);
|
||||
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
fInputFile=createTextField(composite, "Input File:");//$NON-NLS-1$
|
||||
fBufferSize=createTextField(composite, "Buffer Size:");//$NON-NLS-1$
|
||||
loadSettings();
|
||||
}
|
||||
private Text createTextField(Composite composite, String label) {
|
||||
new Label(composite, SWT.RIGHT).setText(label);
|
||||
Text text = new Text(composite, SWT.BORDER);
|
||||
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
return text;
|
||||
}
|
||||
|
||||
public void loadSettings() {
|
||||
setText(fInputFile, fSettings.getInputFile());
|
||||
setText(fBufferSize, fSettings.getBufferSizeString());
|
||||
}
|
||||
private void setText(Text text, String value) {
|
||||
if(value==null)
|
||||
value="";
|
||||
text.setText(value);
|
||||
}
|
||||
|
||||
public void saveSettings() {
|
||||
fSettings.setInputFile(fInputFile.getText());
|
||||
fSettings.setBufferSizeString(fBufferSize.getText());
|
||||
}
|
||||
|
||||
public boolean validateSettings() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,6 @@ Export-Package: org.eclipse.tm.internal.terminal.control;x-friends:="org.eclipse
|
|||
org.eclipse.tm.internal.terminal.control.impl;x-internal:=true,
|
||||
org.eclipse.tm.internal.terminal.emulator;x-friends:="org.eclipse.tm.terminal.test",
|
||||
org.eclipse.tm.internal.terminal.model;x-friends:="org.eclipse.tm.terminal.test",
|
||||
org.eclipse.tm.internal.terminal.provisional.api;x-friends:="org.eclipse.tm.terminal.serial,org.eclipse.tm.terminal.ssh,org.eclipse.tm.terminal.telnet,org.eclipse.tm.terminal.view",
|
||||
org.eclipse.tm.internal.terminal.provisional.api;x-friends:="org.eclipse.tm.terminal.serial,org.eclipse.tm.terminal.ssh,org.eclipse.tm.terminal.telnet,org.eclipse.tm.terminal.view,org.eclipse.tm.terminal.test",
|
||||
org.eclipse.tm.internal.terminal.textcanvas;x-friends:="org.eclipse.tm.terminal.test",
|
||||
org.eclipse.tm.terminal.model
|
||||
|
|
Loading…
Add table
Reference in a new issue