You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by le...@apache.org on 2004/07/22 07:07:26 UTC

svn commit: rev 23135 - excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager

Author: leif
Date: Wed Jul 21 22:07:26 2004
New Revision: 23135

Modified:
   excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/AbstractInstrumentSample.java
   excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/DefaultInstrumentManager.java
   excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentProxy.java
   excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentableProxy.java
Log:
Add additional instruments to track the objects internal to the instrument manager.
Fix some problems where instrument elements defined multiple times in the configuration file would cause problems.

Modified: excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/AbstractInstrumentSample.java
==============================================================================
--- excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/AbstractInstrumentSample.java	(original)
+++ excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/AbstractInstrumentSample.java	Wed Jul 21 22:07:26 2004
@@ -308,6 +308,8 @@
      */
     public long extendLease( long lease )
     {
+        m_instrumentProxy.getInstrumentableProxy().getInstrumentManager().incrementLeaseRequests();
+        
         synchronized( this )
         {
             // Only extend the lease if it is not permanent.
@@ -855,6 +857,14 @@
 
         // Propagate to the parent
         m_instrumentProxy.stateChanged();
+    }
+    
+    /**
+     * Called by the InstrumentProxy class during configuration to make the sample permanent.
+     */
+    void makePermanent()
+    {
+        m_leaseExpirationTime = 0;
     }
 
     /**

Modified: excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/DefaultInstrumentManager.java
==============================================================================
--- excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/DefaultInstrumentManager.java	(original)
+++ excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/DefaultInstrumentManager.java	Wed Jul 21 22:07:26 2004
@@ -67,6 +67,12 @@
     public static final String INSTRUMENT_FREE_MEMORY = "free-memory";
     public static final String INSTRUMENT_MEMORY = "memory";
     public static final String INSTRUMENT_ACTIVE_THREAD_COUNT = "active-thread-count";
+    public static final String INSTRUMENT_REGISTRATIONS = "instrumentable-registrations";
+    public static final String INSTRUMENT_INSTRUMENTABLES = "instrumentables";
+    public static final String INSTRUMENT_INSTRUMENTS = "instruments";
+    public static final String INSTRUMENT_SAMPLES = "samples";
+    public static final String INSTRUMENT_LEASED_SAMPLES = "leased-samples";
+    public static final String INSTRUMENT_LEASE_REQUESTS = "lease-requests";
     
     /** The name used to identify this InstrumentManager. */
     private String m_name;
@@ -128,6 +134,36 @@
     /** Instrument used to profile the active thread count of the JVM. */
     private ValueInstrument m_activeThreadCountInstrument;
     
+    /** Instrument to track the number of times registerInstrumentable is called. */
+    private CounterInstrument m_registrationsInstrument;
+
+    /** The Instrumentable count. */
+    private int m_instrumentableCount;
+    
+    /** Instrument used to track the number of Instrumentables in the system. */
+    private ValueInstrument m_instrumentablesInstrument;
+
+    /** The Instrument count. */
+    private int m_instrumentCount;
+
+    /** Instrument used to track the number of Instruments in the system. */
+    private ValueInstrument m_instrumentsInstrument;
+
+    /** The Permanent Instrument Sample count. */
+    private int m_permanentSampleCount;
+
+    /** The Leased Instrument Sample count. */
+    private int m_leasedSampleCount;
+
+    /** Instrument used to track the number of Instrument samples in the system. */
+    private ValueInstrument m_samplesInstrument;
+
+    /** Instrument used to track the number of Leased Instrument samples in the system. */
+    private ValueInstrument m_leasedSamplesInstrument;
+    
+    /** Instrument used to track the number of lease requests. */
+    private CounterInstrument m_leaseRequestsInstrument;
+    
     /** State Version. */
     private int m_stateVersion;
 
@@ -157,6 +193,12 @@
         m_freeMemoryInstrument = new ValueInstrument( INSTRUMENT_FREE_MEMORY );
         m_memoryInstrument = new ValueInstrument( INSTRUMENT_MEMORY );
         m_activeThreadCountInstrument = new ValueInstrument( INSTRUMENT_ACTIVE_THREAD_COUNT );
+        m_registrationsInstrument = new CounterInstrument( INSTRUMENT_REGISTRATIONS );
+        m_instrumentablesInstrument = new ValueInstrument( INSTRUMENT_INSTRUMENTABLES );
+        m_instrumentsInstrument = new ValueInstrument( INSTRUMENT_INSTRUMENTS );
+        m_samplesInstrument = new ValueInstrument( INSTRUMENT_SAMPLES );
+        m_leasedSamplesInstrument = new ValueInstrument( INSTRUMENT_LEASED_SAMPLES );
+        m_leaseRequestsInstrument = new CounterInstrument( INSTRUMENT_LEASE_REQUESTS );
     }
 
     /*---------------------------------------------------------------
@@ -172,6 +214,20 @@
     public void configure( Configuration configuration )
         throws ConfigurationException
     {
+        // Register the InstrumentManager as an Instrumentable.  This must be done before
+        //  the configuration and state file is loaded or our own instruments will not yet
+        //  have proxies.
+        try
+        {
+            registerInstrumentable( this, getInstrumentableName() );
+        }
+        catch ( Exception e )
+        {
+            // Should never happen
+            throw new ConfigurationException(
+                "Unable to register the InstrumentManager's own instruments.", e );
+        }
+
         synchronized( m_semaphore )
         {
             m_configuration = configuration;
@@ -189,15 +245,23 @@
                 Configuration instrumentableConf = instrumentableConfs[ i ];
                 String instrumentableName = instrumentableConf.getAttribute( "name" );
 
-                InstrumentableProxy instrumentableProxy = new InstrumentableProxy(
-                    this, null, instrumentableName, instrumentableName );
-                instrumentableProxy.enableLogging( getLogger() );
+                // See if the instrumentable already exists.
+                InstrumentableProxy instrumentableProxy =
+                    (InstrumentableProxy)m_instrumentableProxies.get( instrumentableName );
+                if ( instrumentableProxy == null )
+                {
+                    instrumentableProxy = new InstrumentableProxy(
+                        this, null, instrumentableName, instrumentableName );
+                    instrumentableProxy.enableLogging( getLogger() );
+                    incrementInstrumentableCount();
+                    m_instrumentableProxies.put( instrumentableName, instrumentableProxy );
+    
+                    // Clear the optimized arrays
+                    m_instrumentableProxyArray = null;
+                    m_instrumentableDescriptorArray = null;
+                }
+                // Always configure
                 instrumentableProxy.configure( instrumentableConf );
-                m_instrumentableProxies.put( instrumentableName, instrumentableProxy );
-
-                // Clear the optimized arrays
-                m_instrumentableProxyArray = null;
-                m_instrumentableDescriptorArray = null;
             }
 
             // Configure the state file.
@@ -301,9 +365,6 @@
     public void initialize()
         throws Exception
     {
-        // Register the InstrumentManager as an Instrumentable.
-        registerInstrumentable( this, getInstrumentableName() );
-
         if( m_runner == null )
         {
             m_runner = new Thread( this, "InstrumentManagerRunner" );
@@ -360,6 +421,8 @@
         throws Exception
     {
         getLogger().debug( "Registering Instrumentable: " + instrumentableName );
+        
+        m_registrationsInstrument.increment();
 
         synchronized( m_semaphore )
         {
@@ -374,12 +437,13 @@
                     instrumentableName.substring( pos + 1 );
                 InstrumentableProxy instrumentableProxy =
                     (InstrumentableProxy)m_instrumentableProxies.get( parentName );
-                if( instrumentableProxy == null )
+                if ( instrumentableProxy == null )
                 {
                     // This is a Instrumentable that has not been seen before.
                     instrumentableProxy = new InstrumentableProxy(
                         this, null, parentName, parentName );
                     instrumentableProxy.enableLogging( getLogger() );
+                    incrementInstrumentableCount();
                     // Do not call configure here because there is no configuration
                     //  for discovered instrumentables.
                     m_instrumentableProxies.put( parentName, instrumentableProxy );
@@ -411,6 +475,7 @@
                     instrumentableProxy = new InstrumentableProxy(
                         this, null, instrumentableName, instrumentableName );
                     instrumentableProxy.enableLogging( getLogger() );
+                    incrementInstrumentableCount();
                     // Do not call configure here because there is no configuration
                     //  for discovered instrumentables.
                     m_instrumentableProxies.put( instrumentableName, instrumentableProxy );
@@ -700,6 +765,7 @@
                 instrumentableProxy = new InstrumentableProxy(
                     this, null, instrumentableName, instrumentableName );
                 instrumentableProxy.enableLogging( getLogger() );
+                incrementInstrumentableCount();
                 m_instrumentableProxies.put( instrumentableName, instrumentableProxy );
 
                 // Clear the optimized arrays
@@ -885,7 +951,13 @@
             m_totalMemoryInstrument,
             m_freeMemoryInstrument,
             m_memoryInstrument,
-            m_activeThreadCountInstrument
+            m_activeThreadCountInstrument,
+            m_registrationsInstrument,
+            m_instrumentablesInstrument,
+            m_instrumentsInstrument,
+            m_samplesInstrument,
+            m_leasedSamplesInstrument,
+            m_leaseRequestsInstrument
         };
     }
 
@@ -1252,6 +1324,7 @@
                 proxy = new InstrumentableProxy(
                     this, instrumentableProxy, fullChildName, newParentName );
                 proxy.enableLogging( getLogger() );
+                incrementInstrumentableCount();
                 
                 instrumentableProxy.addChildInstrumentableProxy( proxy );
             }
@@ -1274,6 +1347,7 @@
                 proxy = new InstrumentableProxy(
                     this, instrumentableProxy, fullChildName, childName );
                 proxy.enableLogging( getLogger() );
+                incrementInstrumentableCount();
                 
                 instrumentableProxy.addChildInstrumentableProxy( proxy );
             }
@@ -1314,6 +1388,7 @@
                 proxy = new InstrumentProxy(
                     instrumentableProxy, fullInstrumentName, instrumentName );
                 proxy.enableLogging( getLogger() );
+                incrementInstrumentCount();
 
                 // Set the type of the new InstrumentProxy depending on the
                 //  class of the actual Instrument.
@@ -1433,6 +1508,7 @@
                 proxy = new InstrumentableProxy(
                     this, instrumentableProxy, fullChildName, childName );
                 proxy.enableLogging( getLogger() );
+                incrementInstrumentableCount();
                 
                 instrumentableProxy.addChildInstrumentableProxy( proxy );
             }
@@ -1448,6 +1524,85 @@
     protected void stateChanged()
     {
         m_stateVersion++;
+    }
+    
+    /**
+     * Called to increment the number of Instrumentables registered.
+     */
+    protected void incrementInstrumentableCount()
+    {
+        int count;
+        synchronized( m_semaphore )
+        {
+            count = ++m_instrumentableCount;
+        }
+        m_instrumentablesInstrument.setValue( count );
+    }
+    
+    /**
+     * Called to increment the number of Instruments registered.
+     */
+    protected void incrementInstrumentCount()
+    {
+        int count;
+        synchronized( m_semaphore )
+        {
+            count = ++m_instrumentCount;
+        }
+        m_instrumentsInstrument.setValue( count );
+    }
+    
+    /**
+     * Called to increment the number of Permanent Instrument Samples registered.
+     */
+    protected void incrementPermanentSampleCount()
+    {
+        int count;
+        synchronized( m_semaphore )
+        {
+            count = ++m_permanentSampleCount + m_leasedSampleCount;
+        }
+        m_samplesInstrument.setValue( count );
+    }
+    
+    /**
+     * Called to increment the number of Leased Instrument Samples registered.
+     */
+    protected void incrementLeasedSampleCount()
+    {
+        int count;
+        int leasedCount;
+        synchronized( m_semaphore )
+        {
+            leasedCount = ++m_leasedSampleCount;
+            count = m_permanentSampleCount + m_leasedSampleCount;
+        }
+        m_samplesInstrument.setValue( count );
+        m_leasedSamplesInstrument.setValue( leasedCount );
+    }
+    
+    /**
+     * Called to decrement the number of Leased Instrument Samples registered.
+     */
+    protected void decrementLeasedSampleCount()
+    {
+        int count;
+        int leasedCount;
+        synchronized( m_semaphore )
+        {
+            leasedCount = --m_leasedSampleCount;
+            count = m_permanentSampleCount + m_leasedSampleCount;
+        }
+        m_samplesInstrument.setValue( count );
+        m_leasedSamplesInstrument.setValue( leasedCount );
+    }
+    
+    /**
+     * Increment the lease requests.
+     */
+    protected void incrementLeaseRequests()
+    {
+        m_leaseRequestsInstrument.increment();
     }
 }
 

