OVH Cloud OVH Cloud

panel visualisant l'occpation Mémoire

7 réponses
Avatar
Jean-Marie
Bonjour

je cherche un programme (c'est peut-être un objet
swing mais j'ai pas trouvé) visualisant graphiquement
l'évolution de l'occupation mémoire par une application java

merci

Jean-Marie

7 réponses

Avatar
dnasmars
Salut,

gcviewer
http://www.tagtraum.com/index.html
je le trouve excellent
bon courage

Jean-Marie wrote:
Bonjour

je cherche un programme (c'est peut-être un objet
swing mais j'ai pas trouvé) visualisant graphiquement
l'évolution de l'occupation mémoire par une application java

merci

Jean-Marie


Avatar
Jean-Marie
merci pour l'info

mais je cherche une interface plus simple
comme une sorte de vueMetre donnant à intervalles réguliers
le nb de ko utilisés et le nb de ko alloués,
et que l'utilisateur peut afficher à partir
de l'application Java qu'il utilise

dnasmars wrote:
Salut,

gcviewer
http://www.tagtraum.com/index.html
je le trouve excellent
bon courage

Jean-Marie wrote:

Bonjour

je cherche un programme (c'est peut-être un objet
swing mais j'ai pas trouvé) visualisant graphiquement
l'évolution de l'occupation mémoire par une application java

merci

Jean-Marie




Avatar
jlp
merci pour l'info

mais je cherche une interface plus simple
comme une sorte de vueMetre donnant à intervalles réguliers
le nb de ko utilisés et le nb de ko alloués,
et que l'utilisateur peut afficher à partir
de l'application Java qu'il utilise

dnasmars wrote:

Salut,

gcviewer
http://www.tagtraum.com/index.html
je le trouve excellent
bon courage

Jean-Marie wrote:

Bonjour

je cherche un programme (c'est peut-être un objet
swing mais j'ai pas trouvé) visualisant graphiquement
l'évolution de l'occupation mémoire par une application java

merci

Jean-Marie
La classe Runtime fournit les méthodes :



freeMemory(), maxMemory(), totalMemory()
qui permettent d'obtenir les informations.
Après il faut se retrousser les manches pour afficcher cela dans des
gauges, des thermometres ou autres sliders. Voir bibliothèque JFreeChart
qui offre ce genre d'objet => www.jfree.org.
On peut aussi se contenter d'afficher ces résultats dans des TextField(s).
Nota : si on veut des rafraichissements périodiques, il faudra
programmer cela dans un thread spécifique pour cet affichage pour ne pas
perturber le/les threads applicatifs principaux.



Avatar
Simon OUALID
La classe Runtime fournit les méthodes :
freeMemory(), maxMemory(), totalMemory()
qui permettent d'obtenir les informations.
Après il faut se retrousser les manches pour afficcher cela dans des
gauges, des thermometres ou autres sliders.



Ouaip, voici comment on a implémenté ça sur nos clients swing, si tu
veux t'en inspirer ... (désolé pour l'indentation en 8, c'est pas top
pour les mails !).

Symon


/*
* Created on 29 déc. 2004
*/
package fr.artefrance.commun.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;

import javax.swing.BorderFactory;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import fr.artefrance.commun.outils.AFLogger;

/**
* Memory Monitor used for profiling purposes.
*
* @author f-thibaut
*/
public class AFMemoryMonitorPanel extends AFPanel
{

/** Monitor Thread */
private MemoryUsageThread memoryUsageThread;

private JProgressBar progressBarMemory;
private AFLabel totalMemoryLabel;
private AFLabel usedMemoryLabel;
private final static AFMemoryMonitorPanel aMemoryMonitor = new
AFMemoryMonitorPanel();
private final static AFLogger logger = new AFLogger(
AFMemoryMonitorPanel.class );

/**
* Thread used for memory monitoring
*/
private class MemoryUsageThread extends Thread
{

/**
* Constructor for MemoryUsageThread.
*/
public MemoryUsageThread()
{
super( "Memory-Monitor" );
}

/**
* @see java.lang.Runnable#run()
*/
public void run()
{
NumberFormat nf = NumberFormat.getNumberInstance();
while ( true )
{
try
{
long total = Runtime.getRuntime().totalMemory();
long used = total - Runtime.getRuntime().freeMemory();
totalMemoryLabel.setText( nf.format( total / 1000 ) + " Ko" );
usedMemoryLabel.setText( nf.format( used / 1000 ) + " Ko" );
progressBarMemory.setMaximum( ( int ) total );
progressBarMemory.setValue( ( int ) used );
// invoke a repaint using SwingUtilities ?
super.sleep( 2000 );
}
catch ( InterruptedException ie )
{
// Stop the Thread
break;
}
}
}
}

/**
* Constructor for MemoryMonitor.
*/
public AFMemoryMonitorPanel()
{
super();
initialize();
}

/**
* Show the MemoryMonitor
*/
public static void showMonitor( Frame parent )
{
aMemoryMonitor.start();

new AFGenericInformationDialog( parent, "Monitoring de la Mémoire",
false )
{

/**
* @see
fr.artefrance.commun.gui.AFGenericInformationDialog#getComponentToDisplay()
*/
public Component getComponentToDisplay()
{
return aMemoryMonitor;
}

};

aMemoryMonitor.stop();
}

/**
* Garbage Collection invoked
*/
private void invokeGC()
{
Runtime.getRuntime().gc();
}

/**
* Start monitor
*/
private void start()
{
memoryUsageThread = new MemoryUsageThread();
memoryUsageThread.start();
}

/**
* Stop monitor
*/
private void stop()
{
memoryUsageThread = null;
}

/**
* This method initializes this
*
* @return void
*/
private void initialize()
{
setLayout( new GridBagLayout() );

GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.WEST;
gc.fill = GridBagConstraints.NONE;
gc.insets = new Insets( 4, 4, 4, 4 );

// LABELS
add( new AFLabel( "Mémoire Totale", SwingConstants.LEFT ), gc );

gc.gridx++;
gc.fill = GridBagConstraints.HORIZONTAL;

add( totalMemoryLabel = new AFLabel(), gc );

gc.gridx = 0;
gc.gridy++;
gc.fill = GridBagConstraints.NONE;

add( new AFLabel( "Mémoire Utilisée", SwingConstants.LEFT ), gc );

gc.gridx++;
gc.fill = GridBagConstraints.HORIZONTAL;

add( usedMemoryLabel = new AFLabel(), gc );

gc.gridx = 0;
gc.gridy++;
gc.gridwidth = 2;

// PROGRESS BAR MEMORY
progressBarMemory = new JProgressBar();
progressBarMemory.setStringPainted( true );
progressBarMemory.setOrientation( SwingConstants.HORIZONTAL );
progressBarMemory.setBackground( Color.WHITE );
add( progressBarMemory, gc );

gc.gridx = 0;
gc.gridy++;

// GC BUTTON
AFButton buttonGC = new AFButton( "Garbage Collecting" );
buttonGC.setToolTipText( "Invoque le Garbage Collector" );
buttonGC.addActionListener( new ActionListener()
{

/**
* @see
java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed( ActionEvent arg0 )
{
invokeGC();
}
} );
add( buttonGC, gc );

setBorder( BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Utilisation de la mémoire",
TitledBorder.LEFT, TitledBorder.TOP, new Font( "Sans Serif", Font.BOLD,
11 ) ) );
}

}

Avatar
Syrion
Hep bonhomme ton thread ne doit pas perturber le reste de l'appli comme
jlp l'a dit dont avant le start() il faut un setDaemon(true)
;)



La classe Runtime fournit les méthodes :
freeMemory(), maxMemory(), totalMemory()
qui permettent d'obtenir les informations.
Après il faut se retrousser les manches pour afficcher cela dans des
gauges, des thermometres ou autres sliders.




Ouaip, voici comment on a implémenté ça sur nos clients swing, si tu
veux t'en inspirer ... (désolé pour l'indentation en 8, c'est pas top
pour les mails !).

Symon


/*
* Created on 29 déc. 2004
*/
package fr.artefrance.commun.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;

import javax.swing.BorderFactory;
import javax.swing.JProgressBar;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import fr.artefrance.commun.outils.AFLogger;

/**
* Memory Monitor used for profiling purposes.
*
* @author f-thibaut
*/
public class AFMemoryMonitorPanel extends AFPanel
{

/** Monitor Thread */
private MemoryUsageThread memoryUsageThread;

private JProgressBar progressBarMemory;
private AFLabel totalMemoryLabel;
private AFLabel usedMemoryLabel;
private final static AFMemoryMonitorPanel aMemoryMonitor = new
AFMemoryMonitorPanel();
private final static AFLogger logger = new
AFLogger( AFMemoryMonitorPanel.class );

/**
* Thread used for memory monitoring
*/
private class MemoryUsageThread extends Thread
{

/**
* Constructor for MemoryUsageThread.
*/
public MemoryUsageThread()
{
super( "Memory-Monitor" );
}

/**
* @see java.lang.Runnable#run()
*/
public void run()
{
NumberFormat nf = NumberFormat.getNumberInstance();
while ( true )
{
try
{
long total = Runtime.getRuntime().totalMemory();
long used = total - Runtime.getRuntime().freeMemory();
totalMemoryLabel.setText( nf.format( total / 1000 )
+ " Ko" );
usedMemoryLabel.setText( nf.format( used / 1000 ) +
" Ko" );
progressBarMemory.setMaximum( ( int ) total );
progressBarMemory.setValue( ( int ) used );
// invoke a repaint using SwingUtilities ?
super.sleep( 2000 );
}
catch ( InterruptedException ie )
{
// Stop the Thread
break;
}
}
}
}

/**
* Constructor for MemoryMonitor.
*/
public AFMemoryMonitorPanel()
{
super();
initialize();
}

/**
* Show the MemoryMonitor
*/
public static void showMonitor( Frame parent )
{
aMemoryMonitor.start();

new AFGenericInformationDialog( parent, "Monitoring de la
Mémoire", false )
{

/**
* @see
fr.artefrance.commun.gui.AFGenericInformationDialog#getComponentToDisplay()
*/
public Component getComponentToDisplay()
{
return aMemoryMonitor;
}

};

aMemoryMonitor.stop();
}

/**
* Garbage Collection invoked
*/
private void invokeGC()
{
Runtime.getRuntime().gc();
}

/**
* Start monitor
*/
private void start()
{
memoryUsageThread = new MemoryUsageThread();
memoryUsageThread.start();
}

/**
* Stop monitor
*/
private void stop()
{
memoryUsageThread = null;
}

/**
* This method initializes this
*
* @return void
*/
private void initialize()
{
setLayout( new GridBagLayout() );

GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.WEST;
gc.fill = GridBagConstraints.NONE;
gc.insets = new Insets( 4, 4, 4, 4 );

// LABELS
add( new AFLabel( "Mémoire Totale", SwingConstants.LEFT ), gc );

gc.gridx++;
gc.fill = GridBagConstraints.HORIZONTAL;

add( totalMemoryLabel = new AFLabel(), gc );

gc.gridx = 0;
gc.gridy++;
gc.fill = GridBagConstraints.NONE;

add( new AFLabel( "Mémoire Utilisée", SwingConstants.LEFT ), gc );

gc.gridx++;
gc.fill = GridBagConstraints.HORIZONTAL;

add( usedMemoryLabel = new AFLabel(), gc );

gc.gridx = 0;
gc.gridy++;
gc.gridwidth = 2;

// PROGRESS BAR MEMORY
progressBarMemory = new JProgressBar();
progressBarMemory.setStringPainted( true );
progressBarMemory.setOrientation( SwingConstants.HORIZONTAL );
progressBarMemory.setBackground( Color.WHITE );
add( progressBarMemory, gc );

gc.gridx = 0;
gc.gridy++;

// GC BUTTON
AFButton buttonGC = new AFButton( "Garbage Collecting" );
buttonGC.setToolTipText( "Invoque le Garbage Collector" );
buttonGC.addActionListener( new ActionListener()
{

/**
* @see
java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed( ActionEvent arg0 )
{
invokeGC();
}
} );
add( buttonGC, gc );

setBorder( BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "Utilisation de la mémoire",
TitledBorder.LEFT, TitledBorder.TOP, new Font( "Sans Serif", Font.BOLD,
11 ) ) );
}

}



Avatar
Simon OUALID
Tiens, je ne savais pas... et ça n'a jamais posé de problème, pourtant
ce code est en production depuis quasiment un an. Pour moi, le fait
d'utiliser un thread distinct pour cette tache suffisait.

Dans la doc de Thread.setDaemon(boolean on), je lis :

"Marks this thread as either a daemon thread or a user thread. The Java
Virtual Machine exits when the only threads running are all daemon threads.

This method must be called before the thread is started.

This method first calls the checkAccess method of this thread with no
arguments. This may result in throwing a SecurityException (in the
current thread)."

Dans la mesure ou on sort systématiquement avec un System.exit(0) final
du client Swing, est ce que ça pose vraiment problème ?

Comme quoi ça sert toujours de partager un peu de code, personne dans
l'équipe n'avait remonté cet éventuel problème.

Merci, "bonhomme" ! :)

Symon

Syrion wrote:
Hep bonhomme ton thread ne doit pas perturber le reste de l'appli comme
jlp l'a dit dont avant le start() il faut un setDaemon(true)
;)



Avatar
Jean-Marie
Merci à tous pour ces informations !

Jean-Marie

Simon OUALID wrote:
Tiens, je ne savais pas... et ça n'a jamais posé de problème, pourtant
ce code est en production depuis quasiment un an. Pour moi, le fait
d'utiliser un thread distinct pour cette tache suffisait.

Dans la doc de Thread.setDaemon(boolean on), je lis :

"Marks this thread as either a daemon thread or a user thread. The Java
Virtual Machine exits when the only threads running are all daemon threads.

This method must be called before the thread is started.

This method first calls the checkAccess method of this thread with no
arguments. This may result in throwing a SecurityException (in the
current thread)."

Dans la mesure ou on sort systématiquement avec un System.exit(0) final
du client Swing, est ce que ça pose vraiment problème ?

Comme quoi ça sert toujours de partager un peu de code, personne dans
l'équipe n'avait remonté cet éventuel problème.

Merci, "bonhomme" ! :)

Symon

Syrion wrote:

Hep bonhomme ton thread ne doit pas perturber le reste de l'appli
comme jlp l'a dit dont avant le start() il faut un setDaemon(true)
;)