I'd like to be able to produce traces of program execution triggered by a special condition. E.g. if I encounter a special condition in my code I would call some library that would start tracking and logging all public method calls in my Java app in the given thread until some other defined event happens, e.g. the execution reaches a certain other place in code.

I am looking for a tool that could deliver such a functionality. I am not looking for various simple workarounds like use debug messages or the like. One of the ideas is using aspect-oriented tool for this but I'd rather know whether there are such tools out there that can deliver such a functionality out-of-the-box instead of me developing that solution anew. Some library that I could build my code with and that would offer such a functionality.

I know that generally profilers are the tools with a similar functionality and may be some profiler offers this functionality. But in general profilers do something different. They can monitor ALL calls of a certain set of classes/methods and therefore they usually destroy the application peformance. What I need is tracking just one thread execution under a certain condition with as low performance impact on the other threads as possible so that I could make such a tracking mechanism a part of a production enterprise application without hurting its performance. I could e.g. decide to pick one suspicious thread upon a longer time, track a certain part of its execution, like one DB transaction. If it did not influence the other threads (much) it would be usable this way without hurting the performance of the whole system and I would get real detailed log of the system execution for a certain suspicious use case (that may be difficult to simulate in a test scenario because nobody knows how to reproduce it).

Thanks for any hints