Modified: excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentProxy.java
==============================================================================
--- excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentProxy.java	(original)
+++ excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentProxy.java	Wed Jul 21 22:07:26 2004
@@ -181,13 +181,42 @@
                         " as \"" + sampleDescription + "\"" );
                 }
                 
-                AbstractInstrumentSample instrumentSample = 
-                    (AbstractInstrumentSample)InstrumentSampleFactory.getInstrumentSample( this,
-                    sampleType, sampleName, sampleInterval, sampleSize, sampleDescription, 0 );
-                instrumentSample.enableLogging( getLogger() );
-                instrumentSample.setConfigured();
-                
-                addInstrumentSample( instrumentSample );
+                // See if the sample already exists.
+                String fullSampleName = InstrumentSampleUtils.generateFullInstrumentSampleName(
+                    m_name, sampleType, sampleInterval, sampleSize );
+                InstrumentSample sample = getInstrumentSample( fullSampleName );
+                if ( sample == null )
+                {
+                    AbstractInstrumentSample instrumentSample = 
+                        (AbstractInstrumentSample)InstrumentSampleFactory.getInstrumentSample( this,
+                        sampleType, sampleName, sampleInterval, sampleSize, sampleDescription, 0 );
+                    instrumentSample.enableLogging( getLogger() );
+                    instrumentSample.setConfigured();
+                                
+                    addInstrumentSample( instrumentSample );
+                }
+                else
+                {
+                    // Sample already existed.
+                    if ( sample instanceof AbstractInstrumentSample )
+                    {
+                        AbstractInstrumentSample instrumentSample =
+                            (AbstractInstrumentSample)sample;
+                        instrumentSample.setConfigured();
+                        // If the sample already existed we will need to make it permanent.
+                        instrumentSample.makePermanent();
+                    }
+                    else
+                    {
+                        // Should never happen with normal operation but an error is better than
+                        //  silently failing.
+                        getLogger().warn(
+                            "Instrument sample was configured but already existed and "
+                            + "could not be cast to an AbstractInstrumentSample.  "
+                            + "Name: " + fullSampleName + ", Class: "
+                            + sample.getClass().getName() );
+                    }
+                }
             }
         }
     }
