00001 // Copyright (C) 2011 CNRS - Ecole Polytechnique - INRIA. 00002 // 00003 // This file is part of TIFA. 00004 // 00005 // TIFA is free software; you can redistribute it and/or modify it under the 00006 // terms of the GNU Lesser General Public License as published by the Free 00007 // Software Foundation; either version 2.1 of the License, or (at your option) 00008 // any later version. 00009 // 00010 // TIFA is distributed in the hope that it will be useful, but WITHOUT ANY 00011 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00013 // more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, 00017 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00032 #if !defined(_TIFA_STOPWATCH_H_) 00033 00037 #define _TIFA_STOPWATCH_H_ 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00043 #include <sys/resource.h> 00044 #include <sys/time.h> 00045 #include <stdint.h> 00046 #include <stdbool.h> 00047 00055 struct struct_stopwatch_t { 00059 struct rusage rsg[1]; 00063 uint64_t started_usec; 00067 uint64_t elapsed_usec; 00071 bool is_running; 00072 }; 00077 typedef struct struct_stopwatch_t stopwatch_t; 00078 00086 void init_stopwatch(stopwatch_t* const watch); 00087 00097 void start_stopwatch(stopwatch_t* const watch); 00098 00113 void stop_stopwatch(stopwatch_t* const watch); 00114 00123 void reset_stopwatch(stopwatch_t* const watch); 00124 00136 double get_stopwatch_elapsed(stopwatch_t* const watch); 00137 00138 #ifdef __cplusplus 00139 } 00140 #endif 00141 00142 #endif