Hi!
while developing some ldap authentication routine, I wanted to measure the time taken by the authentication call. I thought going AOP would be rather handy and non-obstrusive on the code I want to profile.
I came up with the following stuff - could anyone with more Spring AOP experience review that ? Any feedback welcome.
the advice:
the helper to return a proxified instance:Code:public class ProfilingAdvice : IMethodInterceptor { private static readonly ILog log = LogManager.GetLogger(typeof(ProfilingAdvice)); public object Invoke(IMethodInvocation invocation) { DateTime startTime = DateTime.Now; try { return invocation.Proceed(); } finally { log.Info(string.Format("{0}.{1} call took {2}",invocation.Method.DeclaringType.Name,invocation.Method.Name,DateTime.Now-startTime)); } } }
and sample code usageCode:private static object BuildProfilingProxy(object originalObject) { ProxyFactory factory = new ProxyFactory(originalObject); factory.AddAdvice(new ProfilingAdvice()); return factory.GetProxy(); }
cheersCode:[Test, Explicit] public void BenchmarkLDAPCall() { BasicConfigurator.Configure(); ILDAPAuthenticationProvider provider = new DirectoryServicesAuthenticationProvider(); provider = (ILDAPAuthenticationProvider)BuildProfilingProxy(provider); Assert.IsTrue(provider.Authenticate("myldaphost", "cn=mylogin,o=mycompany"); }
Thibaut Barrère


Reply With Quote