@@ -576,6 +605,15 @@
             }
         }
         
+        if ( instrumentSample.getLeaseExpirationTime() == 0 )
+        {
+            m_instrumentableProxy.getInstrumentManager().incrementPermanentSampleCount();
+        }
+        else
+        {
+            m_instrumentableProxy.getInstrumentManager().incrementLeasedSampleCount();
+        }
+        
         stateChanged();
     }
 
@@ -612,6 +650,8 @@
             m_sampleDescriptorArray = null;
         }
         
+        m_instrumentableProxy.getInstrumentManager().decrementLeasedSampleCount();
+        
         stateChanged();
     }
     
@@ -699,6 +739,8 @@
                     sampleDescription, sampleLease );
                 instrumentSample.enableLogging( getLogger() );
                 
+                m_instrumentableProxy.getInstrumentManager().incrementLeaseRequests();
+                
                 addInstrumentSample( instrumentSample );
                 
                 // Register the new sample with the InstrumentManager
@@ -980,12 +1022,15 @@
                         String sampleDescription =
                             instrumentSampleConf.getAttribute( "description", sampleName );
                         
+                        // Create the sample with a permanent expiration time.  The correct
+                        //  expiration time will be set when its state is loaded.
                         AbstractInstrumentSample instrumentSample = 
                             (AbstractInstrumentSample)InstrumentSampleFactory.getInstrumentSample(
                             this, sampleType, fullSampleName, sampleInterval, sampleSize,
                             sampleDescription, 0 );
                         instrumentSample.enableLogging( getLogger() );
                         instrumentSample.loadState( instrumentSampleConf );
