Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

timing.H

Go to the documentation of this file.
00001 // Copyright (C) 2004, Kenneth C. Schalk
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // timing.H - declarations for fine-grained NFS call timing, one of
00020 // the performance debugging features
00021 
00022 // Last modified on Thu Dec  9 17:07:49 EST 2004 by ken@xorian.net
00023 
00024 #include <sys/time.h> /* struct timeval */
00025 
00026 #if defined(REPOS_PERF_DEBUG)
00027 
00028 #if defined(__cplusplus)
00029 
00030 class LongId;
00031 
00032 extern "C" {
00033 #endif // defined(__cplusplus)
00034 
00035   /* Log the start of a call */
00036   void timing_start_call(unsigned int proc);
00037 
00038 #define TIMING_START_CALL(proc) timing_start_call(proc)
00039 
00040   /* Log the duplicate status of a call, and when it was
00041      determined. */
00042   void timing_dupe_status(int new_call);
00043 
00044 #define TIMING_DUPE_STATUS(new_call) timing_dupe_status(new_call)
00045 
00046   /* Log an intermediate time point. */
00047   void timing_record_time_point(const char *file, unsigned int line);
00048 
00049 #define RECORD_TIME_POINT timing_record_time_point(__FILE__, __LINE__)
00050 
00051   /* Log the end of a call, returning to the caller how long the call
00052      took. */
00053   void timing_end_call(/*OUT*/ struct timeval *delta_time);
00054 
00055 #define TIMING_END_CALL(delta) timing_end_call(delta)
00056 
00057   /* Determine whether we're in a call or not. */
00058   int timing_in_call();
00059 
00060 #define TIMING_IN_CALL timing_in_call()
00061 
00062 #if defined(__cplusplus)
00063 
00064   /* Turn timing recording on or off. */
00065   void timing_control(bool enable);
00066 
00067   void timing_record_LongId(const LongId &lid);
00068 
00069 #define TIMING_RECORD_LONGID(lid) timing_record_LongId(lid)
00070 
00071 }
00072 
00073 #include <stdio.h> // FILE *
00074 
00075 #define TIMING_RECORDER_BUF_SIZE 32768
00076 
00077 extern "C"
00078 {
00079   void Timing_Recorder_exit_cleanup_setup() throw();
00080   void Timing_Recorder_exit_cleanup() throw();
00081 }
00082 
00083 class Timing_Recorder
00084 {
00085 private:
00086   // File descriptor we're writing our data to.
00087   FILE *timing_record_stream;
00088 
00089   // The time at which we should switch to a new timing file.
00090   unsigned long file_end_time;
00091 
00092   // Start time of the call, used to compute deltas.
00093   struct timeval start_time;
00094 
00095   // Buffer with data prepared to write out.
00096   char write_buffer[TIMING_RECORDER_BUF_SIZE];
00097 
00098   // Number of bytes in the buffer so far.
00099   unsigned int current_byte_count;
00100 
00101   // Record 6 bytes for a delta from the start time.
00102   struct timeval record_delta();
00103 
00104   // Linked list of all recorders, used for cleanup.
00105   static Timing_Recorder *first;
00106   Timing_Recorder *next;
00107 
00108   // When we need to, start a new timing file.
00109   void start_new_file(struct timeval *current_time = 0);
00110 
00111 public:
00112   Timing_Recorder();
00113   ~Timing_Recorder();
00114 
00115   void start(unsigned int proc);
00116 
00117   void dupe_status(bool new_call);
00118 
00119   void time_point(const char *file, unsigned short line);
00120 
00121   struct timeval end();
00122 
00123   inline bool in_call()
00124   {
00125     return (current_byte_count > 0);
00126   }
00127 
00128   void record_LongId(const LongId &lid);
00129 
00130   friend void Timing_Recorder_exit_cleanup_setup() throw();
00131   friend void Timing_Recorder_exit_cleanup() throw();
00132 };
00133 #endif // defined(__cplusplus)
00134 
00135 #else // defined(REPOS_PERF_DEBUG)
00136 
00137 #define TIMING_START_CALL(proc) ((void)0)
00138 #define TIMING_DUPE_STATUS(new_call) ((void)0)
00139 #define RECORD_TIME_POINT ((void)0)
00140 #define TIMING_END_CALL(delta) ((void)0)
00141 #define TIMING_IN_CALL 0
00142 #define TIMING_RECORD_LONGID(lid) ((void)0)
00143 
00144 #endif // defined(REPOS_PERF_DEBUG)

Generated on Mon May 8 00:48:47 2006 for Vesta by  doxygen 1.4.2