Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/profileTimer.h

Go to the documentation of this file.
00001 // Filename: profileTimer.h
00002 // Created by:  
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 #ifndef PROFILETIMER_H //[
00019 #define PROFILETIMER_H
00020 
00021 #include "pandabase.h"
00022 #include "trueClock.h"
00023 
00024 /*
00025     ProfileTimer
00026 
00027     HowTo:
00028       Create a ProfileTimer and hold onto it.
00029       Call init() whenever you like (the timer doesn't
00030         start yet).
00031       Call on() to start the timer.
00032       While the timer is on, call mark() at each point of interest,
00033         in the code you are timing.
00034       You can turn the timer off() and on() to skip things you
00035         don't want to time.
00036       When your timing is finished, call printTo() to see the
00037         results (e.g. myTimer.printTo(cerr)).
00038 
00039     Notes:
00040       You should be able to time things down to the millisecond
00041       well enough, but if you call on() and off() within micro-
00042       seconds of each other, I don't think you'll get very good
00043       results.
00044 */
00045 class EXPCL_PANDAEXPRESS ProfileTimer {
00046   enum { MaxEntriesDefault=4096 };
00047 PUBLISHED:
00048   ProfileTimer(const char* name=0, int maxEntries=MaxEntriesDefault);
00049   ProfileTimer(const ProfileTimer& other);
00050   ~ProfileTimer();
00051 
00052   void init(const char* name, int maxEntries=MaxEntriesDefault);
00053 
00054   void on();
00055   void mark(const char* tag);
00056   void off();
00057   void off(const char* tag);
00058 
00059   // Don't call any of the following during timing:
00060   // (Because they are slow, not because anything will break).
00061   double getTotalTime() const;
00062   static void consolidateAllTo(ostream &out=cout);
00063   void consolidateTo(ostream &out=cout) const;
00064   static void printAllTo(ostream &out=cout);
00065   void printTo(ostream &out=cout) const;
00066 
00067 public:
00068   /*
00069       e.g.
00070       void Foo() {
00071         ProfileTimer::AutoTimer(myProfiler, "Foo()");
00072         ...
00073       }
00074   */
00075   class EXPCL_PANDAEXPRESS AutoTimer {
00076   public:
00077     AutoTimer(ProfileTimer& profile, const char* tag);
00078     ~AutoTimer();
00079 
00080   protected:
00081     ProfileTimer& _profile;
00082     const char* _tag;
00083   };
00084 
00085 protected:
00086   static ProfileTimer* _head;
00087   ProfileTimer* _next;
00088   class TimerEntry {
00089   public:
00090     const char* _tag; // not owned by this.
00091     double _time;
00092   };
00093   double _on;
00094   double _elapsedTime;
00095   const char* _name; // not owned by this.
00096   int _maxEntries;
00097   int _entryCount;
00098   TimerEntry* _entries;
00099   int _autoTimerCount; // see class AutoTimer
00100 
00101   double getTime();
00102 
00103   friend class ProfileTimer::AutoTimer;
00104 };
00105 
00106 #include "profileTimer.I"
00107 
00108 #endif //]

Generated on Fri May 2 00:38:33 2003 for Panda by doxygen1.3