diff --git a/src/intel/common/intel_measure.c b/src/intel/common/intel_measure.c index 80ba409b8b5..ff85a94c8fd 100644 --- a/src/intel/common/intel_measure.c +++ b/src/intel/common/intel_measure.c @@ -116,12 +116,8 @@ intel_measure_init(struct intel_measure_device *device) if (filename && __normal_user()) { filename += 5; - config.file = fopen(filename, "w"); - if (!config.file) { - fprintf(stderr, "INTEL_MEASURE failed to open output file %s: %s\n", - filename, strerror (errno)); - abort(); - } + config.deferred_create_filename = malloc(strlen(filename)); + strcpy(config.deferred_create_filename, filename); } if (start_frame_s) { @@ -219,16 +215,6 @@ intel_measure_init(struct intel_measure_device *device) if (cpu_s) { config.cpu_measure = true; } - - if (!config.cpu_measure) - fputs("draw_start,draw_end,frame,batch,batch_size,renderpass," - "event_index,event_count,type,count,vs,tcs,tes," - "gs,fs,cs,ms,ts,idle_us,time_us\n", - config.file); - else - fputs("draw_start,frame,batch,batch_size,event_index,event_count," - "type,count\n", - config.file); } device->config = NULL; @@ -670,6 +656,27 @@ static void intel_measure_print(struct intel_measure_device *device, const struct intel_device_info *info) { + if (unlikely(config.deferred_create_filename)) { + config.file = fopen(config.deferred_create_filename, "w"); + if (!config.file) { + fprintf(stderr, "INTEL_MEASURE failed to open output file %s: %s\n", + config.deferred_create_filename, strerror(errno)); + abort(); + } + free(config.deferred_create_filename); + config.deferred_create_filename = NULL; + + if (!config.cpu_measure) + fputs("draw_start,draw_end,frame,batch,batch_size,renderpass," + "event_index,event_count,type,count,vs,tcs,tes," + "gs,fs,cs,ms,ts,idle_us,time_us\n", + config.file); + else + fputs("draw_start,frame,batch,batch_size,event_index,event_count," + "type,count\n", + config.file); + } + while (true) { const int events_to_combine = buffered_event_count(device); if (events_to_combine == 0) diff --git a/src/intel/common/intel_measure.h b/src/intel/common/intel_measure.h index d54b4b5c74a..5c2a2916f9b 100644 --- a/src/intel/common/intel_measure.h +++ b/src/intel/common/intel_measure.h @@ -68,6 +68,9 @@ struct intel_measure_config { /* Stderr, or optionally set with INTEL_MEASURE=file={path{ */ FILE *file; + /* Defer log file create until first write */ + char *deferred_create_filename; + /* Events that will be measured. Set only one flag, with * INTEL_MEASURE=[draw,rt,shader,batch,frame] */ enum intel_measure_events flags;