summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/profiler.h
blob: 6f22e181c7a132e1a45af124604138a236eb5b2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/***************************************************************************

    profiler.h

    Functions to manage profiling of MAME execution.

    Copyright Nicola Salmoria and the MAME Team.
    Visit http://mamedev.org for licensing and usage restrictions.

****************************************************************************

	To start profiling a certain section, e.g. video:
	profiler_mark(PROFILER_VIDEO);

	to end profiling the current section:
	profiler_mark(PROFILER_END);

	the profiler handles a FILO list so calls may be nested.
	
***************************************************************************/

#pragma once

#ifndef __PROFILER_H__
#define __PROFILER_H__

#include "astring.h"


/***************************************************************************
    CONSTANTS
***************************************************************************/

/* profiling */
enum
{
	PROFILER_END = -1,
	PROFILER_CPU_FIRST = 0,
	PROFILER_CPU_MAX = PROFILER_CPU_FIRST + 32,
	PROFILER_MEMREAD,
	PROFILER_MEMWRITE,
	PROFILER_VIDEO,
	PROFILER_DRAWGFX,
	PROFILER_COPYBITMAP,
	PROFILER_TILEMAP_DRAW,
	PROFILER_TILEMAP_DRAW_ROZ,
	PROFILER_TILEMAP_UPDATE,
	PROFILER_BLIT,
	PROFILER_SOUND,
	PROFILER_TIMER_CALLBACK,
	PROFILER_INPUT,		/* input.c and inptport.c */
	PROFILER_MOVIE_REC,	/* movie recording */
	PROFILER_LOGERROR,	/* logerror */
	PROFILER_EXTRA,		/* everything else */

	/* the USER types are available to driver writers to profile */
	/* custom sections of the code */
	PROFILER_USER1,
	PROFILER_USER2,
	PROFILER_USER3,
	PROFILER_USER4,

	PROFILER_PROFILER,
	PROFILER_IDLE,
	PROFILER_TOTAL
};



/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

typedef struct _profiler_filo_entry profiler_filo_entry;
struct _profiler_filo_entry
{
	int				type;				/* type of entry */
	osd_ticks_t		start;				/* start time */
};


typedef struct _profiler_data profiler_data;
struct _profiler_data
{
	UINT32			context_switches;	/* number of context switches seen */
	osd_ticks_t		duration[PROFILER_TOTAL]; /* duration spent in each entry */
};


typedef struct _profiler_state profiler_state;
struct _profiler_state
{
	UINT8			enabled;			/* are we enabled? */
	UINT8			filoindex;			/* current FILO index */
	UINT8			dataindex;			/* current data index */
	UINT8			dataready;			/* are we to display the data yet? */
	profiler_filo_entry filo[16];		/* array of FILO entries */
	profiler_data	data[16];			/* array of data */
};



/***************************************************************************
    GLOBAL VARIABLES
***************************************************************************/

extern profiler_state global_profiler;



/***************************************************************************
    MACROS
***************************************************************************/

#ifdef MAME_PROFILER

#define profiler_mark(x)		do { if (global_profiler.enabled) _profiler_mark(x); } while (0)
#define profiler_start()		do { global_profiler.enabled = TRUE; global_profiler.filoindex = global_profiler.dataindex = global_profiler.dataready = 0; } while (0)
#define profiler_stop()			do { global_profiler.enabled = FALSE; } while (0)
#define profiler_get_text(x,s)	_profiler_get_text(x, s)

#else

#define profiler_mark(x)		do { } while (0)
#define profiler_start()		do { } while (0)
#define profiler_stop()			do { } while (0)
#define profiler_get_text(x,s) 	astring_reset(s)

#endif



/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/


/* ----- core functions (do not call directly; use macros) ----- */

/* mark the beginning/end of a profiler entry */
void _profiler_mark(int type);

/* return the current text in an astring */
astring *_profiler_get_text(running_machine *machine, astring *string);


#endif	/* __PROFILER_H__ */