~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/profiler.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
***************************************************************************/
42
42
 
43
43
/*-------------------------------------------------
44
 
    _profiler_mark - mark the beginning/end of a
 
44
    _profiler_mark_start - mark the beginning of a
45
45
    profiler entry
46
46
-------------------------------------------------*/
47
47
 
48
 
void _profiler_mark(int type)
 
48
void _profiler_mark_start(int type)
49
49
{
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
        int index;
52
54
 
53
55
        /* track context switches */
54
56
        if (type >= PROFILER_CPU_FIRST && type <= PROFILER_CPU_MAX)
55
57
                data->context_switches++;
56
58
 
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];
 
62
 
 
63
        /* fail if we overflow */
 
64
        if (index > ARRAY_LENGTH(global_profiler.filo))
 
65
                fatalerror("Profiler FILO overflow (type = %d)\n", type);
 
66
 
 
67
        /* if we're nested, stop the previous entry */
 
68
        if (index > 0)
59
69
        {
60
 
                int index = global_profiler.filoindex++;
61
 
                profiler_filo_entry *entry = &global_profiler.filo[index];
62
 
 
63
 
                /* fail if we overflow */
64
 
                if (index > ARRAY_LENGTH(global_profiler.filo))
65
 
                        fatalerror("Profiler FILO overflow\n");
66
 
 
67
 
                /* if we're nested, stop the previous entry */
68
 
                if (index > 0)
69
 
                {
70
 
                        profiler_filo_entry *preventry = entry - 1;
71
 
                        data->duration[preventry->type] += curticks - preventry->start;
72
 
                }
73
 
 
74
 
                /* fill in this entry */
75
 
                entry->type = type;
76
 
                entry->start = curticks;
 
70
                profiler_filo_entry *preventry = entry - 1;
 
71
                data->duration[preventry->type] += curticks - preventry->start;
77
72
        }
78
73
 
79
 
        /* if we're ending an existing bucket, update the time */
80
 
        else if (global_profiler.filoindex > 0)
 
74
        /* fill in this entry */
 
75
        entry->type = type;
 
76
        entry->start = curticks;
 
77
}
 
78
 
 
79
 
 
80
/*-------------------------------------------------
 
81
    _profiler_mark_end - mark the end of a
 
82
    profiler entry
 
83
-------------------------------------------------*/
 
84
 
 
85
void _profiler_mark_end(void)
 
86
{
 
87
        profiler_data *data = &global_profiler.data[global_profiler.dataindex];
 
88
        osd_ticks_t curticks = get_profile_ticks();
 
89
 
 
90
        /* we're ending an existing bucket, update the time */
 
91
        if (global_profiler.filoindex > 0)
81
92
        {
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" }
128
143
        };
129
144
        UINT64 computed, normalize, total;
130
145
        int curtype, curmem, switches;
131
146
 
132
 
        profiler_mark(PROFILER_PROFILER);
 
147
        profiler_mark_start(PROFILER_PROFILER);
133
148
 
134
149
        /* compute the total time for all bits, not including profiler or idle */
135
150
        computed = 0;
147
162
        total = computed;
148
163
        astring_reset(string);
149
164
        if (total == 0 || normalize == 0)
150
 
                return string;
 
165
                goto out;
151
166
 
152
167
        /* loop over all types and generate the string */
153
168
        for (curtype = 0; curtype < PROFILER_TOTAL; curtype++)
194
209
                astring_catprintf(string, "%d CPU switches\n", switches / (int) ARRAY_LENGTH(global_profiler.data));
195
210
        }
196
211
 
197
 
        profiler_mark(PROFILER_END);
198
 
 
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]));
204
217
        if (global_profiler.dataindex == 0)
205
218
                global_profiler.dataready = TRUE;
206
219
 
 
220
out:
 
221
        profiler_mark_end();
 
222
 
207
223
        return string;
208
224
}