⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timers.h

📁 一个学习SNMP项目:tmoerlan.
💻 H
字号:
/* timers.h */#ifndef _SNAP_TIMERS_H#define _SNAP_TIMERS_H/*If you want to time a .c file (all that's supported right now), youfirst add a new timer to the file timers.c.Right now there are two timers defined:struct timert_t timerlist[] ={ENTRY(0,        "total_time"),ENTRY(1,        "timer_time"),};To add a new one, add it to the list:struct timert_t timerlist[] ={ENTRY(0,        "total_time"),ENTRY(1,        "timer_time"),ENTRY(2,        "my_new_timer"),};Then, in you source file, you include the file "timers.h" andmake use of the macros print_anti_timer to start a timerand print_timer to stop it:  print_anti_timer(0,"total_time");  sleep(2);  print_timer(0,"total_time");To make use of the timing system, the global variablesprint_flags and do_print_individual_timers must be set properly.If do_print_individual_timers is set to 1, then each timethe time is taken, a message will be printed.  This is usefulfor seeing the ordering of events, but causes more timing overhead.print_flags indicates which timers you want to turn on for yourrun.  It is a char* where each element of the array is '1' or '0'.If the value of the xth entry is '1' then all print_timer andprint_anti_timer calls for timer x will be enabled.To see the results of the timings, the call dump_all_timers() isused.  It prints the average elapsed time and total elapsed timefor each timer.The underlying mechanism of the timers is the pentium cycle counter.When you build, a program will be run to determine the clockrateon your machine so that cycles may be properly converted to microsecs.*/extern char *print_flags;extern int print_flag_count;extern int do_print_individual_timers;extern int do_print_item_messages;extern int do_print_antitimers;extern void init_all_timers(void);extern void dump_all_timers(void);/*#define TIMERS_OFF*/#ifdef __KERNEL__#define TIMERS_OFF#endif /* __KERNEL__ */#ifndef TIMERS_OFFextern void internal_print_time(int index, char *label);extern void internal_print_anti_time(int index, char *label);#define print_timer(index, string)  \  if ((print_flags[index] == '1') && (index < print_flag_count)) {  \    internal_print_time(index, string);  \  }#define print_anti_timer(index, string)  \  if ((print_flags[index] == '1') && (index < print_flag_count)) {  \    internal_print_anti_time(index, string);  \  }#ifndef MINOR_TIMERS_OFF#define print_mtimer(index, string)  \  if ((print_flags[index] == '1') && (index < print_flag_count)) {  \    internal_print_time(index, string);  \  }#define print_anti_mtimer(index, string)  \  if ((print_flags[index] == '1') && (index < print_flag_count)) {  \    internal_print_anti_time(index, string);  \  }#else#define print_mtimer(x, y) {}#define print_anti_mtimer(x, y) {}#endif#else#define print_timer(x, y) {}#define print_anti_timer(x, y) {}#define print_mtimer(x, y) {}#define print_anti_mtimer(x, y) {}#endif#endif /* _SNAP_TIMERS_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -