intel/measure: defer file open until first write

Fixes abort on steam.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31938>
This commit is contained in:
Felix DeGrood
2024-11-01 16:52:12 +00:00
committed by Marge Bot
parent f345019830
commit 99e8502013
2 changed files with 26 additions and 16 deletions

View File

@@ -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)

View File

@@ -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;