Bruce
Bruce

Reputation: 35223

Visual Studio Function Debugging

I am working on VS 2008. I wish to get the following information for all my methods:

1) Time at call entry

2) Time at call exit and the return value.

GDB allows me to set a break point at each function entry and exit and run a script at the breakpoint and then continue debugging. I am tired of looking for solutions to do something similar on VS. I even thought of writing a script to parse my entire code and write fprintf's at entry and exit but this is very complex. Desperately looking for help.

Upvotes: 2

Views: 343

Answers (4)

plodoc
plodoc

Reputation: 2803

using windbg, you can also set at each function entry and run a script. For instance the following command will add a breakpoint on all functions of your module, display the name of the function, the current time, run until the function exit, display the time and continue.

bm yourmodule!* "kcL1;.echotime;gu;.echotime;gc"

Upvotes: 2

Luke
Luke

Reputation: 11421

Visual Studio is not suited for this; you would have to use WinDbg. It has its own scripting language that would allow you to do what you are seeking. Unfortunately I don't know the first thing about it's scripting language; you will have to read the help file (which is actually more-or-less useful, for once).

Upvotes: 1

Yi Zhao
Yi Zhao

Reputation: 6784

I assume you are suing c++. You can define a time trace class which display the timestamps

/* define this in a header file */
class ShowTimestamp {
private:
    static int level_;   // nested level for function call tree

private:
    const char *func_;
public:
    ShowTimestamp(const char* f) : func_(f) {
        std::cout << func_ << ":" << (level_++) << ":begin\t" << GetTickCount64() << std::endl;
    }

    ~ShowTimestamp() {
        std::cout << func_ << ":" << (--level_) << ":end\t" << GetTickCount64() << std::endl;
    }
};

#ifndef NO_TRACE_TIMER
  #define TIMESTAMP_TRACER     ShowTimestamp _stt_(__FUNCTION__); 
#elif
  #define TIMESTAMP_TRACER
#endif

The level_ should be declared in a CPP file separately.

// You need to define the static member in a CPP file         
int ShowTimestamp::level_ = 0;

In your code, you can do

int Foo(int bar) {
  TIMESTAMP_TRACER 

  // all the other things.
  ......

  return bar;
}

If you don't want to trace timer any longer, you can just define NO_TRACE_TIMER

Upvotes: 1

Yi Zhao
Yi Zhao

Reputation: 6784

Basically this is a function level Time-Based Profiling (TBP). Several tools can help you on this:

I suggest you to try with AMD CodeAnalyst first. If you don't have Visual Studio Premium or Ultimate edition.

Upvotes: 1

Related Questions