📄 oo1benchmarkapp.java
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: OO1BenchmarkApp.java,v 1.3 2002/09/18 06:54:18 per_nyfelt Exp $
package org.ozoneDB.tools;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
/** */
class BenchmarkThread extends Thread {
/** */
public String benchmarkClassName;
private int benchmarkId = 1;
private int size = 1000;
private String objectName = "cattell";
private String serverHost = "localhost";
private BenchmarkProgressLog log = new BenchmarkProgressLog();
/** */
public BenchmarkThread( String className ) {
benchmarkClassName = className;
}
/** */
public void setProgressLog( BenchmarkProgressLog blog ) {
log = blog;
}
/** */
public String[] filterAndApplyArgs( String[] args ) {
Vector remainingArgs = new Vector();
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith( "-benchmark=" )) {
benchmarkId = new Integer( args[i].substring( 11 ) ).intValue();
} else if (args[i].startsWith( "-size=" )) {
size = new Integer( args[i].substring( 6 ) ).intValue();
} else if (args[i].startsWith( "-name=" )) {
objectName = args[i].substring( 6 );
} else if (args[i].startsWith( "-host=" )) {
serverHost = args[i].substring( 6 );
log.logMessage("serverHost=" + serverHost);
} else {
remainingArgs.addElement( args[i] );
}
}
String[] result = new String[remainingArgs.size()];
for (int i = 0; i < result.length; i++) {
result[i] = (String)remainingArgs.elementAt( i );
}
return result;
}
/** */
public static String availableArgs() {
return "-benchmark=<test> -size=<size> [-name=<name>] [-host=<host[:port]>]";
}
/** */
public static String helpText() {
return
" -benchmark= : 1: create database; size: 100..(10000)\n"
+ " 2: lookup; size 1..\n" + " 3: traversal; size: 1..7\n"
+ " 4: insert and delete; size: 1..\n" + " 5: insert; size: 1..\n"
+ " 6: insert size*1000 objects\n"
+ " 7: traversal on the first size cattell objects\n"
+ " 8: insert on the first size cattell objects\n"
+ " -size : the size of the test\n"
+ " -name : optional name of the benchmark object\n"
+ " -host : optional name of the server host\n";
}
/** */
public void run() {
try {
Class benchmarkClass = Class.forName( benchmarkClassName );
OO1Benchmark benchmark = (OO1Benchmark)benchmarkClass.newInstance();
benchmark.setProgressLog( log );
switch (benchmarkId) {
case 1:
benchmark.create( size, objectName, serverHost );
break;
case 2:
benchmark.lookup( size, objectName, serverHost );
break;
case 3:
benchmark.traversal( size, objectName, serverHost );
break;
case 4:
benchmark.insertAndDelete( size, objectName, serverHost );
break;
case 5:
benchmark.insert( size, objectName, serverHost );
break;
case 55:
benchmark.delete( size, objectName, serverHost );
break;
case 6:
benchmark.createObjects( size, objectName, serverHost );
break;
case 7:
benchmark.traversalObjects( size, objectName, serverHost );
break;
case 8:
benchmark.insertObjects( size, objectName, serverHost );
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/** */
public class OO1BenchmarkApp extends Applet implements ActionListener, ItemListener {
/** */
public class AppletProgressLog extends BenchmarkProgressLog {
/** */
public AppletProgressLog() {
}
/** */
public void logMessage( String msg ) {
if (outText != null) {
outText.append( msg + "\n" );
}
}
/** */
public void logTime( long time ) {
if (outText != null) {
outText.append( "time: " + time + "msec\n" );
}
if (chart != null) {
chart.appendTime( time );
}
}
}
/** */
protected Button startButton;
protected Choice testChoice;
protected TextField sizeText;
protected TextField nameText;
protected TextField serverText;
protected TextField portText;
protected TextArea outText;
protected Label statusLabel;
protected ChartCanvas chart;
protected BenchmarkThread benchmarkThread;
/** */
public OO1BenchmarkApp() {
}
/** */
public void init() {
init( false, new BenchmarkThread( "CattellImpl" ) );
}
/** */
public void init( boolean chartOnly, BenchmarkThread bmt ) {
benchmarkThread = bmt;
setLayout( new BorderLayout() );
if (!chartOnly) {
Panel panel = new Panel();
panel.setLayout( new FlowLayout( FlowLayout.LEFT ) );
startButton = new Button( " Start " );
startButton.setFont( new Font( "Monospaced", Font.BOLD, 14 ) );
startButton.addActionListener( this );
panel.add( startButton );
testChoice = new Choice();
testChoice.add( "Help" );
testChoice.add( "1 Create" );
testChoice.add( "2 Lookup" );
testChoice.add( "3 Traversal" );
testChoice.add( "4 Ins & del" );
testChoice.add( "5 Insert" );
testChoice.add( "6 Ins*1000" );
testChoice.add( "7 Traversal" );
testChoice.add( "8 Insert" );
testChoice.addItemListener( this );
panel.add( testChoice );
sizeText = new TextField( "1000", 5 );
sizeText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
sizeText.addActionListener( this );
panel.add( sizeText );
nameText = new TextField( "cattell", 9 );
nameText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
nameText.addActionListener( this );
panel.add( nameText );
serverText = new TextField( "localhost", 9 );
serverText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
serverText.addActionListener( this );
panel.add( serverText );
portText = new TextField( "3333", 9 );
portText.setFont( new Font( "Monospaced", Font.PLAIN, 12 ) );
portText.addActionListener( this );
panel.add( portText );
add( "North", panel );
panel = new Panel();
panel.setLayout( new BorderLayout() );
outText = new TextArea();
panel.add( outText, "North" );
chart = new ChartCanvas();
panel.add( chart, "Center" );
add( "Center", panel );
statusLabel = new Label( "Test:Build - Size:1000 - Name:cattell " );
add( "South", statusLabel );
} else {
chart = new ChartCanvas();
add( "Center", chart );
}
benchmarkThread.setProgressLog( new AppletProgressLog() );
}
/** */
public void itemStateChanged( ItemEvent e ) {
String[] defaults = {"0", "1000", "100", "7", "100", "100", "10", "10", "10"};
if (testChoice.getSelectedIndex() > -1) {
sizeText.setText( defaults[testChoice.getSelectedIndex()] );
}
}
/** */
public void actionPerformed( ActionEvent e ) {
if (startButton.getLabel().equals( " Start " )) {
int test = testChoice.getSelectedIndex();
int size = Integer.valueOf( sizeText.getText() ).intValue();
String name = nameText.getText();
String server = serverText.getText();
String port = portText.getText();
statusLabel.setText( "Test: " + test + " Size: " + size + " Name: " + name + " Host: " + server + ":"
+ port );
String[] args = {"-benchmark=" + test, "-size=" + size, "-name=" + name, "-host=" + server + ":" + port};
benchmarkThread.filterAndApplyArgs( args );
startButton.setLabel( " Stop " );
benchmarkThread.start();
} else {
benchmarkThread.stop();
benchmarkThread = new BenchmarkThread( benchmarkThread.benchmarkClassName );
benchmarkThread.setProgressLog( new AppletProgressLog() );
startButton.setLabel( " Start " );
}
}
/** */
public static void createFrame( boolean chartOnly, BenchmarkThread thread ) {
Frame f = new Frame( "Cattell Benchmark" );
OO1BenchmarkApp applet = new OO1BenchmarkApp();
applet.init( chartOnly, thread );
applet.start();
f.add( "Center", applet );
f.pack();
f.setSize( chartOnly ? 300 : 550, chartOnly ? 120 : 400 );
f.show();
f.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit( 0 );
}
} );
if (chartOnly) {
thread.run();
}
}
/** */
public static void main( String[] args ) {
boolean chartOnly = false;
boolean noGui = false;
String benchmarkClass = "CattellImpl";
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith( "-chartOnly" )) {
chartOnly = true;
} else if (args[i].startsWith( "-noGui" )) {
noGui = true;
} else if (args[i].startsWith( "-class=" )) {
benchmarkClass = args[i].substring( 7 );
} else {
if (args[i].startsWith( "-help" ) || args[i].startsWith( "-?" )) {
System.out.println( "usage: java OO1BenchmarkApp " + BenchmarkThread.availableArgs() + " "
+ ChartCanvas.availableArgs() + " "
+ "[-chartOnly] [-noGui] [-class=<classname>] [-help|-h|-?]\n" + "Details:\n"
+ BenchmarkThread.helpText() + ChartCanvas.helpText()
+ " -chartOnly : show only the chart panel and perform the given test\n"
+ " -noGui : show no GUI at all and perform the given test\n"
+ " -class= : the benchmark class, default is CattellImpl\n"
+ " -help|-h|-? : shows this help" );
return;
}
}
}
BenchmarkThread thread = new BenchmarkThread( benchmarkClass );
thread.filterAndApplyArgs( args );
if (noGui) {
thread.run();
} else {
createFrame( chartOnly, thread );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -