1 /*
2  * Hatari - profile_priv.h
3  *
4  * This file is distributed under the GNU General Public License, version 2
5  * or at your option any later version. Read the file gpl.txt for details.
6  */
7 
8 #ifndef HATARI_PROFILE_PRIV_H
9 #define HATARI_PROFILE_PRIV_H
10 
11 typedef struct {
12 	char *filename;		/* where to write loop info */
13 	FILE *fp;		/* pointer modified by CPU & DSP code */
14 	Uint32 cpu_limit;	/* max limit for profiled CPU loop size */
15 	Uint32 dsp_limit;	/* max limit for profiled DSP loop size */
16 } profile_loop_t;
17 
18 extern profile_loop_t profile_loop;
19 
20 typedef struct {
21 	Uint64 calls, count, cycles; /* common counters between CPU & DSP */
22 	Uint64 i_misses, d_hits;     /* CPU specific counters */
23 	Uint64 cycles_diffs;         /* DSP specific counter, not updated at run-time */
24 } counters_t;
25 
26 typedef struct {
27 	int callee_idx;		/* index of called function */
28 	Uint32 ret_addr;	/* address after returning from call */
29 	Uint32 caller_addr;	/* remove informational caller address */
30 	Uint32 callee_addr;	/* remove informational callee address */
31 	counters_t all;		/* totals including everything called code does */
32 	counters_t out;		/* totals for subcalls done from callee */
33 } callstack_t;
34 
35 /* callee/caller information */
36 typedef struct {
37 	calltype_t flags;	/* what kind of call it was */
38 	Uint32 addr;		/* address for the caller */
39 	Uint32 calls;		/* number of calls, exclusive */
40 	counters_t all;		/* totals including everything called code does */
41 	counters_t own;		/* totals excluding called code (=sum(all-out)) */
42 } caller_t;
43 
44 typedef struct {
45 	Uint32 addr;		/* called address */
46 	int count;		/* number of callers */
47 	caller_t *callers;	/* who called this address */
48 } callee_t;
49 
50 /* impossible PC value, for unitialized PC values */
51 #define PC_UNDEFINED 0xFFFFFFFF
52 
53 typedef struct {
54 	int sites;		/* number of symbol callsites */
55 	int count;		/* number of items allocated for stack */
56 	int depth;		/* how many callstack calls haven't yet returned */
57 	Uint32 prev_pc;		/* stored previous PC value */
58 	Uint32 return_pc;	/* address for last call return address (speedup) */
59 	callee_t *site;		/* symbol specific caller information */
60 	callstack_t *stack;	/* calls that will return */
61 } callinfo_t;
62 
63 
64 /* CPU/DSP memory area statistics */
65 typedef struct {
66 	counters_t counters;	/* counters for this area */
67 	Uint32 lowest, highest;	/* active address range within memory area */
68 	int active;             /* number of active addresses */
69 	bool overflow;		/* whether counters overflowed */
70 } profile_area_t;
71 
72 
73 /* generic profile caller/callee info functions */
74 extern void Profile_ShowCallers(FILE *fp, int sites, callee_t *callsite, const char * (*addr2name)(Uint32, Uint64 *));
75 extern void Profile_CallStart(int idx, callinfo_t *callinfo, Uint32 prev_pc, calltype_t flag, Uint32 pc, counters_t *totalcost);
76 extern void Profile_FinalizeCalls(callinfo_t *callinfo, counters_t *totalcost, const char* (get_symbol)(Uint32, symtype_t));
77 extern Uint32 Profile_CallEnd(callinfo_t *callinfo, counters_t *totalcost);
78 extern int  Profile_AllocCallinfo(callinfo_t *callinfo, int count, const char *info);
79 extern void Profile_FreeCallinfo(callinfo_t *callinfo);
80 extern bool Profile_LoopReset(void);
81 
82 /* parser helpers */
83 extern void Profile_CpuGetPointers(bool **enabled, Uint32 **disasm_addr);
84 extern void Profile_DspGetPointers(bool **enabled, Uint32 **disasm_addr);
85 extern void Profile_CpuGetCallinfo(callinfo_t **callinfo, const char* (**get_symbol)(Uint32, symtype_t));
86 extern void Profile_DspGetCallinfo(callinfo_t **callinfo, const char* (**get_symbol)(Uint32, symtype_t));
87 
88 typedef enum {
89 	PAGING_DISABLED,
90 	PAGING_ENABLED
91 } paging_t;
92 
93 /* internal CPU profile results */
94 extern Uint32 Profile_CpuShowAddresses(Uint32 lower, Uint32 upper, FILE *out, paging_t use_paging);
95 extern void Profile_CpuShowCounts(int show, bool only_symbols);
96 extern void Profile_CpuShowCycles(int show);
97 extern void Profile_CpuShowInstrMisses(int show);
98 extern void Profile_CpuShowDataHits(int show);
99 extern void Profile_CpuShowCaches(void);
100 extern void Profile_CpuShowStats(void);
101 extern void Profile_CpuShowCallers(FILE *fp);
102 extern void Profile_CpuSave(FILE *out);
103 
104 /* internal DSP profile results */
105 extern Uint16 Profile_DspShowAddresses(Uint32 lower, Uint32 upper, FILE *out, paging_t use_paging);
106 extern void Profile_DspShowCounts(int show, bool only_symbols);
107 extern void Profile_DspShowCycles(int show);
108 extern void Profile_DspShowStats(void);
109 extern void Profile_DspShowCallers(FILE *fp);
110 extern void Profile_DspSave(FILE *out);
111 
112 #endif  /* HATARI_PROFILE_PRIV_H */
113