2

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.

4 Answers 4

2

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"
Sign up to request clarification or add additional context in comments.

3 Comments

Can I print the return value. I am compiling a big source code with lots of dll's. Do I give the .exe file here?
.logopen and .logclose to redirect output to a file.
return value in $retreg register
1

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.

1 Comment

I don't want to profile the code. I have already used the stand alone profiler for VS 2008. I have Professional btw. I want the output to be like the strace output. eg. Timestamp foo -> rv. Does AMD Code Analyst give me this output?
1

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

2 Comments

ShowTimestamp could be refined to add indent for nested function calls.
+1 for the nested function calls. So looks like there is no other way but to insert statements in every function.
1

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.