[insert project logo here (125x200px max)]

Navigator

Mailinglists

Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums.

Copyright and Licensing Information

Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL).

All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License.

All sourcecode is made publicly available.

Acknowledgement

Splash and the Splash website are hosted by SourceForge.net

SourceForge.net Logo

osi-open source certified logo

Splash - Documentation

SNMP Plus a Lightweight API for SNAP Handling

Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

snap-1.1-wjdb/lib/timers.h

Go to the documentation of this file.
00001 /* timers.h
00002  */
00003 
00004 #ifndef _SNAP_TIMERS_H
00005 #define _SNAP_TIMERS_H
00006 
00007 /*
00008 
00009 If you want to time a .c file (all that's supported right now), you
00010 first add a new timer to the file timers.c.
00011 Right now there are two timers defined:
00012 
00013 struct timert_t timerlist[] =
00014 {
00015 ENTRY(0,        "total_time"),
00016 ENTRY(1,        "timer_time"),
00017 };
00018 
00019 To add a new one, add it to the list:
00020 
00021 struct timert_t timerlist[] =
00022 {
00023 ENTRY(0,        "total_time"),
00024 ENTRY(1,        "timer_time"),
00025 ENTRY(2,        "my_new_timer"),
00026 };
00027 
00028 Then, in you source file, you include the file "timers.h" and
00029 make use of the macros print_anti_timer to start a timer
00030 and print_timer to stop it:
00031 
00032   print_anti_timer(0,"total_time");
00033   sleep(2);
00034   print_timer(0,"total_time");
00035 
00036 To make use of the timing system, the global variables
00037 print_flags and do_print_individual_timers must be set properly.
00038 If do_print_individual_timers is set to 1, then each time
00039 the time is taken, a message will be printed.  This is useful
00040 for seeing the ordering of events, but causes more timing overhead.
00041 print_flags indicates which timers you want to turn on for your
00042 run.  It is a char* where each element of the array is '1' or '0'.
00043 If the value of the xth entry is '1' then all print_timer and
00044 print_anti_timer calls for timer x will be enabled.
00045 
00046 To see the results of the timings, the call dump_all_timers() is
00047 used.  It prints the average elapsed time and total elapsed time
00048 for each timer.
00049 
00050 The underlying mechanism of the timers is the pentium cycle counter.
00051 When you build, a program will be run to determine the clockrate
00052 on your machine so that cycles may be properly converted to microsecs.
00053 
00054 */
00055 
00056 extern char *print_flags;
00057 extern int print_flag_count;
00058 extern int do_print_individual_timers;
00059 extern int do_print_item_messages;
00060 extern int do_print_antitimers;
00061 
00062 extern void init_all_timers(void);
00063 extern void dump_all_timers(void);
00064 
00065 /*
00066 #define TIMERS_OFF
00067 */
00068 #ifdef __KERNEL__
00069 #define TIMERS_OFF
00070 #endif /* __KERNEL__ */
00071 
00072 
00073 #ifndef TIMERS_OFF
00074 
00075 extern void internal_print_time(int index, char *label);
00076 extern void internal_print_anti_time(int index, char *label);
00077 
00078 #define print_timer(index, string)  \
00079   if ((print_flags[index] == '1') && (index < print_flag_count)) {  \
00080     internal_print_time(index, string);  \
00081   }
00082 
00083 #define print_anti_timer(index, string)  \
00084   if ((print_flags[index] == '1') && (index < print_flag_count)) {  \
00085     internal_print_anti_time(index, string);  \
00086   }
00087 
00088 #ifndef MINOR_TIMERS_OFF
00089 
00090 #define print_mtimer(index, string)  \
00091   if ((print_flags[index] == '1') && (index < print_flag_count)) {  \
00092     internal_print_time(index, string);  \
00093   }
00094 
00095 #define print_anti_mtimer(index, string)  \
00096   if ((print_flags[index] == '1') && (index < print_flag_count)) {  \
00097     internal_print_anti_time(index, string);  \
00098   }
00099 #else
00100 #define print_mtimer(x, y) {}
00101 #define print_anti_mtimer(x, y) {}
00102 #endif
00103 #else
00104 #define print_timer(x, y) {}
00105 #define print_anti_timer(x, y) {}
00106 #define print_mtimer(x, y) {}
00107 #define print_anti_mtimer(x, y) {}
00108 #endif
00109 
00110 #endif /* _SNAP_TIMERS_H */
00111