+                        
                         addInstrumentSample( instrumentSample );
                     }
                     else

Modified: excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentableProxy.java
==============================================================================
--- excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentableProxy.java	(original)
+++ excalibur/trunk/containerkit/instrument-manager/impl/src/java/org/apache/excalibur/instrument/manager/InstrumentableProxy.java	Wed Jul 21 22:07:26 2004
@@ -146,16 +146,23 @@
                 Configuration childConf = childConfs[ i ];
                 String childName = childConf.getAttribute( "name" );
                 String fullChildName = m_name + "." + childName;
-
-                InstrumentableProxy childProxy = new InstrumentableProxy(
-                    m_instrumentManager, this, fullChildName, childName );
-                childProxy.enableLogging( getLogger() );
+                
+                // See if the instrumentable already exists.
+                InstrumentableProxy childProxy = getChildInstrumentableProxy( fullChildName );
+                if( childProxy == null )
+                {
+                    childProxy = new InstrumentableProxy(
+                        m_instrumentManager, this, fullChildName, childName );
+                    childProxy.enableLogging( getLogger() );
+                    m_instrumentManager.incrementInstrumentableCount();
+                    m_childInstrumentableProxies.put( fullChildName, childProxy );
+    
+                    // Clear the optimized arrays
+                    m_childInstrumentableProxyArray = null;
+                    m_childInstrumentableDescriptorArray = null;
+                }
+                // Always configure the instrumentable.
                 childProxy.configure( childConf );
