문제

I've inherited a sizable project using a nhibernate/castle Windsor, wcf services and all manner of beast. The system is a processing tool for calculating values and then sending messages and data all over the place.

The system is large and complicated and not easy to debug.

I am looking for a way/tool/idea of how to display what functions are being called and with what parameters so that I can run a few scenarios and be able to get some sort of a visual map of how everything fits together.

1) Debug - yes I know I can but I would like to get a tool that generates some sort of map without havig to go through the code. I want to concentrate on the business logic for now.

2) Log statements / log4net - don't want to do that as it requires changing / adding a lot of code.

3) View callstack during debug - that doesn't give too much info and only the last few calls.

What I guess I'm looking for is maybe a plugin so I can: Run my process -> file generated with list of methods called and parameters passed.

Thanks

도움이 되었습니까?

해결책

I've done this in the past using postsharp (http://www.postsharp.net/diagnostics). Your second suggestion would work, and doesn't have to introduce many changes.

You can configure postsharp to re-write your assembly after compilation to automatically hook into all method calls and write out what was passed using something like log4net to give you a detailed trace of what the application is doing. The only thing you will need to do is add a reference to postsharp, and add an attribute to the assemblyinfo class telling postsharp what to log (if their new diagnostic wizard doesn't do that automatically)

I'm doing it in production using the free postsharp licence - I ended up writing my own aspect (implementation of OnMethodBoundaryAspect) and hooked it up to every method in a very large legacy product using one line of code, before the diagnostic pattern library was available from postsharp.

다른 팁

Since you've got Castle.Windsor in there i wouldn't try to log every call to every function. Instead i'd recommend using Castle.Windsor interception capabilities to log communications between components at their boundaries. This way you can get a mile-high view of what components live together, how they interact and how the application is architectured

Instead of a series of all possible class.function calls, you could get something that follow each important interface in your system

IControllerFactory.Resolve
IController.Process
IBindingEngine.BuildModel
etc...

For that you would have to use a Castle.Windsor IInterceptor. Here is an example of what such an interceptor would look like

public class LoggingInterceptor : IInterceptor
{
    public ILogger Logger { get; set; }

    public void Intercept(IInvocation invocation)
    {

        Logger.Debug(() =>
        {
            return String.Format("calling {0}.{1}"
                               , invocation.TargetType.Name
                               , invocation.Method.Name);
            // add whatever information is important
            // you can even dump the values of your parameters
        });

        invocation.Proceed();
    }
}

Registering it would be something along these lines

_container.Register(
            Classes.FromAssemblyInThisApplication()
            .BasedOn<IInterceptor>()
            .WithServiceBase()
            .Configure(c => c.Named(c.Implementation.Name))
        );

and then you would add it to the components that you need traced by using the Interceptors("LoggingInterceptor") method on your chosen registrations.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top