📄 performancetest.java
字号:
/*
Copyright (c) 2008, Intel Corporation.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/import java.io.IOException;import com.intel.mobile.base.IntelMobileException;import com.intel.mobile.battery.BatteryClass;import com.intel.mobile.context.ContextClass;import com.intel.mobile.network.*;import com.intel.mobile.processor.ProcessorClass;/** * <class or interface desc> */public class PerformanceTest{ private static int iteration = 1; public static void main(String[] args) { try { if (args.length > 0) iteration = Integer.parseInt(args[0]); new PerformanceTest().test(); } catch (IntelMobileException ex) { System.out.println(ex); System.out.println("Message: " + ex.getMessage()); System.out.println("GeneralMessage: " + ex.GetGeneralMessage()); System.out.println("Source: " + ex.GetSource()); System.out.println("TargetSite: " + ex.GetTargetSite()); System.out.println("ErrorCode: " + ex.GetErrorCode()); System.out.println("DetailErrorInfo: " + ex.GetDetailErrorInfo()); //ex.printStackTrace(); } } private ProcessorClass myProcessorClass = null; private BatteryClass myBatteryClass = null; private NetworkAdapterClass myAdapterClass = null; private WiredAdapterClass myWiredClass = null; private RadioAdapterClass myRadioClass = null; private LinkProtocolClass myProtocolClass = null; private Protocol802_3Class my802_3Class = null; private Protocol802_11Class my802_11Class = null; private ProtocolWwanClass myWwanClass = null; private ProtocolGprsClass myGprsClass = null; private ProtocolCdmaClass myCdmaClass = null; private ProtocolBluetoothPanClass myBluetoothPanClass = null; private ContextClass myContextClass = null; private ClientObserver theObserver = null; public void test() throws IntelMobileException { myProcessorClass = new ProcessorClass(); myBatteryClass = new BatteryClass(); myAdapterClass = new NetworkAdapterClass(); myWiredClass = new WiredAdapterClass(); myRadioClass = new RadioAdapterClass(); myProtocolClass = new LinkProtocolClass(); my802_3Class = new Protocol802_3Class(); my802_11Class = new Protocol802_11Class(); myWwanClass = new ProtocolWwanClass(); myGprsClass = new ProtocolGprsClass(); myCdmaClass = new ProtocolCdmaClass(); myBluetoothPanClass = new ProtocolBluetoothPanClass(); myContextClass = new ContextClass(); theObserver = new ClientObserver(); try { System.out.print("------------Enter COMMAND ('H' for help)------------\n"); boolean bExit = false; do { switch (System.in.read()) { case 'g': case 'G': System.gc(); break; case 'q': case 'Q': unregisterEvents(); theObserver.Close(); bExit = true; continue; case 'h': case 'H': printHelp(); break; case 'e': case 'E': registerEvents(); break; case 'c': case 'C': printContext(); break; case 'a': case 'A': printNetworkAdapter(); break; case 'p': case 'P': printLinkProtocol(); break; case 'b': case 'B': printBattery(); break; case 'r': case 'R': printProcessor(); break; default: continue; } System.out.print("------------Enter COMMAND ('H' for help)------------\n"); } while (!bExit); System.out.print("------------Leaving COMMAND------------\n"); } catch (IOException ex) { ex.printStackTrace(); } finally { theObserver.Close(); } } private void printHelp() { StringBuffer strBuf = new StringBuffer(); strBuf.append("\n") .append(" - 'G' - Garbage Collect\n") .append(" - 'Q' - Quit\n") .append(" - 'E' - Register for Events\n") .append(" - 'A' - Adapters\n") .append(" - 'P' - Protocols\n") .append(" - 'B' - Batteries\n") .append(" - 'R' - Processor\n") .append(" - 'C' - Connectivity\n") .append(" - 'H' - Help\n\n"); System.out.print( strBuf.toString() ); } private void printProcessor() throws IntelMobileException { System.out.println("not implement in Linux/CE\n"); /*ProcessorTest processor = new ProcessorTest(myProcessorClass); long startTick = System.currentTimeMillis(); for (int i = 0; i < iteration; i++) { processor.queryInfo(); //System.gc(); } long endTick = System.currentTimeMillis(); System.out.println( "Processor -- During Time of " + iteration + " repeat (ms): " + (endTick - startTick) ); */ } private void printBattery() { BatteryTest battery = new BatteryTest(myBatteryClass); long startTick = System.currentTimeMillis(); for (int i = 0; i < iteration; i++) { battery.queryInfo(); //System.gc(); } long endTick = System.currentTimeMillis(); System.out.println( "Battery -- During Time of " + iteration + " repeat (ms): " + (endTick - startTick) ); } private void printLinkProtocol() { LinkProtocolTest protocol = new LinkProtocolTest(myProtocolClass, my802_3Class, my802_11Class, myWwanClass, myGprsClass, myCdmaClass, myBluetoothPanClass); long startTick = System.currentTimeMillis(); for (int i = 0; i < iteration; i++) { protocol.queryInfo(); //System.gc(); } long endTick = System.currentTimeMillis(); System.out.println( "Link Protocol -- During Time of " + iteration + " repeat (ms): " + (endTick - startTick) ); } private void printNetworkAdapter() { NetworkAdapterTest adapter = new NetworkAdapterTest(myAdapterClass, myWiredClass, myRadioClass); long startTick = System.currentTimeMillis(); for (int i = 0; i < iteration; i++) { adapter.queryInfo(); //System.gc(); } long endTick = System.currentTimeMillis(); System.out.println( "Network Adapter -- During Time of " + iteration + " repeat (ms): " + (endTick - startTick) ); } private void printContext() { ContextTest Context = new ContextTest(myContextClass); long startTick = System.currentTimeMillis(); for (int i = 0; i < iteration; i++) { //Context.queryInfo(); //System.gc(); } long endTick = System.currentTimeMillis(); System.out.println( "Context -- During Time of " + iteration + " repeat (ms): " + (endTick - startTick) ); } private void registerEvents() throws IntelMobileException { myAdapterClass.Added.AddObserver( theObserver ); myAdapterClass.Removed.AddObserver( theObserver ); myRadioClass.Added.AddObserver( theObserver ); myRadioClass.Removed.AddObserver( theObserver ); myBatteryClass.Added.AddObserver( theObserver ); myBatteryClass.Removed.AddObserver( theObserver ); } private void unregisterEvents() throws IntelMobileException { myAdapterClass.Added.RemoveObserver( theObserver ); myAdapterClass.Removed.RemoveObserver( theObserver ); myRadioClass.Added.RemoveObserver( theObserver ); myRadioClass.Removed.RemoveObserver( theObserver ); myBatteryClass.Added.RemoveObserver( theObserver ); myBatteryClass.Removed.RemoveObserver( theObserver ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -