vulkan/overlay: add support for fps output in file
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Mon, 25 Feb 2019 17:48:14 +0000 (17:48 +0000)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 28 Feb 2019 12:40:57 +0000 (12:40 +0000)
Also make the sampling period configurable.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
src/vulkan/overlay-layer/README
src/vulkan/overlay-layer/overlay.cpp
src/vulkan/overlay-layer/overlay_params.c
src/vulkan/overlay-layer/overlay_params.h

index ae0d6dc37e9ce195ff782f7bac6431e53544a747..660ab94a7157036e0723bba1fa388dd7510319cd 100644 (file)
@@ -10,8 +10,8 @@ List the available statistics :
 VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=help /path/to/my_vulkan_app
 
 Turn on some statistics :
-VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit=1,draw=1,pipeline_graphics=1 /path/to/my_vulkan_app
+VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit,draw,pipeline_graphics /path/to/my_vulkan_app
 
 Position the layer :
 
-VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit=1,draw=1,pipeline_graphics=1,position=top-right /path/to/my_vulkan_app
+VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay VK_LAYER_MESA_OVERLAY_CONFIG=submit,draw,pipeline_graphics,position=top-right /path/to/my_vulkan_app
index c6f49c2ad754f3f74b056056f1bc25c57b5e6b60..a2f6f24bdecd81c1d7d7d43f96231e1c9b15e6f1 100644 (file)
@@ -211,6 +211,8 @@ static struct instance_data *new_instance_data(VkInstance instance)
 
 static void destroy_instance_data(struct instance_data *data)
 {
+   if (data->params.output_file)
+      fclose(data->params.output_file);
    unmap_object(data->instance);
    ralloc_free(data);
 }
@@ -338,7 +340,8 @@ static void destroy_swapchain_data(struct swapchain_data *data)
 
 static void snapshot_swapchain_frame(struct swapchain_data *data)
 {
-   uint64_t now = os_time_get();
+   struct instance_data *instance_data = data->device->instance;
+   uint64_t now = os_time_get(); /* us */
 
    if (data->last_present_time) {
       data->frame_times[(data->n_frames - 1) % ARRAY_SIZE(data->frame_times)] =
@@ -346,11 +349,15 @@ static void snapshot_swapchain_frame(struct swapchain_data *data)
    }
 
    if (data->last_fps_update) {
-      double elapsed = (double)(now - data->last_fps_update);
-      if (elapsed >= 500000.0) {
-         data->fps = ((uint64_t)data->n_frames_since_update * 1000000 / elapsed);
+      double elapsed = (double)(now - data->last_fps_update); /* us */
+      if (elapsed >= instance_data->params.fps_sampling_period) {
+         data->fps = 1000000.0f * data->n_frames_since_update / elapsed;
          data->n_frames_since_update = 0;
          data->last_fps_update = now;
+         if (instance_data->params.output_file) {
+            fprintf(instance_data->params.output_file, "%.2f\n", data->fps);
+            fflush(instance_data->params.output_file);
+         }
       }
    } else {
       data->last_fps_update = now;
index d28799ccf06d3dd9e04a0fc5e6c737a2241f8172..36819659c6fce6417b50f4a29f3d12dfc080c0f9 100644 (file)
@@ -41,6 +41,18 @@ parse_position(const char *str)
    return LAYER_POSITION_TOP_LEFT;
 }
 
+static FILE *
+parse_output_file(const char *str)
+{
+   return fopen(str, "w+");
+}
+
+static uint32_t
+parse_fps_sampling_period(const char *str)
+{
+   return strtol(str, NULL, 0) * 1000;
+}
+
 static bool
 parse_help(const char *str)
 {
@@ -51,11 +63,8 @@ parse_help(const char *str)
    OVERLAY_PARAMS
 #undef OVERLAY_PARAM_BOOL
 #undef OVERLAY_PARAM_CUSTOM
-   fprintf(stderr, "\tposition=\n"
-           "\t\ttop-left\n"
-           "\t\ttop-right\n"
-           "\t\tbottom-left\n"
-           "\t\tbottom-right\n");
+   fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
+   fprintf(stderr, "\tfps_sampling_period=number of milliseconds\n");
 
    return true;
 }
@@ -80,7 +89,8 @@ parse_string(const char *s, char *out_param, char *out_value)
       i++;
       for (; !is_delimiter(*s); s++, out_value++, i++)
          *out_value = *s;
-   }
+   } else
+      *(out_value++) = '1';
    *out_value = 0;
 
    if (*s && is_delimiter(*s)) {
@@ -117,6 +127,7 @@ parse_overlay_env(struct overlay_params *params,
    /* Visible by default */
    params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
    params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
+   params->fps_sampling_period = 500000; /* 500ms */
 
    if (!env)
       return;
@@ -126,11 +137,12 @@ parse_overlay_env(struct overlay_params *params,
 
 #define OVERLAY_PARAM_BOOL(name)                                        \
       if (!strcmp(#name, key)) {                                        \
-         params->enabled[OVERLAY_PARAM_ENABLED_##name] = strtol(value, NULL, 0); \
+         params->enabled[OVERLAY_PARAM_ENABLED_##name] =                \
+            strtol(value, NULL, 0);                                     \
          continue;                                                      \
       }
-#define OVERLAY_PARAM_CUSTOM(name)              \
-      if (!strcmp(#name, key)) {                \
+#define OVERLAY_PARAM_CUSTOM(name)               \
+      if (!strcmp(#name, key)) {                 \
          params->name = parse_##name(value);     \
          continue;                               \
       }
index 7e86c6f0e43ef8990e967f469a4e9cb4ce56c97a..75bcf956e8e2eb82376cdacaa42aa95ab3277f47 100644 (file)
@@ -28,6 +28,7 @@
 extern "C" {
 #endif
 
+#include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
 
@@ -47,6 +48,8 @@ extern "C" {
    OVERLAY_PARAM_BOOL(pipeline_compute)              \
    OVERLAY_PARAM_BOOL(pipeline_raytracing)           \
    OVERLAY_PARAM_BOOL(acquire_timing)                \
+   OVERLAY_PARAM_CUSTOM(fps_sampling_period)         \
+   OVERLAY_PARAM_CUSTOM(output_file)                 \
    OVERLAY_PARAM_CUSTOM(position)                    \
    OVERLAY_PARAM_CUSTOM(help)
 
@@ -69,6 +72,8 @@ enum overlay_param_enabled {
 struct overlay_params {
    bool enabled[OVERLAY_PARAM_ENABLED_MAX];
    enum overlay_param_position position;
+   FILE *output_file;
+   uint32_t fps_sampling_period; /* us */
    bool help;
 };