summaryrefslogtreecommitdiff
path: root/firmware/export/profile.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/export/profile.h')
-rw-r--r--firmware/export/profile.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/firmware/export/profile.h b/firmware/export/profile.h
new file mode 100644
index 0000000000..cb751328ae
--- /dev/null
+++ b/firmware/export/profile.h
@@ -0,0 +1,80 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Profiling routines counts ticks and calls to each profiled function.
11 *
12 * Copyright (C) 2005 by Brandon Low
13 *
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 ****************************************************************************/
20
21#ifndef _SYS_PROFILE_H
22#define _SYS_PROFILE_H 1
23
24#include <sys/types.h>
25
26/* PFD is Profiled Function Data */
27
28/* Indices are shorts which means that we use 4k of RAM */
29#define INDEX_BITS 11 /* What is a reasonable size for this? */
30#define INDEX_SIZE 2048 /* 2 ^ INDEX_BITS */
31#define INDEX_MASK 0x7FF /* lower INDEX_BITS 1 */
32
33/*
34 * In the current setup (pfd has 4 longs and 2 shorts) this uses 20k of RAM
35 * for profiling, and allows for profiling sections of code with up-to
36 * 1024 function caller->callee pairs
37 */
38#define NUMPFDS 1024
39
40struct pfd_struct {
41 void *self_pc;
42 unsigned long count;
43 unsigned long time;
44 unsigned short link;
45 struct pfd_struct *caller;
46};
47
48/* Possible states of profiling */
49#define PROF_ON 0x00
50#define PROF_BUSY 0x01
51#define PROF_ERROR 0x02
52#define PROF_OFF 0x03
53/* Masks for thread switches */
54#define PROF_OFF_THREAD 0x10
55#define PROF_ON_THREAD 0x0F
56
57extern int current_thread;
58
59/* Initialize and start profiling */
60void profstart(int current_thread)
61 NO_PROF_ATTR;
62
63/* Clean up and write profile data */
64void profstop (void)
65 NO_PROF_ATTR;
66
67/* Called every time a thread stops, we check if it's our thread and store
68 * temporary timing data if it is */
69void profile_thread_stopped(int current_thread)
70 NO_PROF_ATTR;
71/* Called when a thread starts, we check if it's our thread and resume timing */
72void profile_thread_started(int current_thread)
73 NO_PROF_ATTR;
74
75void profile_func_exit(void *this_fn, void *call_site)
76 NO_PROF_ATTR ICODE_ATTR;
77void profile_func_enter(void *this_fn, void *call_site)
78 NO_PROF_ATTR ICODE_ATTR;
79
80#endif /*_SYS_PROFILE_H*/