2
votes

I am using Madexcept tool to log the exceptions, but I am not able to log the call stack in periodically. Can any one suggest me how to log the call stack.

2
Please give more details. What do you mean by "log the call stack periodically". Which call stack? There's one per thread. And what do you mean by periodically? What is the purpose of this? - David Heffernan
I am using an application with multiple threads, some times my application performance is very slow, that time I want to write the call stack log for all threads to analyze the problem. Can we use any other tool to log the call stack. - nanda
The problem with this is that a full madExcept bug report takes a long time to generate. Especially if you have many threads. You need a profiler or less intrusive logging. - David Heffernan

2 Answers

4
votes

To get just the trace without the whole report (which slows it down), you can just call MadStackTrace. It's very handy when you want to know how your program is getting into various procedures/functions/methods, expecially when there are multiple ways it can happen, or you're scratching your head over performance problems.

You'll need this in your Uses:

uses
  MadStackTrace;

// Then to use the thing:

procedure foo;
begin
  writeln('How I got to FOO:' + MadStackTrace.StackTrace);
end;

http://help.madshi.net/madStackTraceUnit.htm

1
votes

The naive answer to your question is that you can do the following, inside a dedicated thread:

var
  exc: IMEException;
....
exc := madExcept.NewException;
Logger.Log(exc.BugReport);

Note that this logs the entire bug report. If you want to log less information, you can use the normal madExcept techniques to extract that information from the IMEException reference.

Also be warned that gathering all this information takes a significant amount of time, and will interfere with the execution of your program. It seems to me that what you really want is a profiler, or some trace logging. I don't think that madExcept is actually the solution to your underlying problem.