Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-02-04 17:45:16


christopher diggins wrote:
> I was searching around boost for mention of a profiling library. A
> fellow by the name of Carl Daniels posted something about an invasive
> profiling library. I was wondering in anyone knows what happened to
> that project? Profiling seems lacking at Boost, is anyone else
> interested in such a thing?
>
> Would a trivial policy driven RAII type be sufficient to garner
> interest as
> a mini-library?
>
> e.g.
>
> struct ProfilerDefaultPolicy {
> OnElapsed(int msec) {
> cout << "time elapsed (msec): " << msec << endl;
> }
> };
>
> template<typename Policy_T = ProfilerDefaultPolicy>
> class Profiler {
> public:
> Profiler() { mnStart = GetTickCount(); };
> ~Profiler() { Policy_T::OnElapsed(GetMSecElapsed()); };
> int GetMSecElapsed() { return GetTickCount() - mnStart; };
> int GetTickCount() { return int(double(clock()) * 1000 /
> CLOCKS_PER_SEC); };
> private:
> int mnStart;
> };
>
> usage:
>
> void MyRoutine() {
> Profiler<> p;
> // do stuff
> }

How about:

    typedef profiled< MyClass, Interface, Profiler<> > > MyProfiledClass;

?

This would be a good application of aspect-oriented programming.

Jonathan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk