Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Tools/Debugging/Stopwatch.h

Go to the documentation of this file.
00001 /** 
00002 * @file Stopwatch.h
00003 * Makros and for the Stopwatch
00004 *
00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
00006 */
00007 
00008 #ifdef NEWDEBUGGING
00009 #include "Stopwatch2.h"
00010 #else //NEWDEBUGGING
00011 #ifndef __Stopwatch_h_
00012 #define __Stopwatch_h_
00013 
00014 #include "Tools/Debugging/Debugging.h"
00015 #include "Platform/SystemCall.h"
00016 #include "Platform/GTAssert.h"
00017 
00018 
00019 
00020 /** 
00021 * @class Stopwatch
00022 * Provides IDs and names for different stopwatch tasks; makros
00023 * are used to provide real stopwatch functionality with that.
00024 */
00025 class Stopwatch
00026 {
00027 public:
00028   enum StopwatchEventID
00029   {
00030     imageProcessor,
00031       sensorDataProcessor,
00032       ballLocator,
00033       teamBallLocator,
00034       selfLocator,
00035       playersLocator,
00036       obstaclesLocator,
00037       behaviorControl,
00038       motionControl,
00039       soundControl,
00040       specialVision,
00041       perceptBehaviorControl,
00042       sensorBehaviorControl,
00043       headControl,
00044       collisionDetector,
00045       robotStateDetector,
00046 
00047       numberOfStopwatchEventIDs
00048   };
00049   
00050   static DebugKeyTable::debugKeyID getDebugKeyID(enum StopwatchEventID stopwatchEventID)
00051   {
00052     switch (stopwatchEventID) 
00053     {
00054    case imageProcessor: return DebugKeyTable::sendImageProcessorTime;
00055    case sensorDataProcessor: return DebugKeyTable::sendSensorDataProcessorTime;
00056    case ballLocator: return DebugKeyTable::sendBallLocatorTime;
00057    case teamBallLocator: return DebugKeyTable::sendTeamBallLocatorTime;
00058    case selfLocator: return DebugKeyTable::sendSelfLocatorTime;
00059    case playersLocator: return DebugKeyTable::sendPlayersLocatorTime;
00060    case obstaclesLocator: return DebugKeyTable::sendObstaclesLocatorTime;
00061    case behaviorControl: return DebugKeyTable::sendBehaviorControlTime;
00062     case motionControl: return DebugKeyTable::sendMotionControlTime;
00063     case soundControl: return DebugKeyTable::sendSoundControlTime;
00064     case specialVision: return DebugKeyTable::sendSpecialVisionTime;
00065     case perceptBehaviorControl: return DebugKeyTable::sendPerceptBehaviorControlTime;
00066     case sensorBehaviorControl: return DebugKeyTable::sendSensorBehaviorControlTime;
00067     case headControl: return DebugKeyTable::sendHeadControlTime;
00068     case collisionDetector: return DebugKeyTable::sendCollisionDetectorTime;
00069     case robotStateDetector: return DebugKeyTable::sendRobotStateDetectorTime;
00070     default: 
00071       {
00072         ASSERT(false);
00073         return (DebugKeyTable::debugKeyID)0;
00074       }
00075     }
00076   }
00077   
00078   static const char* getStopwatchEventIDName(enum StopwatchEventID stopwatchEventID)
00079   {
00080     switch (stopwatchEventID) 
00081     {
00082    case imageProcessor: return "imageProcessor";
00083    case sensorDataProcessor: return "sensorDataProcessor";
00084    case ballLocator: return "ballLocator";
00085    case teamBallLocator: return "teamBallLocator";
00086    case selfLocator: return "selfLocator";
00087    case playersLocator: return "playersLocator";
00088    case obstaclesLocator: return "obstaclesLocator";
00089    case behaviorControl: return "behaviorControl";
00090    case perceptBehaviorControl: return "perceptBehaviorControl";
00091    case sensorBehaviorControl: return "sensorBehaviorControl";
00092     case motionControl: return "motionControl";
00093     case soundControl: return "soundControl";
00094     case specialVision: return "specialVision";
00095     case headControl: return "headControl";
00096     case collisionDetector: return "collisionDetector";
00097     case robotStateDetector: return "robotStateDetector";
00098     default: return "check available stopwatchEventIDs";
00099     }
00100   }
00101 };
00102 #define NSTOP_TIME_ON_REQUEST(eventID, expression)
00103 #define NSTOP_TIME(expression)
00104 
00105 #ifdef NDEBUG
00106 
00107 #define STOP_TIME_ON_REQUEST(eventID, expression) expression
00108 #define STOP_TIME(expression) expression/**/
00109 
00110 #else //NDEBUG
00111 
00112 /**
00113 * Stops the execution time of "expression"  if a DebugKey is set for the eventID.
00114 * The start and stop times are sent as a idStopwatch message to RobotControl
00115 */
00116 
00117 #define STOP_TIME_ON_REQUEST(eventID, expression) \
00118   if (getDebugKeyTable().isActive(Stopwatch::getDebugKeyID(Stopwatch::eventID))) \
00119 {\
00120   unsigned long eventID##StartTime; \
00121   static unsigned long evendID##Counter = 0; \
00122   eventID##StartTime = SystemCall::getCurrentSystemTime();\
00123   expression \
00124   OUTPUT(idStopwatch, bin, (char) Stopwatch::eventID << eventID##StartTime << SystemCall::getCurrentSystemTime() << evendID##Counter++)\
00125 }\
00126   else {expression}\
00127 
00128 
00129 /** 
00130 * Starts a StopWatch without an id.
00131 */
00132 #define STOP_TIME(expression) \
00133 {\
00134   unsigned long stopwatchStartTime = SystemCall::getCurrentSystemTime();\
00135   expression\
00136   OUTPUT(idText, text, "Stopwatch: " << SystemCall::getTimeSince(stopwatchStartTime) << "ms")\
00137 }\
00138 
00139 #endif //NDEBUG
00140 
00141 #endif //Stopwatch_h
00142 
00143 #endif //NEWDEBUGGING
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 

Generated on Mon Mar 20 22:00:05 2006 for GT2005 by doxygen 1.3.6