1 2 /* 3 * Copyright (C) Texas Instruments - http://www.ti.com/ 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 /* This should be only included from perf.h and perf_config.c */ 22 23 #include <stdio.h> 24 #include <stdlib.h> 25 #include <string.h> 26 27 /* This file contains the implementation of the PERF instrumentation object, 28 including the customizable interfaces */ 29 30 /****************************************************************************** 31 GENERIC TYPES 32 ******************************************************************************/ 33 #ifdef _WIN32 34 #undef INLINE_SUPPORTED 35 #define INLINE 36 #define INLINEORSTATIC static 37 38 #include <time.h> 39 40 /* time and process ID routines */ 41 42 #define TIME_STRUCT unsigned long 43 #define TIME_GET(target) time(&target) 44 #define TIME_COPY(target, source) target = source 45 #define TIME_MICROSECONDS(time) 0 46 #define TIME_SECONDS(time) (time) 47 #define TIME_INCREASE(time, microsecs) time += microsecs / 1000000 48 #define TIME_SET(time, sec, microsec) time = sec 49 #define PID_GET(target) target = 0 50 51 #else 52 #ifdef __STRICT_ANSI__ 53 /* for some reason strdup, strcasecmp and strncasecmp does not get 54 defined on ANSI builds */ 55 extern char *strdup(char const *); 56 extern int strcasecmp(const char *, const char *); 57 extern int strncasecmp(const char *, const char *, size_t); 58 #endif 59 60 #undef INLINE_SUPPORTED 61 #define INLINE 62 #define INLINEORSTATIC static 63 64 #include <sys/time.h> 65 #include <sys/types.h> 66 #include <unistd.h> 67 68 /* time and process ID routines */ 69 70 #define TIME_STRUCT struct timeval 71 #define TIME_GET(target) gettimeofday(&target, NULL) 72 #define TIME_COPY(target, source) \ 73 ((target).tv_sec = (source).tv_sec), ((target).tv_usec = (source).tv_usec) 74 #define TIME_MICROSECONDS(time) (time).tv_usec 75 #define TIME_SECONDS(time) (time).tv_sec 76 #define TIME_INCREASE(time, microsecs) \ 77 ((time).tv_sec += ((microsecs) / 1000000) + \ 78 ((time).tv_usec + (microsecs) % 1000000) / 1000000), \ 79 ((time).tv_usec = ((time).tv_usec + (microsecs) % 1000000) % 1000000) 80 #define TIME_SET(time, sec, microsec) \ 81 ((time).tv_sec = (sec)), ((time).tv_usec = (microsec)) 82 #define PID_GET(target) target = getpid() 83 84 #endif 85 86 #define TIME_DELTA(time, base) \ 87 ((TIME_SECONDS(time) - TIME_SECONDS(base)) * 1000000 + \ 88 (TIME_MICROSECONDS(time) - TIME_MICROSECONDS(base))) 89 90