00001 /* MLPACK 0.2 00002 * 00003 * Copyright (c) 2008, 2009 Alexander Gray, 00004 * Garry Boyer, 00005 * Ryan Riegel, 00006 * Nikolaos Vasiloglou, 00007 * Dongryeol Lee, 00008 * Chip Mappus, 00009 * Nishant Mehta, 00010 * Hua Ouyang, 00011 * Parikshit Ram, 00012 * Long Tran, 00013 * Wee Chin Wong 00014 * 00015 * Copyright (c) 2008, 2009 Georgia Institute of Technology 00016 * 00017 * This program is free software; you can redistribute it and/or 00018 * modify it under the terms of the GNU General Public License as 00019 * published by the Free Software Foundation; either version 2 of the 00020 * License, or (at your option) any later version. 00021 * 00022 * This program is distributed in the hope that it will be useful, but 00023 * WITHOUT ANY WARRANTY; without even the implied warranty of 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00025 * General Public License for more details. 00026 * 00027 * You should have received a copy of the GNU General Public License 00028 * along with this program; if not, write to the Free Software 00029 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00030 * 02110-1301, USA. 00031 */ 00040 #ifndef FX_TIMER_H 00041 #define FX_TIMER_H 00042 00043 #include "fastlib/base/common.h" 00044 00045 #include <sys/times.h> 00046 00047 EXTERN_C_BEGIN 00048 00050 typedef uint64 tsc_t; 00052 #define LTSC L64 00053 /* #define LT L64 */ 00054 00055 /* TODO: Check x86_64 and other architectures */ 00056 00057 #if defined(__i386__) 00058 00059 #define RDTSC(tscv) __asm__ volatile (".byte 0x0f, 0x31" : "=A" (tscv)) 00060 #define HAVE_RDTSC 00061 #endif 00062 00064 struct timestamp { 00066 tsc_t micros; 00067 #ifdef HAVE_RDTSC 00068 00069 tsc_t cycles; 00070 #endif 00071 00072 struct tms cpu; 00073 }; 00074 00076 struct stopwatch { 00078 struct timestamp total; 00080 struct timestamp start; 00081 }; 00082 00084 void timestamp_init(struct timestamp *snapshot); 00086 void timestamp_add(struct timestamp *dest, const struct timestamp *src); 00088 void timestamp_sub(struct timestamp *dest, const struct timestamp *src); 00094 void timestamp_now(struct timestamp *dest); 00100 void timestamp_now_rev(struct timestamp *dest); 00101 00103 void stopwatch_init(struct stopwatch *timer); 00105 void stopwatch_start(struct stopwatch *timer); 00107 void stopwatch_stop(struct stopwatch *timer, const struct timestamp *now); 00108 00110 #define STOPWATCH_ACTIVE(timer) ((timer)->start.micros != 0) 00111 00112 EXTERN_C_END 00113 00114 #endif