EventLog.H

Go to the documentation of this file.
00001 /*!@file Component/EventLog.H Simple text-based event logger */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the University of Southern California (USC) and the iLab at USC.  //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file:
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Component/EventLog.H $
00035 // $Id: EventLog.H 6526 2006-04-25 17:26:17Z rjpeters $
00036 //
00037 
00038 #ifndef COMPONENT_EVENTLOG_H_DEFINED
00039 #define COMPONENT_EVENTLOG_H_DEFINED
00040 
00041 #include "Component/ModelComponent.H"
00042 #include "Component/ModelParam.H"
00043 #include "Util/Timer.H"
00044 #include <list>
00045 #include <pthread.h>
00046 
00047 //! EventLog is a simple text-based event logger
00048 /*! EventLog allows simple logging of various user-defined events,
00049   with simultaneous recording of the (real) time at which the events
00050   were triggered. This functionality used to be part of
00051   PsychoDisplay. EventLog derives from ModelComponent and hence can be
00052   configured via the command line. EventLog complements at least two
00053   types of logging available in this toolkit: in Util/log.H, functions
00054   are defined which can generate logs onto stderr or syslog,
00055   prepending class and function name to any event. In addition,
00056   ModelComponent itself has a built-int logging facility that logs
00057   events to file without a timestamp (see --txtlog command-line
00058   option). One critical feature of EventLog is its ability to keep all
00059   logs in a mmory queue util the program is stopped, hence avoiding
00060   disk access during execution of a program. */
00061 class EventLog : public ModelComponent
00062 {
00063 public:
00064   //! Constructor
00065   EventLog(OptionManager& mgr,
00066            const std::string& descrName = "Event Log",
00067            const std::string& tagName = "EventLog");
00068 
00069   //! Destructor
00070   virtual ~EventLog();
00071 
00072   //! push a new event into the event queue
00073   void pushEvent(const std::string& msg);
00074 
00075   //! push the beginning of an event into our queue
00076   /*! This is like pushEvent() but it will add a start marker to the string */
00077   void pushEventBegin(const std::string& msg);
00078 
00079   //! push the end of an event into our queue
00080   /*! This is like pushEvent() but it will add an end marker to the string */
00081   void pushEventEnd(const std::string& msg);
00082 
00083 protected:
00084   OModelParam<std::string> itsFileName; //!< filename for event log output
00085 
00086   virtual void start1(); //!< get started
00087   virtual void stop2();  //!< get stopped
00088 
00089 private:
00090   // this is the data we record as event:
00091   struct LogEvent
00092   {
00093     uint64 tim;           // the time in microseconds since start()
00094     std::string descrip;  // description of the event
00095   };
00096 
00097   std::list<LogEvent> itsEvents;  // record a bunch of events
00098   Timer itsTimer;                 // Measure time since start()
00099   pthread_mutex_t itsMutex;       // make sure we are thread-safe
00100 };
00101 
00102 // ######################################################################
00103 /* So things look consistent in everyone's emacs... */
00104 /* Local Variables: */
00105 /* mode: c++ */
00106 /* indent-tabs-mode: nil */
00107 /* End: */
00108 
00109 #endif // COMPONENT_EVENTLOG_H_DEFINED
Generated on Sun May 8 08:04:42 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3