From 9ecd51ab1028e8033057df3117aac27f6f2cd406 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Thu, 4 May 2017 15:23:10 -0400 Subject: Copy profiling code from MCUOnEclipse. --- libraries/libprof/profil.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 libraries/libprof/profil.h (limited to 'libraries/libprof/profil.h') diff --git a/libraries/libprof/profil.h b/libraries/libprof/profil.h new file mode 100644 index 0000000..af7a3ed --- /dev/null +++ b/libraries/libprof/profil.h @@ -0,0 +1,60 @@ +/* profil.h: gprof profiling header file + + Copyright 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +/* + * This file is taken from Cygwin distribution. Please keep it in sync. + * The differences should be within __MINGW32__ guard. + */ + +#ifndef __PROFIL_H__ +#define __PROFIL_H__ + +/* profiling frequency. (No larger than 1000) */ +#define PROF_HZ 1000 + +/* convert an addr to an index */ +#define PROFIDX(pc, base, scale) \ + ({ \ + size_t i = (pc - base) / 2; \ + if (sizeof (unsigned long long int) > sizeof (size_t)) \ + i = (unsigned long long int) i * scale / 65536; \ + else \ + i = i / 65536 * scale + i % 65536 * scale / 65536; \ + i; \ + }) + +/* convert an index into an address */ +#define PROFADDR(idx, base, scale) \ + ((base) \ + + ((((unsigned long long)(idx) << 16) \ + / (unsigned long long)(scale)) << 1)) + +/* convert a bin size into a scale */ +#define PROFSCALE(range, bins) (((bins) << 16) / ((range) >> 1)) + +typedef void *_WINHANDLE; + +typedef enum { + PROFILE_NOT_INIT = 0, + PROFILE_ON, + PROFILE_OFF +} PROFILE_State; + +struct profinfo { + PROFILE_State state; /* profiling state */ + u_short *counter; /* profiling counters */ + size_t lowpc, highpc; /* range to be profiled */ + u_int scale; /* scale value of bins */ +}; + +int profile_ctl(struct profinfo *, char *, size_t, size_t, u_int); +int profil(char *, size_t, size_t, u_int); + +#endif /* __PROFIL_H__ */ -- cgit v1.2.3 From 03d7fa26a89d44349df86e29ac782d075856c570 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Wed, 10 May 2017 00:00:04 -0400 Subject: Sigh, right offset for the wrong register. Get the PC (the address we interrupted) rather than LR (the return address from the function we interrupted). Also, change u_short and u_int to unsigned short and unsigned int, since gcc recently decided that those aren't part of the C99 standard. Finally, add profilable versions of memcpy, memset, and friends, because they get called a lot in the course of unit testing, and it would be nice to know who's calling them. --- libraries/libprof/profil.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libraries/libprof/profil.h') diff --git a/libraries/libprof/profil.h b/libraries/libprof/profil.h index af7a3ed..c72dc00 100644 --- a/libraries/libprof/profil.h +++ b/libraries/libprof/profil.h @@ -48,13 +48,13 @@ typedef enum { } PROFILE_State; struct profinfo { - PROFILE_State state; /* profiling state */ - u_short *counter; /* profiling counters */ + PROFILE_State state; /* profiling state */ + unsigned short *counter; /* profiling counters */ size_t lowpc, highpc; /* range to be profiled */ - u_int scale; /* scale value of bins */ + unsigned int scale; /* scale value of bins */ }; -int profile_ctl(struct profinfo *, char *, size_t, size_t, u_int); -int profil(char *, size_t, size_t, u_int); +int profile_ctl(struct profinfo *, char *, size_t, size_t, unsigned int); +int profil(char *, size_t, size_t, unsigned int); #endif /* __PROFIL_H__ */ -- cgit v1.2.3