Chat Support
Loupe - Log - Monitor - Resolve
Gibraltar.Agent.PostSharp Namespace / GTimer Class
Members Example

In This Topic
    GTimer Class
    In This Topic
    A PostSharp aspect that will log execution time for methods. Data is stored as a Gibraltar metric allowing charting and graphing in Gibraltar Analyst.
    Syntax
    'Declaration
     
    
    <DebuggerNonUserCodeAttribute()>
    <PostSharp.Extensibility.MulticastAttributeUsageAttribute(MulticastTargets.Constructor Or  _
        MulticastTargets.InstanceConstructor Or  _
        MulticastTargets.Method Or  _
        MulticastTargets.StaticConstructor, 
       AllowMultiple=True, 
       TargetMemberAttributes=MulticastAttributes.NonAbstract)>
    <PostSharp.Serialization.SerializerAttribute()>
    <PostSharp.Aspects.Configuration.AspectConfigurationAttributeTypeAttribute(PostSharp.Aspects.Configuration.OnMethodBoundaryAspectConfigurationAttribute)>
    <AttributeUsageAttribute(AttributeTargets.Assembly Or  _
        AttributeTargets.Class Or  _
        AttributeTargets.Constructor Or  _
        AttributeTargets.Event Or  _
        AttributeTargets.Interface Or  _
        AttributeTargets.Method Or  _
        AttributeTargets.Property Or  _
        AttributeTargets.Struct, 
       AllowMultiple=True, 
       Inherited=False)>
    <PostSharp.Extensibility.HasInheritedAttributeAttribute()>
    <XmlTypeAttribute("http://schemas.postsharp.net/2.0/aspects")>
    <SerializableAttribute()>
    Public NotInheritable Class GTimer 
       Inherits GAspectBase
       Implements Gibraltar.Agent.IMessageSourceProvider, PostSharp.Aspects.IAspect, PostSharp.Aspects.IAspectBuildSemantics, PostSharp.Aspects.IMethodLevelAspect, PostSharp.Aspects.IMethodLevelAspectBuildSemantics, PostSharp.Aspects.IOnMethodBoundaryAspect, PostSharp.Extensibility.IValidableAnnotation 
    [DebuggerNonUserCode()]
    [PostSharp.Extensibility.MulticastAttributeUsage(MulticastTargets.Constructor | 
        MulticastTargets.InstanceConstructor | 
        MulticastTargets.Method | 
        MulticastTargets.StaticConstructor, 
       AllowMultiple=true, 
       TargetMemberAttributes=MulticastAttributes.NonAbstract)]
    [PostSharp.Serialization.Serializer()]
    [PostSharp.Aspects.Configuration.AspectConfigurationAttributeType(PostSharp.Aspects.Configuration.OnMethodBoundaryAspectConfigurationAttribute)]
    [AttributeUsage(AttributeTargets.Assembly | 
        AttributeTargets.Class | 
        AttributeTargets.Constructor | 
        AttributeTargets.Event | 
        AttributeTargets.Interface | 
        AttributeTargets.Method | 
        AttributeTargets.Property | 
        AttributeTargets.Struct, 
       AllowMultiple=true, 
       Inherited=false)]
    [PostSharp.Extensibility.HasInheritedAttribute()]
    [XmlType("http://schemas.postsharp.net/2.0/aspects")]
    [Serializable()]
    public sealed class GTimer : GAspectBase, Gibraltar.Agent.IMessageSourceProvider, PostSharp.Aspects.IAspect, PostSharp.Aspects.IAspectBuildSemantics, PostSharp.Aspects.IMethodLevelAspect, PostSharp.Aspects.IMethodLevelAspectBuildSemantics, PostSharp.Aspects.IOnMethodBoundaryAspect, PostSharp.Extensibility.IValidableAnnotation  
    Remarks

    GTimer is a PostSharp aspect used to record the duration of a method call. It writes a message to the log every time an associated method is entered and when it returns. Additionally:

    • The input parameters to the method are recorded for the entering message
    • The execution time of the method is recorded in the exiting message.
    • The return value (if any) is recorded in the exiting message
    • If the method is exiting because an exception is being thrown out of the method that is noted and the exception details are recorded.
    • The log messages are attributed to the source code location that invoked the method, if source code location information is available.

    Log Message Categorization

    Each log message is recorded in an automatically generated category in the form {BaseCategory}.Trace Enter or {BaseCategory}.Trace Exit. See the BaseCategory property for more information on changing the log message category.

    Enabling and Disabling at Runtime

    You can globally enable and disable GTimer metrics at runtime. To do this just set the Enabled property which will affect all methods instrumented with GTimer in the current process. When disabled GTimer has minimal performance impact even in high volume scenarios.

    Refining Data Captured

    You can manually set the category used to record this specific timer within all of the timers with the Category property. By default each timer is recorded in a generated category composed of the BaseCategory Property (Gibraltar.Agent.PostSharp.GAspectBase) along with "Method Profiling" and the fully qualified class name. By setting the Category property you can put a specific timer into a subcategory underneath "Method Profiling".

    You can override the default name for each timer by setting the Name property. Within a given category timers that share the same name will be analyzed together in the Gibraltar Analyst. By default the Name is set to the name of the method being timed.

    Example
    You can associate the GTimer attribute with a single method, a property, or an entire class to time all methods in that class. You can also use attribute multicasting to apply it to all matching methods in your assembly.
    Timing one method within a class
    public class SampleApplication
    {
        [GTimer]
        private void InterestingMethod(int valueOne, String anotherValue)
        {
            //Do something interesting here
        }
    }
    Timing all methods within a class
    [GTimer]
    public class SampleApplication
    {
        private void InterestingMethod(int valueOne, String anotherValue)
        {
            //Do something interesting here
        }
     
        private void AnotherInterestingMethod(int valueTwo, String anotherValue)
        {
            //Do something even more interesting here
        }
    }
    Inheritance Hierarchy

    System.Object
       System.Attribute
          PostSharp.Extensibility.MulticastAttribute
             PostSharp.Aspects.Aspect
                PostSharp.Aspects.MethodLevelAspect
                   PostSharp.Aspects.OnMethodBoundaryAspect
                      Gibraltar.Agent.PostSharp.GAspectBase
                         Gibraltar.Agent.PostSharp.GTimer

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also