41
41
***************************************************************************/
43
43
/*-------------------------------------------------
44
_profiler_mark - mark the beginning/end of a
44
_profiler_mark_start - mark the beginning of a
46
46
-------------------------------------------------*/
48
void _profiler_mark(int type)
48
void _profiler_mark_start(int type)
50
50
profiler_data *data = &global_profiler.data[global_profiler.dataindex];
51
osd_ticks_t curticks = osd_profiling_ticks();
51
osd_ticks_t curticks = get_profile_ticks();
52
profiler_filo_entry *entry;
53
55
/* track context switches */
54
56
if (type >= PROFILER_CPU_FIRST && type <= PROFILER_CPU_MAX)
55
57
data->context_switches++;
57
/* if we're starting a new bucket, begin now */
58
if (type != PROFILER_END)
59
/* we're starting a new bucket, begin now */
60
index = global_profiler.filoindex++;
61
entry = &global_profiler.filo[index];
63
/* fail if we overflow */
64
if (index > ARRAY_LENGTH(global_profiler.filo))
65
fatalerror("Profiler FILO overflow (type = %d)\n", type);
67
/* if we're nested, stop the previous entry */
60
int index = global_profiler.filoindex++;
61
profiler_filo_entry *entry = &global_profiler.filo[index];
63
/* fail if we overflow */
64
if (index > ARRAY_LENGTH(global_profiler.filo))
65
fatalerror("Profiler FILO overflow\n");
67
/* if we're nested, stop the previous entry */
70
profiler_filo_entry *preventry = entry - 1;
71
data->duration[preventry->type] += curticks - preventry->start;
74
/* fill in this entry */
76
entry->start = curticks;
70
profiler_filo_entry *preventry = entry - 1;
71
data->duration[preventry->type] += curticks - preventry->start;
79
/* if we're ending an existing bucket, update the time */
80
else if (global_profiler.filoindex > 0)
74
/* fill in this entry */
76
entry->start = curticks;
80
/*-------------------------------------------------
81
_profiler_mark_end - mark the end of a
83
-------------------------------------------------*/
85
void _profiler_mark_end(void)
87
profiler_data *data = &global_profiler.data[global_profiler.dataindex];
88
osd_ticks_t curticks = get_profile_ticks();
90
/* we're ending an existing bucket, update the time */
91
if (global_profiler.filoindex > 0)
82
93
int index = --global_profiler.filoindex;
83
94
profiler_filo_entry *entry = &global_profiler.filo[index];
123
134
{ PROFILER_USER2, "User 2" },
124
135
{ PROFILER_USER3, "User 3" },
125
136
{ PROFILER_USER4, "User 4" },
137
{ PROFILER_USER5, "User 5" },
138
{ PROFILER_USER6, "User 6" },
139
{ PROFILER_USER7, "User 7" },
140
{ PROFILER_USER8, "User 8" },
126
141
{ PROFILER_PROFILER, "Profiler" },
127
142
{ PROFILER_IDLE, "Idle" }
129
144
UINT64 computed, normalize, total;
130
145
int curtype, curmem, switches;
132
profiler_mark(PROFILER_PROFILER);
147
profiler_mark_start(PROFILER_PROFILER);
134
149
/* compute the total time for all bits, not including profiler or idle */
194
209
astring_catprintf(string, "%d CPU switches\n", switches / (int) ARRAY_LENGTH(global_profiler.data));
197
profiler_mark(PROFILER_END);
199
212
/* advance to the next dataset and reset it to 0 */
200
213
global_profiler.dataindex = (global_profiler.dataindex + 1) % ARRAY_LENGTH(global_profiler.data);
201
214
memset(&global_profiler.data[global_profiler.dataindex], 0, sizeof(global_profiler.data[global_profiler.dataindex]));