58 mprintf((
"Failed to open profiling output file 'profiling.csv'!"));
85 for (
int i = 0;
i < (
int)samples.size();
i++) {
86 if ( !samples[
i].open_profiles ) {
90 samples[
i].num_children++;
92 if (samples[
i].num_children == 1) {
98 for(
int i = 0;
i < (
int)samples.size();
i++) {
99 if( !strcmp(samples[
i].name.c_str(),
name) && samples[
i].parent == parent ) {
101 samples[
i].open_profiles++;
102 samples[
i].profile_instances++;
104 Assert(samples[
i].open_profiles == 1);
119 new_sample.
parent = parent;
121 samples.push_back(new_sample);
136 for (
int i = 0;
i < (
int)samples.size();
i++ ) {
137 if ( samples[
i].open_profiles ) {
138 if ( samples[
i].num_children == 1 ) {
144 for (
int i = 0;
i < (
int)samples.size();
i++ ) {
145 if ( !strcmp(samples[
i].name.c_str(),
name) && samples[
i].parent == child_of ) {
149 samples[
i].open_profiles--;
152 while ( inner < (
int)samples.size() ) {
153 if ( samples[inner].open_profiles > 0 ) {
161 else if (samples[inner].start_time >= samples[parent].start_time) {
170 samples[
i].num_parents = num_parents;
174 samples[parent].children_sample_time += end_time - samples[
i].start_time;
178 samples[
i].accumulator += end_time - samples[
i].start_time;
184 for (
int i = 0;
i < (
int)samples.size();
i++) {
185 if (samples[
i].open_profiles) {
186 samples[
i].num_children--;
187 samples[
i].num_children =
MAX(samples[
i].num_children, 0);
210 for(
int i = 0;
i < (
int)samples.size();
i++) {
212 float percent_time, avg_time, min_time, max_time;
213 uint avg_micro_seconds, min_micro_seconds, max_micro_seconds;
215 Assert(samples[
i].open_profiles == 0);
217 sample_time = samples[
i].accumulator - samples[
i].children_sample_time;
225 avg_micro_seconds = min_micro_seconds = max_micro_seconds = sample_time;
226 avg_time = min_time = max_time = percent_time;
230 get_profile_from_history(samples[
i].name, &avg_time, &min_time, &max_time, &avg_micro_seconds, &min_micro_seconds, &max_micro_seconds);
233 char avg[64], min[64], max[64],
num[64];
235 sprintf(avg,
"%3.1f%% (%3.1fms)", avg_time,
i2fl(avg_micro_seconds)*0.001
f);
236 sprintf(min,
"%3.1f%% (%3.1fms)", min_time,
i2fl(min_micro_seconds)*0.001f);
237 sprintf(max,
"%3.1f%% (%3.1fms)", max_time,
i2fl(max_micro_seconds)*0.001f);
238 sprintf(num,
"%3d", samples[
i].profile_instances);
242 for(
uint indent = 0; indent < samples[
i].num_parents; indent++) {
243 indented_name =
">" + indented_name;
247 sprintf(line,
"%5s : %5s : %5s : %3s : ", avg, min, max, num);
268 if(new_ratio > 1.0
f) {
272 old_ratio = 1.0f - new_ratio;
274 for(
int i = 0;
i < (
int)history.size();
i++) {
275 if( history[
i].valid && history[
i].name == name ) {
277 history[
i].avg = (history[
i].avg * old_ratio) + (percent * new_ratio);
278 history[
i].avg_micro_sec =
fl2i((history[
i].avg_micro_sec * old_ratio) + (time * new_ratio));
280 if( percent < history[
i].min ) {
281 history[
i].min = percent;
283 history[
i].min = (history[
i].min*old_ratio) + (percent*new_ratio);
286 if( time < history[
i].min_micro_sec ) {
287 history[
i].min_micro_sec = time;
289 history[
i].min_micro_sec =
fl2i((history[
i].min_micro_sec*old_ratio) + (time*new_ratio));
292 if( percent > history[
i].max) {
293 history[
i].max = percent;
295 history[
i].max = (history[
i].max * old_ratio) + (percent * new_ratio);
298 if( time > history[
i].max_micro_sec) {
299 history[
i].max_micro_sec = time;
301 history[
i].max_micro_sec =
fl2i((history[
i].max_micro_sec * old_ratio) + (time * new_ratio));
312 new_history.
valid =
true;
313 new_history.
avg = new_history.
min = new_history.
max = percent;
316 history.push_back(new_history);
328 for (
int i = 0;
i < (
int)history.size();
i++ ) {
329 if ( history[
i].name == name ) {
330 *avg = history[
i].avg;
331 *min = history[
i].min;
332 *max = history[
i].max;
333 *avg_micro_sec = history[
i].avg_micro_sec;
334 *min_micro_sec = history[
i].min_micro_sec;
335 *max_micro_sec = history[
i].max_micro_sec;
340 *avg = *min = *max = 0.0f;
SCP_string profile_output
SCP_vector< profile_sample > samples
SCP_vector< profile_sample_history > history
bool Cmdline_profile_write_file
void get_profile_from_history(SCP_string &name, float *avg, float *min, float *max, uint *avg_micro_sec, uint *min_micro_sec, uint *max_micro_sec)
std::basic_string< char, std::char_traits< char >, std::allocator< char > > SCP_string
void profile_begin(const char *name)
bool Cmdline_frame_profile
void store_profile_in_history(SCP_string &name, float percent, uint time)
void profile_init()
Called once at engine initialization to set the timer.
typedef int(SCP_EXT_CALLCONV *SCPDLL_PFVERSION)(SCPDLL_Version *)
uint timer_get_high_res_microseconds()
sprintf(buf,"(%f,%f,%f)", v3->xyz.x, v3->xyz.y, v3->xyz.z)
void profile_dump_output()
GLuint const GLchar * name
void profile_end(const char *name)
std::ofstream profiling_file
uint children_sample_time