Results 1 to 4 of 4
- 04-29-2011, 11:52 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Counting Method Execution, Testing Tool
I am currently writing a testing tool which displays any selected class's methods. This tool can also execute any .java class with a "static void Main(String[] args)" method.
I would also like to be able to count how many times a method is invoked(used) during run time. Although I haven't the slightest Idea how i would even go about approaching the task..
Can anyone shed some light?
- 04-30-2011, 01:02 AM #2
I presume you mean "public static void main(String[] args)".This tool can also execute any .java class with a "static void Main(String[] args)"
And I guess you thought of private static int's to keep count? Or do you mean something else? (I can imagine that it is a bit more difficult to foresee the needed ints if you get the methods by introspection.)
I think you have to clarify your problem a bit more.
(And give a SSCEE, short self contained compiling example of what you have until now, with only code refering to the problem. Using codetags.)Last edited by Jodokus; 04-30-2011 at 01:09 AM. Reason: Asking SSCEE
- 04-30-2011, 09:47 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Does this help? This is the function where i plan on handling the count..
Java Code:public void updateNumbers() { int idx = jList1.getSelectedIndex(); try { int i = farray[idx].getName().indexOf(".class"); String cName = farray[idx].getName().substring(0,i); Class c = Class.forName(dir.getName() + "." + cName, true, ucl); // handle method counts // : // : // jColHeader.setText(...); (Used to show the count of each method) } catch (Exception ex) { System.out.println(ex); } }
Also this is a snipit of the "run button action performed"
Java Code:// Run button clicked void jButton4_actionPerformed(ActionEvent e) { LaunchingConnector lc = Bootstrap.virtualMachineManager().defaultConnector(); Map map = lc.defaultArguments(); Connector.Argument ca = (Connector.Argument) map.get("main"); int idx = jList1.getSelectedIndex(); try { int i = farray[idx].getName().indexOf(".class"); String cName = dir.getName() + "." + farray[idx].getName().substring(0, i); ca.setValue("-cp \"" + dir.getParentFile()+ "\" " + cName); vm = lc.launch(map); Process process = vm.process(); vm.setDebugTraceMode(VirtualMachine.TRACE_NONE); displayRemoteOutput(process.getInputStream()); mt = new MyThread(vm, false, dir.getName(), farray.length, this); } catch (Exception ex) { System.out.println(e); } } }Last edited by PataRican; 04-30-2011 at 09:56 PM.
- 05-01-2011, 11:24 AM #4
I would make some counterClass:
Then you make a static instance of this class, and increase/decrease it as needed:Java Code:package countmethods; import java.util.ArrayList; public class RunningClasses{ private ArrayList<ClassCounter> counters = new ArrayList<ClassCounter>(); public void addRunningClass( String theClassName ){ //add a counter, or increase if it exists } public void removeRunningClass( String theClassName ){ //decrease counter, or remove counter if numberLaunched==1 //errorcode if it doesn't exists } public int getNumberLaunched( String theClassName ){ int result = 0; //get the result return result; } class ClassCounter{ private String className; private int numberLauched; //some methods to check for name and adapt the count } }
Java Code:package countmethods; //import java.awt.event.ActionEvent;//added import java.io.File;//added //import java.util.Map;//added import javax.swing.JButton;//added import javax.swing.JList;//added public class SomeClass { private JButton jButton4;//added private JList jList1;//added private SomeArrayItem[] farray;//added private File dir;//added private ClassLoader ucl; private SomeVirtualMachine vm; private static RunningClasses runningCounts = new RunningClasses(); public void updateNumbers() { int idx = jList1.getSelectedIndex(); try { int i = farray[idx].getName().indexOf(".class"); String cName = farray[idx].getName().substring(0,i); Class c = Class.forName(dir.getName() + "." + cName, true, ucl); // handle method counts // : // : // jColHeader.setText(...); (Used to show the count of each method) } catch (Exception ex) { System.out.println(ex); } } public void simulateButtonClicked(){ String cName = "TestClass"; vm.launch( cName ); runningCounts.addRunningClass( cName ); } }
Similar Threads
-
Deterministic execution of Java Threads, tool support
By pulkittomar in forum Threads and SynchronizationReplies: 0Last Post: 03-16-2011, 05:30 AM -
double execution of a method
By matteo in forum AWT / SwingReplies: 0Last Post: 01-13-2011, 02:11 PM -
java UI web testing tool
By roanmv in forum Forum LobbyReplies: 1Last Post: 10-15-2009, 11:20 AM -
Timeout for a method execution
By pjmorce in forum Advanced JavaReplies: 2Last Post: 12-22-2008, 06:51 PM -
Method execution time
By javaplus in forum Advanced JavaReplies: 3Last Post: 11-26-2007, 09:51 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks