/* * libprof -- intercept calls to libc and report profiling information * * Copyright (C) 2004 David Collier-Brown, Data Center Works * Generated by mkinterposer from a template copyright (C) 2004 * David Collier-Brown * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef LIBPROF_H /* Includes for interposer. */ #include /* For dlopen(). */ #include #include /* For assert() macro. */ #include /* For sigaction(). */ #include #ifdef __sun #include /* For process name. */ #endif /* __sun */ #ifdef __sun extern int gettimeofday(struct timeval *, void *); #endif #ifdef __linux extern int gettimeofday(struct timeval *, __timezone_ptr_t); #define MAXLINE 1024 #define RTLD_NEXT ((void *) -1l) #endif /* Profile data, by interface */ struct prof_t { char *name; /* Function name as a string */ long calls; /* Number of call made to it. */ double time;/* Duration of all the calls. */ long errs; /* Reserved for possible future use. */ }; /* * Time Macros -- declare, collect and record times. */ /* * DECLARE_TIME */ #define DECLARE_TIME struct timeval t0, t1 /* * COLLECT_TIME */ #define COLLECT_TZERO (void) gettimeofday(&t0, NULL) /* * RECORD -- record the time taken in the function, in seconds. */ #define RECORD(i) \ (void) gettimeofday(&t1, NULL); \ ProfStats[i].time += (double) ((t1.tv_sec - t0.tv_sec) +\ ((t1.tv_usec - t0.tv_usec)/1000000.0)); \ ProfStats[i].calls++ #endif /* LIBPROF_H */