S3FC project page S3FC home page

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

s3_timer.h

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
00022  */
00023 
00024 //-----------------------------------------------------------------------------
00025 // $Id: s3_timer.h,v 1.1.1.1 2003/01/31 09:51:20 alberts3 Exp $
00026 //-----------------------------------------------------------------------------
00027 // SUMMARY: s3_timer macro definition header file.
00028 //
00029 // AUTHOR:  Francois Swanepoel
00030 // ORG:     Stone Three (Pty) Ltd
00031 // E-MAIL:  swanepoel@stonethree.com
00032 //-----------------------------------------------------------------------------
00033 
00034 /*
00035  * Demo usage:
00036  * ----------
00037  *
00038  *   // Init/define the timers you'll need.
00039  *   s3_timer_init( MainLoop );
00040  *   s3_timer_init( Loop1 );
00041  *   s3_timer_init( Loop2 );
00042  *
00043  *   // Reset/clear the timers.  This is only required to clear timers
00044  *   // you want to re-use later on.  Thus not needed here.
00045  *   s3_timer_reset( MainLoop );
00046  *   s3_timer_reset( Loop1 );
00047  *   s3_timer_reset( Loop2 );
00048  *
00049  *   s3_timer_start( MainLoop );
00050  *   for ( int i=0; i<N_TRIALS, i++ )
00051  *   {
00052  *      s3_timer_start( Loop1 );
00053  *      for ( int j=0; j<J; j++ )
00054  *      {
00055  *         Shaun_DoSomething_1();
00056  *      }
00057  *      s3_timer_stop_add( Loop1 );
00058  *
00059  *      s3_timer_start( Loop2 );
00060  *      for ( int k=0; k<K; k++ )
00061  *      {
00062  *         Shaun_DoSomething_2();
00063  *      }
00064  *      s3_timer_stop_add( Loop2 );
00065  *   }
00066  *  s3_timer_stop_add( MainLoop );
00067  *
00068  *  // Now print the little report.
00069  *  s3_timer_report_init;
00070  *  s3_timer_header( s3_timer_get_seconds( MainLoop ), N_TRIALS );
00071  *  s3_timer_line( Loop1, "Loop #1" );
00072  *  s3_timer_line( Loop2, "Loop #2" );
00073  *  s3_timer_footer;
00074  *
00075  *  // If you want to print additional reports, do NOT call "s3_timer_init"
00076  *  // again.  Simply start the next report with "s3_timer_header()" and
00077  *  // end it off with "s3_timer_footer".
00078  *
00079  */
00080 
00081 #include <iomanip>
00082 
00083 //#define CYCLE_SPEED 850e6
00084 //#define CYCLE_SPEED 600e6
00085 #define CYCLE_SPEED 450e6
00086 
00087 
00088 #define s3_timer_init( proc )                  \
00089 long long s3timer_start_##proc = 0;            \
00090 long long s3timer_stop_##proc = 0;             \
00091 long long s3timer_total_##proc = 0
00092 
00093 #define s3_timer_extern( proc )            \
00094 extern long long s3timer_start_##proc;     \
00095 extern long long s3timer_stop_##proc;      \
00096 extern long long s3timer_total_##proc
00097 
00098 #define s3_timer_reset( proc )            \
00099 s3timer_total_##proc = 0
00100 
00101 #define s3_timer_start( proc )            \
00102 asm volatile("rdtsc" : "=A"(*( &s3timer_start_##proc)))
00103 
00104 #define s3_timer_stop_add( proc )                                            \
00105 asm volatile("rdtsc" : "=A"(*(&s3timer_stop_##proc)));                       \
00106 s3timer_total_##proc += (s3timer_stop_##proc - s3timer_start_##proc )
00107 
00108 #define s3_timer_get_seconds( proc )                                         \
00109  ( (float)s3timer_total_##proc / (float)CYCLE_SPEED )
00110 
00111 #define WIDTH_NAME        15
00112 #define WIDTH_TOTAL_SECS  23
00113 #define WIDTH_PER_SECS    23
00114 #define WIDTH_PERCENT     15
00115 
00116 
00117 #define s3_timer_header( total_time, number_trials )                          \
00118 std::cout << std::setw(WIDTH_NAME)      << "Name"                                       \
00119     << std::setw(WIDTH_TOTAL_SECS) << "Total time [secs]"                          \
00120     << std::setw(WIDTH_PER_SECS)   << "Time per trial [ms]"                        \
00121     << std::setw(WIDTH_PERCENT)    << "Percentage "                                \
00122     << std::endl;                                                                  \
00123 for (int i=0; i<WIDTH_NAME+WIDTH_TOTAL_SECS+WIDTH_PER_SECS+WIDTH_PERCENT; i++)\
00124     std::cout << "-"; std::cout << std::endl;                                                \
00125 s3timer_precentage_accum = 0;                                                 \
00126 s3timer_time_accum = 0;                                                       \
00127 s3timer_number_trials = number_trials;                                        \
00128 s3timer_total_time = total_time
00129 
00130 #define s3_timer_report_init                                                  \
00131 float s3timer_precentage_accum = 0;                                           \
00132 float s3timer_time_accum = 0;                                                 \
00133 float s3timer_number_trials = 0;                                              \
00134 float s3timer_total_time = 04
00135 
00136 
00137 #define s3_timer_line( proc, str_name )                                       \
00138 std::cout << std::setw(WIDTH_NAME) << str_name                                          \
00139     << std::setw(WIDTH_TOTAL_SECS-2) << std::setfill(' ') << std::setprecision(4) <<         \
00140         (float)s3timer_total_##proc / (float)CYCLE_SPEED                      \
00141     << std::setw(WIDTH_PER_SECS) << std::setfill(' ') << std::setprecision(4) <<             \
00142         (float)s3timer_total_##proc / (float)CYCLE_SPEED /                    \
00143    s3timer_number_trials * 1000                                          \
00144     << std::setw(WIDTH_PERCENT) << std::setfill(' ') << std::setprecision(4) <<              \
00145         (float)s3timer_total_##proc / (float)CYCLE_SPEED /                    \
00146         s3timer_total_time*100                                                \
00147     << std::endl;                                                                  \
00148 s3timer_time_accum +=                                                         \
00149             (float)s3timer_total_##proc / (float)CYCLE_SPEED;                 \
00150 s3timer_precentage_accum +=                                                   \
00151             (float)s3timer_total_##proc / (float)CYCLE_SPEED /                \
00152       s3timer_total_time
00153 
00154 #define s3_timer_footer                                                       \
00155 for (int j=0; j<WIDTH_NAME+WIDTH_TOTAL_SECS+WIDTH_PER_SECS+WIDTH_PERCENT; j++)\
00156     std::cout << "-"; std::cout.setf(std::ios::fixed); std::cout << std::endl                          \
00157     << std::setw(WIDTH_NAME) << "Total:" <<                                        \
00158     std::setw(WIDTH_TOTAL_SECS-2) << std::setfill(' ') << std::setprecision(4) <<            \
00159     s3timer_time_accum                                                        \
00160     << std::setw(WIDTH_PER_SECS+WIDTH_PERCENT-0) <<                                \
00161     s3timer_precentage_accum*100 << " %" << std::endl

Send comments to: s3fc@stonethree.com SourceForge Logo