views:

164

answers:

4

I'm planning to add extensive diagnostics into my software. Right now I'm thinking about overall strategy of how to do this, because adding such code simply ad hoc can result in serious mess.

Do you have any experience in this?

I want to monitor:

  1. How intensively objects from selected subset are created.
  2. How intensively selected methods are called.
  3. Number of other events in selected periods of time.
  4. For selected methods gather information about callers (libcwd allows this?)
  5. Amount of time consumed by each thread in sequence of time periods.

My software is a processing-like tool, which in general works like other processing or computing tools, like lame mp3 encoder for example. This is why such overall statistics harvesting does have sense for me.

I'm currently planning to add a base class for each object that I want to monitor for creations/destructions. The base class would log proper information in its constructors and destructors. What else can be done??

class LifeCycleProbe {
    char * name;
    LifeCycleProbe(char * _name) : name(_name) {
       some::important::object.created(_name);
    }
    ~LifeCycleProbe() {
       some::important::object.destroyed(_name);
    }
}
class MonitorMe : private LifeCycleProbe {
    MonitorMe() : LifeCycleProbe("MonitorMe") {
        // ...
    }
}
A: 

This looks like something a good profiler should be able to gather for you, without changing your sourcecode.

I use kprof and valgrind, maybe those tools can help you.

Alexander Kjäll
+4  A: 

The first thing I can think of is that you can probably make good use of a separate profiling tool. This would also remove the need to alter your source code to allow it.

Tools I can recommend:

These tools can easily help you find answers to all of your questions.

Magnus Hoff
A: 

This sounds like a classic case of YAGNI - I'd suggest spendingv the time on desiginig and writing the software correctly in the first place.

anon
A: 

+1 to those suggesting external profiler. I'd bind profiling code only in a very drastic situations during development or testing cycles, and definitely not in production code base.

Back then, when I worked in C++, there was an absolutely fantastic tool called BugTrapper. It was about 7 years ago, they were a startup company, and it was impressive piece of software they made. I think they've matured a lot since then and stayed in business as far as I can tell by looking at their site. Used to be cool stuff, although I'm not sure what it's like now. In any case, it's worth trying off the shelf solution before reinventing the wheel. IMHO.

Dima