-                m_childInstrumentableProxies.put( fullChildName, childProxy );
-
-                // Clear the optimized arrays
-                m_childInstrumentableProxyArray = null;
-                m_childInstrumentableDescriptorArray = null;
             }
             
             // Configure any Instruments
@@ -166,15 +173,22 @@
                 String instrumentName = instrumentConf.getAttribute( "name" );
                 String fullInstrumentName = m_name + "." + instrumentName;
 
-                InstrumentProxy instrumentProxy =
-                    new InstrumentProxy( this, fullInstrumentName, instrumentName );
-                instrumentProxy.enableLogging( getLogger() );
+                // See if the instrument already exists.
+                InstrumentProxy instrumentProxy = getInstrumentProxy( fullInstrumentName );
+                if ( instrumentProxy == null )
+                {
+                    instrumentProxy =
+                        new InstrumentProxy( this, fullInstrumentName, instrumentName );
+                    instrumentProxy.enableLogging( getLogger() );
+                    m_instrumentManager.incrementInstrumentCount();
+                    m_instrumentProxies.put( fullInstrumentName, instrumentProxy );
+    
+                    // Clear the optimized arrays
+                    m_instrumentProxyArray = null;
+                    m_instrumentDescriptorArray = null;
+                }
+                // Always configure the instrument
                 instrumentProxy.configure( instrumentConf );
-                m_instrumentProxies.put( fullInstrumentName, instrumentProxy );
-
-                // Clear the optimized arrays
-                m_instrumentProxyArray = null;
-                m_instrumentDescriptorArray = null;
             }
         }
     }
@@ -687,6 +701,7 @@
                     childProxy = new InstrumentableProxy(
                         m_instrumentManager, this, fullChildName, childName );
                     childProxy.enableLogging( getLogger() );
+                    m_instrumentManager.incrementInstrumentableCount();
                     m_childInstrumentableProxies.put( fullChildName, childProxy );
     
                     // Clear the optimized arrays
@@ -714,6 +729,7 @@
                     instrumentProxy =
                         new InstrumentProxy( this, fullInstrumentName, instrumentName );
                     instrumentProxy.enableLogging( getLogger() );
+                    m_instrumentManager.incrementInstrumentCount();
                     m_instrumentProxies.put( fullInstrumentName, instrumentProxy );
     
                     // Clear the optimized arrays

---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org