1 /*****************************************************************************\ 2 * timers.h - timing functions 3 ***************************************************************************** 4 * Copyright (C) 2002 The Regents of the University of California. 5 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 6 * Written by Morris Jette <jette1@llnl.gov> and Kevin Tew <tew1@llnl.gov> 7 * CODE-OCEC-09-009. All rights reserved. 8 * 9 * This file is part of Slurm, a resource management program. 10 * For details, see <https://slurm.schedmd.com/>. 11 * Please also read the included file: DISCLAIMER. 12 * 13 * Slurm is free software; you can redistribute it and/or modify it under 14 * the terms of the GNU General Public License as published by the Free 15 * Software Foundation; either version 2 of the License, or (at your option) 16 * any later version. 17 * 18 * In addition, as a special exception, the copyright holders give permission 19 * to link the code of portions of this program with the OpenSSL library under 20 * certain conditions as described in each individual source file, and 21 * distribute linked combinations including the two. You must obey the GNU 22 * General Public License in all respects for all of the code used other than 23 * OpenSSL. If you modify file(s) with this exception, you may extend this 24 * exception to your version of the file(s), but you are not obligated to do 25 * so. If you do not wish to do so, delete this exception statement from your 26 * version. If you delete this exception statement from all source files in 27 * the program, then also delete it here. 28 * 29 * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY 30 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 31 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 32 * details. 33 * 34 * You should have received a copy of the GNU General Public License along 35 * with Slurm; if not, write to the Free Software Foundation, Inc., 36 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 37 \*****************************************************************************/ 38 39 #ifndef _HAVE_TIMERS_H 40 #define _HAVE_TIMERS_H 41 42 #include <sys/time.h> 43 44 #define DEF_TIMERS struct timeval tv1, tv2; char tv_str[20] = ""; long delta_t; 45 #define START_TIMER gettimeofday(&tv1, NULL) 46 #define END_TIMER do { \ 47 gettimeofday(&tv2, NULL); \ 48 slurm_diff_tv_str(&tv1, &tv2, tv_str, 20, NULL, 0, &delta_t); \ 49 } while (0) 50 #define END_TIMER2(from) do { \ 51 gettimeofday(&tv2, NULL); \ 52 slurm_diff_tv_str(&tv1, &tv2, tv_str, 20, from, 0, &delta_t); \ 53 } while (0) 54 #define END_TIMER3(from, limit) do { \ 55 gettimeofday(&tv2, NULL); \ 56 slurm_diff_tv_str(&tv1, &tv2, tv_str, 20, from, limit, &delta_t); \ 57 } while (0) 58 #define DELTA_TIMER delta_t 59 #define TIME_STR tv_str 60 61 /* Return the number of micro-seconds between now and argument "tv", 62 * Initialize tv to NOW if zero on entry */ 63 extern int slurm_delta_tv(struct timeval *tv); 64 65 /* 66 * slurm_diff_tv_str - build a string showing the time difference between two 67 * times 68 * IN tv1 - start of event 69 * IN tv2 - end of event 70 * OUT tv_str - place to put delta time in format "usec=%ld" 71 * IN len_tv_str - size of tv_str in bytes 72 * IN from - Name to be printed on long diffs 73 * IN limit - limit to wait 74 * OUT delta_t - raw time difference in usec 75 */ 76 extern void slurm_diff_tv_str(struct timeval *tv1,struct timeval *tv2, 77 char *tv_str, int len_tv_str, const char *from, 78 long limit, long *delta_t); 79 80 #endif 81