2

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.

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
nanda
  • 25
  • 7
  • 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 Mar 04 '14 at 07:09
  • 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 Mar 04 '14 at 07:41
  • 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 Mar 04 '14 at 07:52

2 Answers2

4

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

Chris Thornton
  • 15,620
  • 5
  • 37
  • 62
  • Actually it is the stack tracing that is most expensive. And I think that what the asked is really after is some sort of a trace of where the application spends its time. What you have here will produce the stack trace to get **here**. – David Heffernan Mar 04 '14 at 14:54
1

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490