|
From: Lukas P. <pe...@us...> - 2002-07-29 16:45:00
|
Update of /cvsroot/javaprofiler/test/module
In directory usw-pr-cvs1:/tmp/cvs-serv30814
Modified Files:
MainThreads.java
Log Message:
using ActiveThreadsView component
Index: MainThreads.java
===================================================================
RCS file: /cvsroot/javaprofiler/test/module/MainThreads.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** MainThreads.java 26 Jul 2002 09:38:19 -0000 1.3
--- MainThreads.java 29 Jul 2002 16:44:57 -0000 1.4
***************
*** 1,109 ****
! //package net.sourceforge.javaprofiler.module.views;
!
! import javax.swing.*;
! import javax.swing.event.ChangeListener;
! import javax.swing.event.ChangeEvent;
! import java.awt.*;
! import java.awt.event.*;
! import java.util.Timer;
! import java.util.TimerTask;
!
! import net.sourceforge.javaprofiler.jpiimpl.commun.*;
! import net.sourceforge.javaprofiler.jpiimpl.realtime.*;
import net.sourceforge.javaprofiler.module.views.*;
!
! /** Example of using TimeSeriesGraph to show number of running threads.
! * Please supply the name of profiled computer as a command-line parameter.
! * Default: localhost
! * @author Lukas Petru
! */
! public class MainThreads
! {
! static TimeSeriesGraph component;
!
! public static void main (String[] args) {
! connectAndRun(args);
! }
!
! private static void launchGui (final ImageR image, final IProf iprof) {
! JFrame frame=new JFrame("Main");
! frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
! frame.addWindowListener(new WindowAdapter() {
! public void windowClosing(WindowEvent e) {
! iprof.stop();
! System.exit(0);
! }
! });
!
! component=new TimeSeriesGraph();
! component.setBorder(BorderFactory.createLineBorder(Color.yellow));
! frame.getContentPane().add(component, BorderLayout.NORTH);
!
! final TimeSeriesModel m=component.getModel();
! final JLabel label1=new JLabel("curr: 000");
! final JLabel label2=new JLabel("max: 000");
! m.addChangeListener(new ChangeListener() {
! public void stateChanged(ChangeEvent e) {
! label1.setText("curr: " + m.getLast());
! label2.setText("max: " + m.getMax());
! }
! });
! JPanel sPanel=new JPanel();
! sPanel.add(label2);
! sPanel.add(label1);
! frame.getContentPane().add(sPanel, BorderLayout.SOUTH);
!
! frame.pack();
! frame.show();
!
! // Using java.util.Timer instead that of swing, because we don't
! // want the task to run in the event-dispatching thread.
! Timer timer=new Timer();
! TimerTask task=new TimerTask() {
! public void run() {
! final TimeSeriesModel m=component.getModel();
! image.refreshThreads();
! // get last value
! final int val=image.getThreads().size();
! // set data in event-dispatching thread
! SwingUtilities.invokeLater(new Runnable() {
! public void run() {
! m.shift(val);
! }
! });
! }
! };
! timer.schedule(task, 1000, 500);
! }
!
! private static ImageR getImage(IProf iprof) {
! ImageR image=new ImageR(iprof, false);
! return image;
! }
!
! private static IProf connect (String hostName) {
! IProf iprof = new IProf(new CommunSetupSocket(CommunSetupSocket.
! CLIENT_MODE, hostName, 25595));
! try {
! iprof.run();
! return iprof;
! } catch (IProfException e) {
! System.out.println(e);
! return null;
! }
! }
!
! private static void connectAndRun(String[] arg) {
! String hostName = "localhost";
! if (arg.length >= 1)
! hostName = arg[0];
! System.out.println("host: " + hostName);
!
! IProf iprof = connect(hostName);
! if (iprof != null) {
! ImageR image=getImage(iprof);
! launchGui(image, iprof);
! }
! else System.out.println("Error connecting.");
! }
! }
--- 1,113 ----
! /*
! * Sun Public License Notice
! *
! * The contents of this file are subject to the Sun Public License
! * Version 1.0 (the "License"); you may not use this file except
! * in compliance with the License. A copy of the License is available
! * at http://www.sun.com/
! *
! * The Original Code is the Java Profiler module. The Initial Developers
! * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
! * Lukas Petru and Marek Przeczek.
! *
! * Portions created by Jan Stola are Copyright (C) 2000-2001.
! * All Rights Reserved.
! *
! * Portions created by Pavel Vacha are Copyright (C) 2000-2001.
! * All Rights Reserved.
! *
! * Portions created by Michal Pise are Copyright (C) 2000-2001.
! * All Rights Reserved.
! *
! * Portions created by Petr Luner are Copyright (C) 2000-2001.
! * All Rights Reserved.
! *
! * Portions created by Lukas Petru are Copyright (C) 2000-2001.
! * All Rights Reserved.
! *
! * Portions created by Marek Przeczek are Copyright (C) 2000-2001.
! * All Rights Reserved.
! *
! * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner,
! * Lukas Petru and Marek Przeczek.
! */
!
! import javax.swing.*;
! import javax.swing.event.ChangeListener;
! import javax.swing.event.ChangeEvent;
! import java.awt.*;
! import java.awt.event.*;
! import java.util.Timer;
! import java.util.TimerTask;
! import java.util.Iterator;
!
! import net.sourceforge.javaprofiler.jpiimpl.commun.*;
! import net.sourceforge.javaprofiler.jpiimpl.realtime.*;
import net.sourceforge.javaprofiler.module.views.*;
!
! /** Example of using TimeSeriesGraph to show number of running threads.
! * Please supply the name of profiled computer as a command-line parameter.
! * Default: localhost
! * @author Lukas Petru
! */
! public class MainThreads
! {
!
! public static void main (String[] args) {
! connectAndRun(args);
! }
!
! private static void launchGui (final ImageR image, final IProf iprof) {
! JFrame frame=new JFrame("Active threads");
! frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
! frame.addWindowListener(new WindowAdapter() {
! public void windowClosing(WindowEvent e) {
! try {
! iprof.shutdown();
! } catch (IProfException ex) {}
! iprof.stop();
! System.exit(0);
! }
! });
!
! ActiveThreadsView view=new ActiveThreadsView(image);
! frame.getContentPane().add(view, BorderLayout.CENTER);
!
! frame.pack();
! frame.show();
!
! Timer timer=new Timer();
! timer.schedule(view.getTimerTask(), 500, 500);
! }
!
! private static ImageR getImage(IProf iprof) {
! ImageR image=new ImageR(iprof, false);
! return image;
! }
!
! private static IProf connect (String hostName) {
! IProf iprof = new IProf(new CommunSetupSocket(CommunSetupSocket.
! CLIENT_MODE, hostName, 25595));
! try {
! iprof.run();
! return iprof;
! } catch (IProfException e) {
! System.out.println(e);
! return null;
! }
! }
!
! private static void connectAndRun(String[] arg) {
! String hostName = "localhost";
! if (arg.length >= 1)
! hostName = arg[0];
! System.out.println("host: " + hostName);
!
! IProf iprof = connect(hostName);
! if (iprof != null) {
! ImageR image=getImage(iprof);
! launchGui(image, iprof);
! }
! else System.out.println("Error connecting.");
! }
! }
|